mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 04:42:58 +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>
|
/// <summary>
|
||||||
/// A subview containing online content, to be displayed inside a <see cref="FullscreenOverlay"/>.
|
/// A subview containing online content, to be displayed inside a <see cref="FullscreenOverlay"/>.
|
||||||
/// </summary>
|
/// </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
|
public abstract class OverlayView<T> : CompositeDrawable, IOnlineComponent
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
|
|
||||||
|
private APIRequest<T> request;
|
||||||
|
|
||||||
protected OverlayView()
|
protected OverlayView()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
@ -30,20 +35,36 @@ namespace osu.Game.Overlays
|
|||||||
API.Register(this);
|
API.Register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private APIRequest<T> request;
|
/// <summary>
|
||||||
|
/// Create the API request for fetching data.
|
||||||
|
/// </summary>
|
||||||
protected abstract APIRequest<T> CreateRequest();
|
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);
|
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)
|
public virtual void APIStateChanged(IAPIProvider api, APIState state)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case APIState.Online:
|
case APIState.Online:
|
||||||
request = CreateRequest();
|
PerformFetch();
|
||||||
request.Success += response => Schedule(() => OnSuccess(response));
|
|
||||||
api.Queue(request);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user