mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:47:26 +08:00
Implement PostBeatmapFavouriteRequest
This commit is contained in:
parent
84c13b93fc
commit
2d707b2b65
36
osu.Game/Online/API/Requests/PostBeatmapFavouriteRequest.cs
Normal file
36
osu.Game/Online/API/Requests/PostBeatmapFavouriteRequest.cs
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.IO.Network;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class PostBeatmapFavouriteRequest : APIRequest
|
||||
{
|
||||
private readonly int id;
|
||||
private readonly BeatmapFavouriteAction action;
|
||||
|
||||
public PostBeatmapFavouriteRequest(int id, BeatmapFavouriteAction action)
|
||||
{
|
||||
this.id = id;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
req.Method = HttpMethod.Post;
|
||||
req.AddParameter(@"action", action.ToString().ToLowerInvariant());
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => $@"beatmapsets/{id}/favourites";
|
||||
}
|
||||
|
||||
public enum BeatmapFavouriteAction
|
||||
{
|
||||
Favourite,
|
||||
UnFavourite
|
||||
}
|
||||
}
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user