Implement PostBeatmapFavouriteRequest

This commit is contained in:
Andrei Zavatski
2019-10-07 15:36:23 +03:00
parent 84c13b93fc
commit 2d707b2b65
2 changed files with 59 additions and 1 deletions

View File

@ -10,6 +10,9 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osuTK;
namespace osu.Game.Overlays.BeatmapSet.Buttons
@ -20,8 +23,11 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
private readonly Bindable<bool> favourited = new Bindable<bool>();
private PostBeatmapFavouriteRequest request;
private DimmedLoadingLayer loading;
[BackgroundDependencyLoader]
private void load()
private void load(IAPIProvider api)
{
Container pink;
SpriteIcon icon;
@ -55,6 +61,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
Size = new Vector2(18),
Shadow = false,
},
loading = new DimmedLoadingLayer(),
});
BeatmapSet.BindValueChanged(setInfo =>
@ -67,6 +74,8 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
favourited.ValueChanged += favourited =>
{
loading.Hide();
if (favourited.NewValue)
{
pink.FadeIn(200);
@ -78,6 +87,19 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
icon.Icon = FontAwesome.Regular.Heart;
}
};
Action = () =>
{
if (loading.State.Value == Visibility.Visible)
return;
loading.Show();
request?.Cancel();
request = new PostBeatmapFavouriteRequest(BeatmapSet.Value?.OnlineBeatmapSetID ?? 0, favourited.Value ? BeatmapFavouriteAction.UnFavourite : BeatmapFavouriteAction.Favourite);
request.Success += () => favourited.Value = !favourited.Value;
api.Queue(request);
};
}
protected override void UpdateAfterChildren()