From 9947867e8408e8f2d0d4296061c9f67ea3bf1ffe Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 26 May 2021 22:46:43 +0900 Subject: [PATCH] Remove unnecessary bindable flow --- .../Overlays/News/Displays/ArticleListing.cs | 42 +++---------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/osu.Game/Overlays/News/Displays/ArticleListing.cs b/osu.Game/Overlays/News/Displays/ArticleListing.cs index 3524b8652c..48a3f5498a 100644 --- a/osu.Game/Overlays/News/Displays/ArticleListing.cs +++ b/osu.Game/Overlays/News/Displays/ArticleListing.cs @@ -3,11 +3,9 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; using System.Threading; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.UserInterface; @@ -23,9 +21,6 @@ namespace osu.Game.Overlays.News.Displays { public Action RequestMorePosts; - private readonly BindableList posts = new BindableList(); - private bool showMoreButtonIsVisible; - private FillFlowContainer content; private ShowMoreButton showMore; @@ -71,41 +66,16 @@ namespace osu.Game.Overlays.News.Displays }; } - protected override void LoadComplete() - { - base.LoadComplete(); - - posts.BindCollectionChanged((sender, args) => - { - switch (args.Action) - { - case NotifyCollectionChangedAction.Add: - addPosts(args.NewItems.Cast()); - break; - - default: - throw new NotSupportedException(@"You can only add items to this list. Other actions are not supported."); - } - }, true); - } - - public void AddPosts(IEnumerable posts, bool showMoreButtonIsVisible) - { - this.showMoreButtonIsVisible = showMoreButtonIsVisible; - this.posts.AddRange(posts); - } - - private CancellationTokenSource cancellationToken; - - private void addPosts(IEnumerable posts) - { + public void AddPosts(IEnumerable posts, bool morePostsAvailable) => Schedule(() => LoadComponentsAsync(posts.Select(p => new NewsCard(p)).ToList(), loaded => { content.AddRange(loaded); showMore.IsLoading = false; - showMore.Alpha = showMoreButtonIsVisible ? 1 : 0; - }, (cancellationToken = new CancellationTokenSource()).Token); - } + showMore.Alpha = morePostsAvailable ? 1 : 0; + }, (cancellationToken = new CancellationTokenSource()).Token) + ); + + private CancellationTokenSource cancellationToken; protected override void Dispose(bool isDisposing) {