1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 14:12:56 +08:00

Simplify offset calculation

This commit is contained in:
smoogipoo 2019-07-19 16:02:33 +09:00
parent 2a66cf36d5
commit 066bee3535
9 changed files with 19 additions and 19 deletions

View File

@ -13,8 +13,8 @@ namespace osu.Game.Online.API.Requests
private readonly BeatmapSetType type;
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, int offset = 0, int limit = 6)
: base(offset, limit)
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, int page = 0, int itemsPerPage = 6)
: base(page, itemsPerPage)
{
this.userId = userId;
this.type = type;

View File

@ -10,8 +10,8 @@ namespace osu.Game.Online.API.Requests
{
private readonly long userId;
public GetUserMostPlayedBeatmapsRequest(long userId, int offset = 0, int limit = 5)
: base(offset, limit)
public GetUserMostPlayedBeatmapsRequest(long userId, int page = 0, int itemsPerPage = 5)
: base(page, itemsPerPage)
{
this.userId = userId;
}

View File

@ -10,8 +10,8 @@ namespace osu.Game.Online.API.Requests
{
private readonly long userId;
public GetUserRecentActivitiesRequest(long userId, int offset = 0, int limit = 5)
: base(offset, limit)
public GetUserRecentActivitiesRequest(long userId, int page = 0, int itemsPerPage = 5)
: base(page, itemsPerPage)
{
this.userId = userId;
}

View File

@ -11,8 +11,8 @@ namespace osu.Game.Online.API.Requests
private readonly long userId;
private readonly ScoreType type;
public GetUserScoresRequest(long userId, ScoreType type, int offset = 0, int limit = 5)
: base(offset, limit)
public GetUserScoresRequest(long userId, ScoreType type, int page = 0, int itemsPerPage = 5)
: base(page, itemsPerPage)
{
this.userId = userId;
this.type = type;

View File

@ -8,21 +8,21 @@ namespace osu.Game.Online.API.Requests
{
public abstract class PaginatedAPIRequest<T> : APIRequest<T>
{
private readonly int offset;
private readonly int limit;
private readonly int page;
private readonly int itemsPerPage;
protected PaginatedAPIRequest(int offset, int limit)
protected PaginatedAPIRequest(int page, int itemsPerPage)
{
this.offset = offset;
this.limit = limit;
this.page = page;
this.itemsPerPage = itemsPerPage;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("offset", offset.ToString(CultureInfo.InvariantCulture));
req.AddParameter("limit", limit.ToString(CultureInfo.InvariantCulture));
req.AddParameter("offset", (page * itemsPerPage).ToString(CultureInfo.InvariantCulture));
req.AddParameter("limit", itemsPerPage.ToString(CultureInfo.InvariantCulture));
return req;
}

View File

@ -29,7 +29,7 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
protected override void ShowMore()
{
request = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage, ItemsPerPage);
request = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
request.Success += sets => Schedule(() =>
{
MoreButton.FadeTo(sets.Count == ItemsPerPage ? 1 : 0);

View File

@ -24,7 +24,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
protected override void ShowMore()
{
request = new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++ * ItemsPerPage, ItemsPerPage);
request = new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
request.Success += beatmaps => Schedule(() =>
{
MoreButton.FadeTo(beatmaps.Count == ItemsPerPage ? 1 : 0);

View File

@ -31,7 +31,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
protected override void ShowMore()
{
request = new GetUserScoresRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage, ItemsPerPage);
request = new GetUserScoresRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
request.Success += scores => Schedule(() =>
{
foreach (var s in scores)

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
protected override void ShowMore()
{
request = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage, ItemsPerPage);
request = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
request.Success += activities => Schedule(() =>
{
MoreButton.FadeTo(activities.Count == ItemsPerPage ? 1 : 0);