mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 15:33:21 +08:00
Add better xml documentation and extract fetch method
This commit is contained in:
parent
5464746d3d
commit
99e13b8ed9
@ -11,13 +11,18 @@ namespace osu.Game.Overlays
|
||||
/// <summary>
|
||||
/// A subview containing online content, to be displayed inside a <see cref="FullscreenOverlay"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Response type</typeparam>
|
||||
/// <remarks>
|
||||
/// Automatically performs a data fetch on load.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">The type of the API response.</typeparam>
|
||||
public abstract class OverlayView<T> : CompositeDrawable, IOnlineComponent
|
||||
where T : class
|
||||
{
|
||||
[Resolved]
|
||||
protected IAPIProvider API { get; private set; }
|
||||
|
||||
private APIRequest<T> request;
|
||||
|
||||
protected OverlayView()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
@ -30,20 +35,36 @@ namespace osu.Game.Overlays
|
||||
API.Register(this);
|
||||
}
|
||||
|
||||
private APIRequest<T> request;
|
||||
|
||||
/// <summary>
|
||||
/// Create the API request for fetching data.
|
||||
/// </summary>
|
||||
protected abstract APIRequest<T> CreateRequest();
|
||||
|
||||
/// <summary>
|
||||
/// Fired when results arrive from the main API request.
|
||||
/// </summary>
|
||||
/// <param name="response"></param>
|
||||
protected abstract void OnSuccess(T response);
|
||||
|
||||
/// <summary>
|
||||
/// Force a re-request for data from the API.
|
||||
/// </summary>
|
||||
protected void PerformFetch()
|
||||
{
|
||||
request?.Cancel();
|
||||
|
||||
request = CreateRequest();
|
||||
request.Success += response => Schedule(() => OnSuccess(response));
|
||||
|
||||
API.Queue(request);
|
||||
}
|
||||
|
||||
public virtual void APIStateChanged(IAPIProvider api, APIState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case APIState.Online:
|
||||
request = CreateRequest();
|
||||
request.Success += response => Schedule(() => OnSuccess(response));
|
||||
api.Queue(request);
|
||||
PerformFetch();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user