mirror of
https://github.com/osukey/osukey.git
synced 2025-05-06 14:17:27 +09:00
Tidy up code
This commit is contained in:
parent
7b09955d59
commit
8ffa7f4a5a
@ -6,7 +6,6 @@ using System.Threading;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Overlays.News;
|
using osu.Game.Overlays.News;
|
||||||
using osu.Game.Overlays.News.Displays;
|
using osu.Game.Overlays.News.Displays;
|
||||||
@ -22,9 +21,14 @@ namespace osu.Game.Overlays
|
|||||||
private readonly NewsSidebar sidebar;
|
private readonly NewsSidebar sidebar;
|
||||||
private readonly Container content;
|
private readonly Container content;
|
||||||
|
|
||||||
private APIRequest lastRequest;
|
private GetNewsRequest lastRequest;
|
||||||
|
|
||||||
private Cursor lastCursor;
|
private Cursor lastCursor;
|
||||||
private int? year;
|
|
||||||
|
/// <summary>
|
||||||
|
/// The year currently being displayed. If null, the main listing is being displayed.
|
||||||
|
/// </summary>
|
||||||
|
private int? displayedYear;
|
||||||
|
|
||||||
private CancellationTokenSource cancellationToken;
|
private CancellationTokenSource cancellationToken;
|
||||||
|
|
||||||
@ -100,7 +104,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public void ShowYear(int year)
|
public void ShowYear(int year)
|
||||||
{
|
{
|
||||||
loadFrontPage(year);
|
loadListing(year);
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,18 +134,18 @@ namespace osu.Game.Overlays
|
|||||||
private void onArticleChanged(ValueChangedEvent<string> article)
|
private void onArticleChanged(ValueChangedEvent<string> article)
|
||||||
{
|
{
|
||||||
if (article.NewValue == null)
|
if (article.NewValue == null)
|
||||||
loadFrontPage();
|
loadListing();
|
||||||
else
|
else
|
||||||
loadArticle(article.NewValue);
|
loadArticle(article.NewValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadFrontPage(int? year = null)
|
private void loadListing(int? year = null)
|
||||||
{
|
{
|
||||||
beginLoading();
|
beginLoading();
|
||||||
|
|
||||||
Header.SetFrontPage();
|
Header.SetFrontPage();
|
||||||
|
|
||||||
this.year = year;
|
displayedYear = year;
|
||||||
lastCursor = null;
|
lastCursor = null;
|
||||||
|
|
||||||
performListingRequest(response =>
|
performListingRequest(response =>
|
||||||
@ -165,19 +169,6 @@ namespace osu.Game.Overlays
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performListingRequest(Action<GetNewsResponse> onSuccess)
|
|
||||||
{
|
|
||||||
lastRequest = new GetNewsRequest(year, lastCursor);
|
|
||||||
|
|
||||||
((GetNewsRequest)lastRequest).Success += response => Schedule(() =>
|
|
||||||
{
|
|
||||||
lastCursor = response.Cursor;
|
|
||||||
onSuccess?.Invoke(response);
|
|
||||||
});
|
|
||||||
|
|
||||||
API.PerformAsync(lastRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadArticle(string article)
|
private void loadArticle(string article)
|
||||||
{
|
{
|
||||||
beginLoading();
|
beginLoading();
|
||||||
@ -188,6 +179,18 @@ namespace osu.Game.Overlays
|
|||||||
LoadDisplay(Empty());
|
LoadDisplay(Empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void performListingRequest(Action<GetNewsResponse> onSuccess)
|
||||||
|
{
|
||||||
|
lastRequest = new GetNewsRequest(displayedYear, lastCursor);
|
||||||
|
lastRequest.Success += response => Schedule(() =>
|
||||||
|
{
|
||||||
|
lastCursor = response.Cursor;
|
||||||
|
onSuccess?.Invoke(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
API.PerformAsync(lastRequest);
|
||||||
|
}
|
||||||
|
|
||||||
private void beginLoading()
|
private void beginLoading()
|
||||||
{
|
{
|
||||||
lastRequest?.Cancel();
|
lastRequest?.Cancel();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user