mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 06:52:56 +08:00
Cache metadata in NewsSideBar
This commit is contained in:
parent
e736240a06
commit
9603712aa1
@ -5,6 +5,9 @@ using osu.Framework.Graphics;
|
||||
using osu.Game.Overlays.News.Sidebar;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
@ -13,22 +16,35 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Cached]
|
||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||
|
||||
private readonly YearsPanel panel;
|
||||
[Cached]
|
||||
private readonly Bindable<APINewsSidebar> metadataBindable = new Bindable<APINewsSidebar>();
|
||||
|
||||
public TestSceneNewsYearsPanel()
|
||||
private YearsPanel panel;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Add(panel = new YearsPanel
|
||||
Child = panel = new YearsPanel
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
[Test]
|
||||
public void TestMetadata()
|
||||
{
|
||||
base.LoadComplete();
|
||||
AddStep("Load years", () => panel.Years = new[] { 1000, 2000, 3000, 4000 });
|
||||
AddStep("Load different years", () => panel.Years = new[] { 1001, 2001, 3001, 4001, 5001, 6001, 7001, 8001 });
|
||||
AddStep("Change metadata to null", () => metadataBindable.Value = null);
|
||||
AddAssert("Panel is hidden", () => panel.IsPresent == false);
|
||||
AddStep("Change metadata", () => metadataBindable.Value = metadata);
|
||||
AddAssert("Panel is visible", () => panel.IsPresent == true);
|
||||
AddStep("Change metadata to null", () => metadataBindable.Value = null);
|
||||
AddAssert("Panel is hidden", () => panel.IsPresent == false);
|
||||
}
|
||||
|
||||
private static readonly APINewsSidebar metadata = new APINewsSidebar
|
||||
{
|
||||
Years = new[] { 1001, 2001, 3001, 4001, 5001, 6001, 7001, 8001, 9001 }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user