diff --git a/Totoro.Core/ViewModels/UserListViewModel.cs b/Totoro.Core/ViewModels/UserListViewModel.cs index 1b00f07..2bb33b0 100644 --- a/Totoro.Core/ViewModels/UserListViewModel.cs +++ b/Totoro.Core/ViewModels/UserListViewModel.cs @@ -32,10 +32,8 @@ public UserListViewModel(ITrackingServiceContext trackingService, ChangeCurrentViewCommand = ReactiveCommand.Create(x => Filter.ListStatus = x); RefreshCommand = ReactiveCommand.CreateFromTask(SetInitialState, this.WhenAnyValue(x => x.ViewState).Select(x => x is not ViewState.Loading)); - SetDisplayMode = ReactiveCommand.Create(x => Mode = x); SetSortProperty = ReactiveCommand.Create(columnName => SelectedSortProperty = columnName); SetSortOrder = ReactiveCommand.Create(isAscending => IsSortByAscending = isAscending); - Mode = settings.ListDisplayMode; GridViewSettings = settings.UserListGridViewSettings; DataGridSettings = SettingsModel.UserListTableViewSettings; (SelectedSortProperty, IsSortByAscending) = DataGridSettings.Sort; @@ -90,29 +88,9 @@ public UserListViewModel(ITrackingServiceContext trackingService, .Select(x => x == DisplayMode.List) .ToPropertyEx(this, x => x.IsListView) .DisposeWith(Garbage); - - this.WhenAnyValue(x => x.Mode) - .Subscribe(m => settings.ListDisplayMode = m); - - Observable.Timer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)) - .Where(_ => Mode == DisplayMode.Grid) - .ObserveOn(RxApp.MainThreadScheduler) - .Subscribe(_ => - { - try - { - foreach (var item in Anime.Where(x => x.NextEpisodeAt is not null)) - { - item.RaisePropertyChanged(nameof(item.NextEpisodeAt)); - } - } - catch { } - }, RxApp.DefaultExceptionHandler.OnError) - .DisposeWith(Garbage); } [Reactive] public ViewState ViewState { get; set; } - [Reactive] public DisplayMode Mode { get; set; } [Reactive] public List Genres { get; set; } [Reactive] public AnimeCollectionFilter Filter { get; set; } = new(); [Reactive] public DataGridSettings DataGridSettings { get; set; } diff --git a/Totoro.WinUI/LoadingViews/TableLoadingView.xaml b/Totoro.WinUI/LoadingViews/TableLoadingView.xaml new file mode 100644 index 0000000..80c3993 --- /dev/null +++ b/Totoro.WinUI/LoadingViews/TableLoadingView.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Totoro.WinUI/LoadingViews/TableLoadingView.xaml.cs b/Totoro.WinUI/LoadingViews/TableLoadingView.xaml.cs new file mode 100644 index 0000000..76ad8ee --- /dev/null +++ b/Totoro.WinUI/LoadingViews/TableLoadingView.xaml.cs @@ -0,0 +1,14 @@ +using Microsoft.UI.Xaml.Controls; + + +namespace Totoro.WinUI.LoadingViews; + +public sealed partial class TableLoadingView : UserControl +{ + public List DummyList { get; } = [.. Enumerable.Range(1, 5)]; + + public TableLoadingView() + { + InitializeComponent(); + } +} diff --git a/Totoro.WinUI/Totoro.WinUI.csproj b/Totoro.WinUI/Totoro.WinUI.csproj index f4d7bba..a05505e 100644 --- a/Totoro.WinUI/Totoro.WinUI.csproj +++ b/Totoro.WinUI/Totoro.WinUI.csproj @@ -100,6 +100,10 @@ Always + + $(DefaultXamlRuntime) + MSBuild:Compile + MSBuild:Compile diff --git a/Totoro.WinUI/Views/SettingsSections/PreferencesSection.xaml b/Totoro.WinUI/Views/SettingsSections/PreferencesSection.xaml index c9767ed..b44ff9f 100644 --- a/Totoro.WinUI/Views/SettingsSections/PreferencesSection.xaml +++ b/Totoro.WinUI/Views/SettingsSections/PreferencesSection.xaml @@ -50,14 +50,6 @@ SelectedItem="{x:Bind ViewModel.Settings.ListDisplayMode, Mode=TwoWay}" /> - - - + + + + + + + + @@ -618,14 +625,14 @@ Scores { get; } = [null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + private static readonly ISettings _settings = App.GetService(); + + + public DisplayMode Mode + { + get { return (DisplayMode)GetValue(ModeProperty); } + set { SetValue(ModeProperty, value); } + } + + public static readonly DependencyProperty ModeProperty = + DependencyProperty.Register("Mode", typeof(DisplayMode), typeof(UserListPage), new PropertyMetadata(DisplayMode.Grid)); + + public static string ToStatusString(AnimeStatus status) { return status switch @@ -33,20 +46,25 @@ public static string ToStatusString(AnimeStatus status) } public static ICommand ViewInBrowser { get; } + public ICommand SetDisplayMode { get; } static UserListPage() { + ViewInBrowser = ReactiveCommand.CreateFromTask(LaunchUrl); } public UserListPage() { TableViewSettings = SettingsModel.UserListTableViewSettings; + SetDisplayMode = ReactiveCommand.Create(x => Mode = x); InitializeComponent(); this.WhenActivated(d => { + Mode = _settings.ListDisplayMode; + QuickAdd .Events() .Click @@ -63,12 +81,13 @@ public UserListPage() .Click .Subscribe(_ => GridViewSettingsTeachingTip.IsOpen ^= true); - this.WhenAnyValue(x => x.ViewModel.Mode) + this.WhenAnyValue(x => x.Mode) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(mode => { AnimeCollectionDataTemplateSelector.Mode = mode; AnimeCollectionView.Layout = CreateLayout(mode); + _settings.ListDisplayMode = mode; }); this.WhenAnyValue(x => x.ViewModel.SelectedSortProperty) @@ -95,7 +114,7 @@ public UserListPage() rm.IsChecked = true; }); - this.WhenAnyValue(x => x.ViewModel.Mode) + this.WhenAnyValue(x => x.Mode) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(mode => { @@ -106,6 +125,22 @@ public UserListPage() rm.IsChecked = true; }); + + Observable.Timer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)) + .ObserveOn(RxApp.MainThreadScheduler) + .Where(_ => Mode == DisplayMode.Grid) + .Subscribe(_ => + { + try + { + foreach (var item in ViewModel.Anime.Where(x => x.NextEpisodeAt is not null)) + { + item.RaisePropertyChanged(nameof(item.NextEpisodeAt)); + } + } + catch { } + }, RxApp.DefaultExceptionHandler.OnError) + .DisposeWith(ViewModel.Garbage); }); }