Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
直播页与历史记录页支持自动刷新 (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Oct 10, 2022
1 parent 8f2d634 commit 8e85ebb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/App/Pages/Desktop/LiveFeedPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Richasy. All rights reserved.

using Bili.App.Pages.Base;
using Windows.UI.Xaml.Navigation;

namespace Bili.App.Pages.Desktop
{
Expand All @@ -21,5 +22,9 @@ protected override void OnPageLoaded()
/// <inheritdoc/>
protected override void OnPageUnloaded()
=> Bindings.StopTracking();

/// <inheritdoc/>
protected override void OnNavigatedFrom(NavigationEventArgs e)
=> ViewModel.ResetStateCommand.Execute(null);
}
}
5 changes: 5 additions & 0 deletions src/App/Pages/Desktop/Overlay/HistoryPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Bili.ViewModels.Interfaces.Account;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Bili.App.Pages.Desktop.Overlay
{
Expand All @@ -29,6 +30,10 @@ protected override void OnPageLoaded()
protected override void OnPageUnloaded()
=> Bindings.StopTracking();

/// <inheritdoc/>
protected override void OnNavigatedFrom(NavigationEventArgs e)
=> ViewModel.ResetStateCommand.Execute(null);

private async void OnClearButtonClickAsync(object sender, RoutedEventArgs e)
{
var isClear = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Collections.ObjectModel;
using System.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace Bili.ViewModels.Interfaces
{
Expand All @@ -15,5 +16,10 @@ public interface IInformationFlowViewModel<T> : INotifyPropertyChanged, IInitial
/// 视频集合.
/// </summary>
ObservableCollection<T> Items { get; }

/// <summary>
/// 重置状态的命令.
/// </summary>
IRelayCommand ResetStateCommand { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public partial class InformationFlowViewModelBase<T>
/// <inheritdoc/>
public IAsyncRelayCommand IncrementalCommand { get; }

/// <inheritdoc/>
public IRelayCommand ResetStateCommand { get; }

/// <inheritdoc/>
public ObservableCollection<T> Items { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal InformationFlowViewModelBase(CoreDispatcher dispatcher)
_dispatcher = dispatcher;
Items = new ObservableCollection<T>();

ResetStateCommand = new RelayCommand(ResetState);
InitializeCommand = new AsyncRelayCommand(InitializeAsync);
ReloadCommand = new AsyncRelayCommand(ReloadAsync);
IncrementalCommand = new AsyncRelayCommand(IncrementalAsync);
Expand Down Expand Up @@ -83,11 +84,16 @@ private async Task InitializeAsync()
await ReloadAsync();
}

private async Task ReloadAsync()
private void ResetState()
{
BeforeReload();
TryClear(Items);
ClearException();
}

private async Task ReloadAsync()
{
ResetState();

var task = _dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
Expand Down

0 comments on commit 8e85ebb

Please sign in to comment.