From e702a5026b5cb81337c306ba6023036d14e39eca Mon Sep 17 00:00:00 2001 From: Mrcubix Date: Tue, 21 Nov 2023 04:53:52 +0100 Subject: [PATCH] Emergency fix for duplicate streams opening when changing page and going back --- .../ViewModels/Screens/StreamsBrowserViewModel.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/WhoIsLive.UX/ViewModels/Screens/StreamsBrowserViewModel.cs b/WhoIsLive.UX/ViewModels/Screens/StreamsBrowserViewModel.cs index 694b21c..741d37b 100644 --- a/WhoIsLive.UX/ViewModels/Screens/StreamsBrowserViewModel.cs +++ b/WhoIsLive.UX/ViewModels/Screens/StreamsBrowserViewModel.cs @@ -287,6 +287,8 @@ private void ChangePage(int page, bool doRecalculation = true) { Page = page; + UnsubscribeFromEvents(); + CurrentPageLiveStreams.Clear(); if (doRecalculation) @@ -295,6 +297,15 @@ private void ChangePage(int page, bool doRecalculation = true) FillPage((Page - 1) * _elementsPerPage); } + public void UnsubscribeFromEvents() + { + foreach (var stream in CurrentPageLiveStreams) + { + stream.BlockRequested -= OnBlockRequested; + stream.OpenRequested -= OnOpenRequested; + } + } + public void RecalculatePageCount() { PageCount = (int)Math.Ceiling((double)_liveStreams.Count / _elementsPerPage); @@ -328,6 +339,7 @@ private void FillPage(int fromIndex) var stream = _liveStreams[i]; CurrentPageLiveStreams.Add(stream); + stream.BlockRequested += OnBlockRequested; stream.OpenRequested += OnOpenRequested; }