2020-07-09 01:02:14 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-05-19 12:36:05 +00:00
|
|
|
|
using System;
|
2021-05-26 12:35:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-09 01:02:14 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-05-26 12:35:38 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-07-09 01:02:14 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News.Displays
|
|
|
|
|
{
|
2021-05-20 06:24:01 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Lists articles in a vertical flow for a specified year.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ArticleListing : CompositeDrawable
|
2020-07-09 01:02:14 +00:00
|
|
|
|
{
|
2021-05-26 13:49:39 +00:00
|
|
|
|
private readonly Action fetchMorePosts;
|
2020-07-09 01:02:14 +00:00
|
|
|
|
|
2020-07-25 06:26:29 +00:00
|
|
|
|
private FillFlowContainer content;
|
|
|
|
|
private ShowMoreButton showMore;
|
2020-07-09 01:02:14 +00:00
|
|
|
|
|
2021-05-26 13:49:39 +00:00
|
|
|
|
private CancellationTokenSource cancellationToken;
|
|
|
|
|
|
|
|
|
|
public ArticleListing(Action fetchMorePosts)
|
|
|
|
|
{
|
|
|
|
|
this.fetchMorePosts = fetchMorePosts;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-25 06:26:29 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2020-07-09 01:02:14 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-05-26 13:35:11 +00:00
|
|
|
|
|
2020-07-09 01:02:14 +00:00
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Vertical = 20,
|
|
|
|
|
Left = 30,
|
|
|
|
|
Right = 50
|
|
|
|
|
};
|
2021-05-26 13:35:11 +00:00
|
|
|
|
|
2020-07-09 01:02:14 +00:00
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
content = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2021-05-26 12:35:38 +00:00
|
|
|
|
Spacing = new Vector2(0, 10)
|
2020-07-09 01:02:14 +00:00
|
|
|
|
},
|
|
|
|
|
showMore = new ShowMoreButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2021-05-26 13:35:11 +00:00
|
|
|
|
Margin = new MarginPadding { Top = 15 },
|
2021-05-26 13:49:39 +00:00
|
|
|
|
Action = fetchMorePosts,
|
2021-05-26 12:35:38 +00:00
|
|
|
|
Alpha = 0
|
2020-07-09 01:02:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-26 13:46:43 +00:00
|
|
|
|
public void AddPosts(IEnumerable<APINewsPost> posts, bool morePostsAvailable) => Schedule(() =>
|
2021-05-26 12:35:38 +00:00
|
|
|
|
LoadComponentsAsync(posts.Select(p => new NewsCard(p)).ToList(), loaded =>
|
2020-07-09 01:02:14 +00:00
|
|
|
|
{
|
2021-05-21 06:41:31 +00:00
|
|
|
|
content.AddRange(loaded);
|
2020-07-09 01:02:14 +00:00
|
|
|
|
showMore.IsLoading = false;
|
2021-05-26 13:46:43 +00:00
|
|
|
|
showMore.Alpha = morePostsAvailable ? 1 : 0;
|
|
|
|
|
}, (cancellationToken = new CancellationTokenSource()).Token)
|
|
|
|
|
);
|
|
|
|
|
|
2020-07-09 01:02:14 +00:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|