Skip to content

Commit

Permalink
fix default selection for sorting and filter radio buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Jun 18, 2024
1 parent 3300027 commit 9d24aac
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Totoro.Core/ViewModels/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public void ObserveChanges()
UserListTableViewSettings
.OnColumnChanged()
.Merge(UserListTableViewSettings.OnColumnVisibilityChanged())
.Select(_ => Unit.Default)
.Merge(UserListTableViewSettings.WhenAnyValue(x => x.Sort).Select(_ => Unit.Default))
.Subscribe(_ => _localSettingsService.SaveSetting(Settings.UserListTableViewSettings, UserListTableViewSettings));

ObserveObject(TorrentSearchOptions, Settings.TorrentSearchOptions);
Expand Down
32 changes: 18 additions & 14 deletions Totoro.WinUI/Views/UserListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@

</Grid>

<!--Table Header of Table View-->
<Border Visibility="{x:Bind uhelp:Converters.BooleanToVisibility(ViewModel.IsListView), Mode=OneWay}"
Background="{ThemeResource CardBackgroundFillColorSecondaryBrush}"
Padding="26 0 60 0"
Expand Down Expand Up @@ -368,6 +369,7 @@
</ItemsControl>
</Border>

<!--Anime List-->
<ItemsView ItemsSource="{x:Bind ViewModel.Anime}"
SelectionMode="None"
Grid.Row="2"
Expand All @@ -378,6 +380,7 @@
</ItemsView.ItemTransitionProvider>
</ItemsView>

<!--Teaching Tips-->
<Grid Grid.Row="2">
<TeachingTip
x:Name="GenresTeachingTip"
Expand Down Expand Up @@ -484,17 +487,21 @@
<RadioMenuFlyoutItem
Click="AiringStatusClicked"
IsChecked="True"
GroupName="AiringStatus"
Text="All" />
<RadioMenuFlyoutItem
Click="AiringStatusClicked"
GroupName="AiringStatus"
Tag="{x:Bind cm:AiringStatus.CurrentlyAiring}"
Text="Currently airing" />
<RadioMenuFlyoutItem
Click="AiringStatusClicked"
GroupName="AiringStatus"
Tag="{x:Bind cm:AiringStatus.NotYetAired}"
Text="Not yet aired" />
<RadioMenuFlyoutItem
Click="AiringStatusClicked"
GroupName="AiringStatus"
Tag="{x:Bind cm:AiringStatus.FinishedAiring}"
Text="Finished airing" />
</MenuFlyout>
Expand Down Expand Up @@ -540,7 +547,7 @@
Icon="Sort"
Label="Sort">
<AppBarButton.Flyout>
<MenuFlyout>
<MenuFlyout x:Name="SortingFlyout">
<RadioMenuFlyoutItem
Command="{x:Bind ViewModel.SetSortProperty}"
CommandParameter="Title"
Expand Down Expand Up @@ -609,23 +616,20 @@

<AppBarButton Icon="View" Label="Display mode">
<AppBarButton.Flyout>
<MenuFlyout>
<MenuFlyoutItem
<MenuFlyout x:Name="DisplayModeFlyout">
<RadioMenuFlyoutItem
Command="{x:Bind ViewModel.SetDisplayMode}"
CommandParameter="{x:Bind cm:DisplayMode.Grid}"
Text="Grid view">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xf0e2;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
GroupName="Display Mode"
Text="Grid view"
Icon="{ui:FontIcon Glyph=&#xf0e2;}"/>

<RadioMenuFlyoutItem
Command="{x:Bind ViewModel.SetDisplayMode}"
CommandParameter="{x:Bind cm:DisplayMode.List}"
Text="List view">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xf0e4;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
GroupName="Display Mode"
Text="Table view"
Icon="{ui:FontIcon Glyph=&#xf0e4;}"/>
</MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
Expand Down
37 changes: 37 additions & 0 deletions Totoro.WinUI/Views/UserListPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Labs.WinUI;
using CommunityToolkit.WinUI;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -69,6 +70,42 @@ public UserListPage()
AnimeCollectionDataTemplateSelector.Mode = mode;
AnimeCollectionView.Layout = CreateLayout(mode);
});

this.WhenAnyValue(x => x.ViewModel.SelectedSortProperty)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(property =>
{
if (SortingFlyout.Items.OfType<RadioMenuFlyoutItem>().FirstOrDefault(x => x.CommandParameter?.Equals(property) == true) is not { } rm)
{
return;
}

rm.IsChecked = true;
});

this.WhenAnyValue(x => x.ViewModel.IsSortByAscending)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(isAscending =>
{
if (SortingFlyout.Items.OfType<RadioMenuFlyoutItem>().FirstOrDefault(x => x.CommandParameter?.Equals(isAscending) == true && x.GroupName == @"2") is not { } rm)
{
return;
}

rm.IsChecked = true;
});

this.WhenAnyValue(x => x.ViewModel.Mode)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(mode =>
{
if (DisplayModeFlyout.Items.OfType<RadioMenuFlyoutItem>().FirstOrDefault(x => x.CommandParameter?.Equals(mode) == true) is not { } rm)
{
return;
}

rm.IsChecked = true;
});
});
}

Expand Down

0 comments on commit 9d24aac

Please sign in to comment.