1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-14 08:13:21 +08:00

Refactor MonthDropdown to ensure all the posts are within a given month

This commit is contained in:
Andrei Zavatski 2021-05-11 22:34:01 +03:00
parent b0297c6324
commit f4801c08ff
2 changed files with 13 additions and 5 deletions

View File

@ -14,6 +14,7 @@ using System.Linq;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using System.Diagnostics;
namespace osu.Game.Overlays.News.Sidebar
{
@ -26,8 +27,10 @@ namespace osu.Game.Overlays.News.Sidebar
private readonly FillFlowContainer postsFlow;
public MonthDropdown(IEnumerable<APINewsPost> posts)
public MonthDropdown(int month, int year, IEnumerable<APINewsPost> posts)
{
Debug.Assert(posts.All(p => p.PublishedAt.Month == month && p.PublishedAt.Year == year));
RelativeSizeAxes = Axes.X;
Masking = true;
InternalChild = new FillFlowContainer
@ -38,7 +41,7 @@ namespace osu.Game.Overlays.News.Sidebar
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
new DropdownHeader(posts.ElementAt(0).PublishedAt)
new DropdownHeader(month, year)
{
IsOpen = { BindTarget = IsOpen }
},
@ -102,8 +105,10 @@ namespace osu.Game.Overlays.News.Sidebar
private readonly SpriteIcon icon;
public DropdownHeader(DateTimeOffset date)
public DropdownHeader(int month, int year)
{
var date = new DateTime(year, month, 1);
RelativeSizeAxes = Axes.X;
Height = header_height;
Action = IsOpen.Toggle;

View File

@ -86,11 +86,14 @@ namespace osu.Game.Overlays.News.Sidebar
var keys = lookup.Select(kvp => kvp.Key);
var sortedKeys = keys.OrderByDescending(k => k).ToList();
var year = metadata.NewValue.CurrentYear;
for (int i = 0; i < sortedKeys.Count; i++)
{
var posts = lookup[sortedKeys[i]];
var month = sortedKeys[i];
var posts = lookup[month];
monthsFlow.Add(new MonthDropdown(posts)
monthsFlow.Add(new MonthDropdown(month, year, posts)
{
IsOpen = { Value = i == 0 }
});