mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 19:22:54 +08:00
Move metadata change logic to it's own method
This commit is contained in:
parent
9603712aa1
commit
0a9c3c9413
@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestMetadata()
|
public void TestVisibility()
|
||||||
{
|
{
|
||||||
AddStep("Change metadata to null", () => metadataBindable.Value = null);
|
AddStep("Change metadata to null", () => metadataBindable.Value = null);
|
||||||
AddAssert("Panel is hidden", () => panel.IsPresent == false);
|
AddAssert("Panel is hidden", () => panel.IsPresent == false);
|
||||||
|
@ -66,26 +66,35 @@ namespace osu.Game.Overlays.News.Sidebar
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
Metadata.BindValueChanged(metadata =>
|
Metadata.BindValueChanged(onMetadataChanged, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onMetadataChanged(ValueChangedEvent<APINewsSidebar> metadata)
|
||||||
|
{
|
||||||
|
monthsFlow.Clear();
|
||||||
|
|
||||||
|
if (metadata.NewValue == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var allPosts = metadata.NewValue.NewsPosts;
|
||||||
|
|
||||||
|
if (!allPosts?.Any() ?? false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => post.PublishedAt.Month);
|
||||||
|
|
||||||
|
var keys = lookup.Select(kvp => kvp.Key);
|
||||||
|
var sortedKeys = keys.OrderByDescending(k => k).ToList();
|
||||||
|
|
||||||
|
for (int i = 0; i < sortedKeys.Count; i++)
|
||||||
{
|
{
|
||||||
monthsFlow.Clear();
|
var posts = lookup[sortedKeys[i]];
|
||||||
|
|
||||||
if (metadata.NewValue != null)
|
monthsFlow.Add(new MonthPanel(posts)
|
||||||
{
|
{
|
||||||
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => post.PublishedAt.Month);
|
IsOpen = { Value = i == 0 }
|
||||||
|
});
|
||||||
var keys = lookup.Select(kvp => kvp.Key);
|
}
|
||||||
var sortedKeys = keys.OrderByDescending(k => k).ToList();
|
|
||||||
|
|
||||||
for (int i = 0; i < sortedKeys.Count; i++)
|
|
||||||
{
|
|
||||||
monthsFlow.Add(new MonthPanel(lookup[sortedKeys[i]])
|
|
||||||
{
|
|
||||||
IsOpen = { Value = i == 0 }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user