mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 15:44:04 +09:00
Cache metadata in NewsSideBar
This commit is contained in:
@ -14,9 +14,9 @@ namespace osu.Game.Overlays.News.Sidebar
|
||||
{
|
||||
public class NewsSideBar : CompositeDrawable
|
||||
{
|
||||
[Cached]
|
||||
public readonly Bindable<APINewsSidebar> Metadata = new Bindable<APINewsSidebar>();
|
||||
|
||||
private YearsPanel yearsPanel;
|
||||
private FillFlowContainer<MonthPanel> monthsFlow;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -49,7 +49,7 @@ namespace osu.Game.Overlays.News.Sidebar
|
||||
Spacing = new Vector2(0, 20),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
yearsPanel = new YearsPanel(),
|
||||
new YearsPanel(),
|
||||
monthsFlow = new FillFlowContainer<MonthPanel>
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
@ -70,15 +70,6 @@ namespace osu.Game.Overlays.News.Sidebar
|
||||
{
|
||||
monthsFlow.Clear();
|
||||
|
||||
if (metadata.NewValue == null)
|
||||
{
|
||||
yearsPanel.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
yearsPanel.Years = metadata.NewValue.Years;
|
||||
yearsPanel.Show();
|
||||
|
||||
if (metadata.NewValue != null)
|
||||
{
|
||||
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => post.PublishedAt.Month);
|
||||
|
@ -12,28 +12,21 @@ using osu.Game.Graphics.Sprites;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Bindables;
|
||||
using System.Collections.Specialized;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
|
||||
namespace osu.Game.Overlays.News.Sidebar
|
||||
{
|
||||
public class YearsPanel : CompositeDrawable
|
||||
{
|
||||
public int[] Years
|
||||
{
|
||||
set
|
||||
{
|
||||
years.Clear();
|
||||
years.AddRange(value);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly BindableList<int> years = new BindableList<int>();
|
||||
private readonly Bindable<APINewsSidebar> metadata = new Bindable<APINewsSidebar>();
|
||||
|
||||
private FillFlowContainer<YearButton> flow;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
private void load(OverlayColourProvider colourProvider, Bindable<APINewsSidebar> metadata)
|
||||
{
|
||||
this.metadata.BindTo(metadata);
|
||||
|
||||
Width = 160;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Masking = true;
|
||||
@ -64,14 +57,16 @@ namespace osu.Game.Overlays.News.Sidebar
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
years.BindCollectionChanged((u, v) =>
|
||||
metadata.BindValueChanged(m =>
|
||||
{
|
||||
switch (v.Action)
|
||||
if (m.NewValue == null)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
flow.Children = years.Select(y => new YearButton(y)).ToArray();
|
||||
break;
|
||||
Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
flow.Children = m.NewValue.Years.Select(y => new YearButton(y)).ToArray();
|
||||
Show();
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user