From 735e7b9c741e2bc0d4d29df6e880daf5ff44a665 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 26 May 2021 22:49:39 +0900 Subject: [PATCH] Pass fetch more action in via ctor to avoid potential nullref --- osu.Game/Overlays/News/Displays/ArticleListing.cs | 13 +++++++++---- osu.Game/Overlays/NewsOverlay.cs | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/News/Displays/ArticleListing.cs b/osu.Game/Overlays/News/Displays/ArticleListing.cs index 48a3f5498a..dc3b17b323 100644 --- a/osu.Game/Overlays/News/Displays/ArticleListing.cs +++ b/osu.Game/Overlays/News/Displays/ArticleListing.cs @@ -19,11 +19,18 @@ namespace osu.Game.Overlays.News.Displays /// public class ArticleListing : CompositeDrawable { - public Action RequestMorePosts; + private readonly Action fetchMorePosts; private FillFlowContainer content; private ShowMoreButton showMore; + private CancellationTokenSource cancellationToken; + + public ArticleListing(Action fetchMorePosts) + { + this.fetchMorePosts = fetchMorePosts; + } + [BackgroundDependencyLoader] private void load() { @@ -59,7 +66,7 @@ namespace osu.Game.Overlays.News.Displays Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, Margin = new MarginPadding { Top = 15 }, - Action = RequestMorePosts, + Action = fetchMorePosts, Alpha = 0 } } @@ -75,8 +82,6 @@ namespace osu.Game.Overlays.News.Displays }, (cancellationToken = new CancellationTokenSource()).Token) ); - private CancellationTokenSource cancellationToken; - protected override void Dispose(bool isDisposing) { cancellationToken?.Cancel(); diff --git a/osu.Game/Overlays/NewsOverlay.cs b/osu.Game/Overlays/NewsOverlay.cs index 34bacd5540..12e3f81ca1 100644 --- a/osu.Game/Overlays/NewsOverlay.cs +++ b/osu.Game/Overlays/NewsOverlay.cs @@ -152,7 +152,7 @@ namespace osu.Game.Overlays lastCursor = response.Cursor; sidebar.Metadata.Value = response.SidebarMetadata; - var listing = new ArticleListing { RequestMorePosts = getMorePosts }; + var listing = new ArticleListing(getMorePosts); listing.AddPosts(response.NewsPosts, response.Cursor != null); LoadDisplay(listing); });