mirror of https://github.com/ppy/osu
Simplify offset calculation
This commit is contained in:
parent
2a66cf36d5
commit
066bee3535
|
@ -13,8 +13,8 @@ public class GetUserBeatmapsRequest : PaginatedAPIRequest<List<APIBeatmapSet>>
|
|||
|
||||
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;
|
||||
|
|
|
@ -10,8 +10,8 @@ public class GetUserMostPlayedBeatmapsRequest : PaginatedAPIRequest<List<APIUser
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ public class GetUserRecentActivitiesRequest : PaginatedAPIRequest<List<APIRecent
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ public class GetUserScoresRequest : PaginatedAPIRequest<List<APILegacyScoreInfo>
|
|||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<User> user, strin
|
|||
|
||||
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);
|
||||
|
|
|
@ -24,7 +24,7 @@ public PaginatedMostPlayedBeatmapContainer(Bindable<User> user)
|
|||
|
||||
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);
|
||||
|
|
|
@ -31,7 +31,7 @@ public PaginatedScoreContainer(ScoreType type, Bindable<User> user, string heade
|
|||
|
||||
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)
|
||||
|
|
|
@ -22,7 +22,7 @@ public PaginatedRecentActivityContainer(Bindable<User> user, string header, stri
|
|||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue