mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Refactor PaginatedContainer to centralise repetitive logic
This commit is contained in:
@ -4,48 +4,24 @@
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Users;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.API;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Kudosu
|
||||
{
|
||||
public class PaginatedKudosuHistoryContainer : PaginatedContainer
|
||||
public class PaginatedKudosuHistoryContainer : PaginatedContainer<APIKudosuHistory>
|
||||
{
|
||||
private GetUserKudosuHistoryRequest request;
|
||||
|
||||
public PaginatedKudosuHistoryContainer(Bindable<User> user, string header, string missing)
|
||||
: base(user, header, missing)
|
||||
{
|
||||
ItemsPerPage = 5;
|
||||
}
|
||||
|
||||
protected override void ShowMore()
|
||||
{
|
||||
request = new GetUserKudosuHistoryRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
|
||||
request.Success += items => Schedule(() =>
|
||||
{
|
||||
MoreButton.FadeTo(items.Count == ItemsPerPage ? 1 : 0);
|
||||
MoreButton.IsLoading = false;
|
||||
protected override APIRequest<List<APIKudosuHistory>> CreateRequest()
|
||||
=> new GetUserKudosuHistoryRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
|
||||
|
||||
if (!items.Any() && VisiblePages == 1)
|
||||
{
|
||||
MissingText.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
MissingText.Hide();
|
||||
|
||||
foreach (var item in items)
|
||||
ItemsContainer.Add(new DrawableKudosuHistoryItem(item));
|
||||
});
|
||||
|
||||
Api.Queue(request);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
request?.Cancel();
|
||||
}
|
||||
protected override Drawable CreateDrawableItem(APIKudosuHistory item) => new DrawableKudosuHistoryItem(item);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user