1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 04:22:54 +08:00

Update paginated profile subsections to display items inline with web

This commit is contained in:
Salman Ahmed 2022-04-18 23:04:21 +03:00
parent 9d59cd408f
commit f08449e432
6 changed files with 27 additions and 20 deletions

View File

@ -20,11 +20,12 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
private const float panel_padding = 10f; private const float panel_padding = 10f;
private readonly BeatmapSetType type; private readonly BeatmapSetType type;
protected override int InitialItemsCount => type == BeatmapSetType.Graveyard ? 2 : 6;
public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<APIUser> user, LocalisableString headerText) public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<APIUser> user, LocalisableString headerText)
: base(user, headerText) : base(user, headerText)
{ {
this.type = type; this.type = type;
ItemsPerPage = 6;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -57,8 +58,8 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
} }
} }
protected override APIRequest<List<APIBeatmapSet>> CreateRequest() => protected override APIRequest<List<APIBeatmapSet>> CreateRequest(int itemsPerPage, int initialItems) =>
new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage); new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++, itemsPerPage, initialItems);
protected override Drawable CreateDrawableItem(APIBeatmapSet model) => model.OnlineID > 0 protected override Drawable CreateDrawableItem(APIBeatmapSet model) => model.OnlineID > 0
? new BeatmapCardNormal(model) ? new BeatmapCardNormal(model)

View File

@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
public PaginatedMostPlayedBeatmapContainer(Bindable<APIUser> user) public PaginatedMostPlayedBeatmapContainer(Bindable<APIUser> user)
: base(user, UsersStrings.ShowExtraHistoricalMostPlayedTitle) : base(user, UsersStrings.ShowExtraHistoricalMostPlayedTitle)
{ {
ItemsPerPage = 5;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -30,8 +29,8 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
protected override int GetCount(APIUser user) => user.BeatmapPlayCountsCount; protected override int GetCount(APIUser user) => user.BeatmapPlayCountsCount;
protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest() => protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest(int itemsPerPage, int initialItems) =>
new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++, ItemsPerPage); new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++, itemsPerPage, initialItems);
protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap mostPlayed) => protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap mostPlayed) =>
new DrawableMostPlayedBeatmap(mostPlayed); new DrawableMostPlayedBeatmap(mostPlayed);

View File

@ -17,11 +17,10 @@ namespace osu.Game.Overlays.Profile.Sections.Kudosu
public PaginatedKudosuHistoryContainer(Bindable<APIUser> user) public PaginatedKudosuHistoryContainer(Bindable<APIUser> user)
: base(user, missingText: UsersStrings.ShowExtraKudosuEntryEmpty) : base(user, missingText: UsersStrings.ShowExtraKudosuEntryEmpty)
{ {
ItemsPerPage = 5;
} }
protected override APIRequest<List<APIKudosuHistory>> CreateRequest() protected override APIRequest<List<APIKudosuHistory>> CreateRequest(int itemsPerPage, int initialItems)
=> new GetUserKudosuHistoryRequest(User.Value.Id, VisiblePages++, ItemsPerPage); => new GetUserKudosuHistoryRequest(User.Value.Id, VisiblePages++, itemsPerPage, initialItems);
protected override Drawable CreateDrawableItem(APIKudosuHistory item) => new DrawableKudosuHistoryItem(item); protected override Drawable CreateDrawableItem(APIKudosuHistory item) => new DrawableKudosuHistoryItem(item);
} }

View File

@ -21,11 +21,20 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
public abstract class PaginatedProfileSubsection<TModel> : ProfileSubsection public abstract class PaginatedProfileSubsection<TModel> : ProfileSubsection
{ {
/// <summary>
/// The number of items displayed per page.
/// </summary>
protected virtual int ItemsPerPage => 50;
/// <summary>
/// The number of items displayed initially.
/// </summary>
protected virtual int InitialItemsCount => 5;
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
protected int VisiblePages; protected int VisiblePages;
protected int ItemsPerPage;
protected ReverseChildIDFillFlowContainer<Drawable> ItemsContainer { get; private set; } protected ReverseChildIDFillFlowContainer<Drawable> ItemsContainer { get; private set; }
@ -101,7 +110,7 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
loadCancellation = new CancellationTokenSource(); loadCancellation = new CancellationTokenSource();
retrievalRequest = CreateRequest(); retrievalRequest = CreateRequest(ItemsPerPage, InitialItemsCount);
retrievalRequest.Success += UpdateItems; retrievalRequest.Success += UpdateItems;
api.Queue(retrievalRequest); api.Queue(retrievalRequest);
@ -125,7 +134,9 @@ namespace osu.Game.Overlays.Profile.Sections
LoadComponentsAsync(items.Select(CreateDrawableItem).Where(d => d != null), drawables => LoadComponentsAsync(items.Select(CreateDrawableItem).Where(d => d != null), drawables =>
{ {
missing.Hide(); missing.Hide();
moreButton.FadeTo(items.Count == ItemsPerPage ? 1 : 0);
int maxCount = VisiblePages == 1 ? InitialItemsCount : ItemsPerPage;
moreButton.FadeTo(items.Count == maxCount ? 1 : 0);
moreButton.IsLoading = false; moreButton.IsLoading = false;
ItemsContainer.AddRange(drawables); ItemsContainer.AddRange(drawables);
@ -138,7 +149,7 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
} }
protected abstract APIRequest<List<TModel>> CreateRequest(); protected abstract APIRequest<List<TModel>> CreateRequest(int itemsPerPage, int initialItems);
protected abstract Drawable CreateDrawableItem(TModel model); protected abstract Drawable CreateDrawableItem(TModel model);

View File

@ -23,8 +23,6 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
: base(user, headerText) : base(user, headerText)
{ {
this.type = type; this.type = type;
ItemsPerPage = 5;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -62,8 +60,8 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
base.OnItemsReceived(items); base.OnItemsReceived(items);
} }
protected override APIRequest<List<APIScore>> CreateRequest() => protected override APIRequest<List<APIScore>> CreateRequest(int itemsPerPage, int initialItems) =>
new GetUserScoresRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage); new GetUserScoresRequest(User.Value.Id, type, VisiblePages++, itemsPerPage, initialItems);
private int drawableItemIndex; private int drawableItemIndex;

View File

@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
public PaginatedRecentActivityContainer(Bindable<APIUser> user) public PaginatedRecentActivityContainer(Bindable<APIUser> user)
: base(user, missingText: EventsStrings.Empty) : base(user, missingText: EventsStrings.Empty)
{ {
ItemsPerPage = 10;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -28,8 +27,8 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
ItemsContainer.Spacing = new Vector2(0, 8); ItemsContainer.Spacing = new Vector2(0, 8);
} }
protected override APIRequest<List<APIRecentActivity>> CreateRequest() => protected override APIRequest<List<APIRecentActivity>> CreateRequest(int itemsPerPage, int initialItems) =>
new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++, ItemsPerPage); new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++, itemsPerPage, initialItems);
protected override Drawable CreateDrawableItem(APIRecentActivity model) => new DrawableRecentActivity(model); protected override Drawable CreateDrawableItem(APIRecentActivity model) => new DrawableRecentActivity(model);
} }