Skip to content

Commit

Permalink
Emergency fix for duplicate streams opening when changing page and go…
Browse files Browse the repository at this point in the history
…ing back
  • Loading branch information
Mrcubix committed Nov 21, 2023
1 parent ad269e6 commit e702a50
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions WhoIsLive.UX/ViewModels/Screens/StreamsBrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ private void ChangePage(int page, bool doRecalculation = true)
{
Page = page;

UnsubscribeFromEvents();

CurrentPageLiveStreams.Clear();

if (doRecalculation)
Expand All @@ -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);
Expand Down Expand Up @@ -328,6 +339,7 @@ private void FillPage(int fromIndex)
var stream = _liveStreams[i];

CurrentPageLiveStreams.Add(stream);

stream.BlockRequested += OnBlockRequested;
stream.OpenRequested += OnOpenRequested;
}
Expand Down

0 comments on commit e702a50

Please sign in to comment.