From 9a97a27c8a70117b09f076582a53a4f718721e86 Mon Sep 17 00:00:00 2001 From: Aleh Khantsevich Date: Mon, 19 Aug 2024 16:26:15 +0200 Subject: [PATCH 1/6] Init --- Wino.Mail.ViewModels/MailListPageViewModel.cs | 6 + Wino.Mail/Converters/GridLengthConverter.cs | 27 +++ Wino.Mail/Styles/Converters.xaml | 1 + Wino.Mail/Views/MailListPage.xaml | 93 +++------- Wino.Mail/Views/MailListPage.xaml.cs | 171 +++++++++--------- Wino.Mail/Wino.Mail.csproj | 1 + 6 files changed, 144 insertions(+), 155 deletions(-) create mode 100644 Wino.Mail/Converters/GridLengthConverter.cs diff --git a/Wino.Mail.ViewModels/MailListPageViewModel.cs b/Wino.Mail.ViewModels/MailListPageViewModel.cs index 0ea500c0..3a1900d5 100644 --- a/Wino.Mail.ViewModels/MailListPageViewModel.cs +++ b/Wino.Mail.ViewModels/MailListPageViewModel.cs @@ -120,6 +120,12 @@ public partial class MailListPageViewModel : BaseViewModel, [ObservableProperty] private string barMessage; + [ObservableProperty] + private double mailListLength = 300; + + [ObservableProperty] + private double maxMailListLength = 1200; + [ObservableProperty] private string barTitle; diff --git a/Wino.Mail/Converters/GridLengthConverter.cs b/Wino.Mail/Converters/GridLengthConverter.cs new file mode 100644 index 00000000..14eb8321 --- /dev/null +++ b/Wino.Mail/Converters/GridLengthConverter.cs @@ -0,0 +1,27 @@ +using System; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml; + +namespace Wino.Converters +{ + public class GridLengthConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, string language) + { + if (value is double doubleValue) + { + return new GridLength(doubleValue); + } + return new GridLength(1, GridUnitType.Auto); + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + if (value is GridLength gridLength) + { + return gridLength.Value; + } + return 0.0; + } + } +} diff --git a/Wino.Mail/Styles/Converters.xaml b/Wino.Mail/Styles/Converters.xaml index 0ef5e1cb..ec5a46a4 100644 --- a/Wino.Mail/Styles/Converters.xaml +++ b/Wino.Mail/Styles/Converters.xaml @@ -4,4 +4,5 @@ xmlns:converters="using:Wino.Converters"> + diff --git a/Wino.Mail/Views/MailListPage.xaml b/Wino.Mail/Views/MailListPage.xaml index 837ae05c..4a31671e 100644 --- a/Wino.Mail/Views/MailListPage.xaml +++ b/Wino.Mail/Views/MailListPage.xaml @@ -6,6 +6,7 @@ xmlns:collections="using:CommunityToolkit.Mvvm.Collections" xmlns:controls="using:Wino.Controls" xmlns:controls1="using:CommunityToolkit.WinUI.Controls" + xmlns:converters="using:Wino.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:domain="using:Wino.Core.Domain" xmlns:enums="using:Wino.Core.Domain.Enums" @@ -20,9 +21,8 @@ xmlns:ui="using:Microsoft.Toolkit.Uwp.UI" xmlns:viewModelData="using:Wino.Mail.ViewModels.Data" xmlns:wino="using:Wino" - xmlns:converters="using:Wino.Converters" x:Name="root" - Loaded="MailListPageLoaded" + SizeChanged="Page_SizeChanged" mc:Ignorable="d"> @@ -181,11 +181,11 @@ - + - + @@ -615,11 +612,11 @@ - - + + + + VerticalAlignment="Center" + Opacity="0.5" + Spacing="6"> - + + Text="{x:Bind ViewModel.SelectedMessageText, Mode=OneWay}" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Wino.Mail/Views/MailListPage.xaml.cs b/Wino.Mail/Views/MailListPage.xaml.cs index 80617854..b54b924f 100644 --- a/Wino.Mail/Views/MailListPage.xaml.cs +++ b/Wino.Mail/Views/MailListPage.xaml.cs @@ -42,6 +42,7 @@ public sealed partial class MailListPage : MailListPageAbstract, { private const string NarrowVisualStateKey = "NarrowState"; private const string AdaptivenessStatesKey = "AdaptiveStates"; + private const int RENDERING_COLUMN_MIN_WIDTH = 300; private IStatePersistanceService StatePersistanceService { get; } = App.Current.Services.GetService(); private IPreferencesService PreferencesService { get; } = App.Current.Services.GetService(); @@ -147,77 +148,6 @@ private void SelectAllCheckboxUnchecked(object sender, Windows.UI.Xaml.RoutedEve MailListView.ClearSelections(); } - #region Mostly UI - - private void UpdateAdaptiveness() - { - - bool shouldDisplayNoMessagePanel, shouldDisplayMailingList, shouldDisplayRenderingFrame; - - // This is the smallest state UI can get. - // Either mailing list or rendering grid is visible. - if (StatePersistanceService.IsReaderNarrowed) - { - // Start visibility checks by no message panel. - - bool isMultiSelectionEnabled = ViewModel.IsMultiSelectionModeEnabled || KeyPressService.IsCtrlKeyPressed(); - - shouldDisplayMailingList = isMultiSelectionEnabled ? true : (!ViewModel.HasSelectedItems || ViewModel.HasMultipleItemSelections); - shouldDisplayNoMessagePanel = shouldDisplayMailingList ? false : !ViewModel.HasSelectedItems || ViewModel.HasMultipleItemSelections; - shouldDisplayRenderingFrame = shouldDisplayMailingList ? false : !shouldDisplayNoMessagePanel; - } - else - { - shouldDisplayMailingList = true; - shouldDisplayNoMessagePanel = !ViewModel.HasSelectedItems || ViewModel.HasMultipleItemSelections; - shouldDisplayRenderingFrame = !shouldDisplayNoMessagePanel; - } - - ReaderGridContainer.Visibility = shouldDisplayMailingList ? Visibility.Visible : Visibility.Collapsed; - RenderingFrame.Visibility = shouldDisplayRenderingFrame ? Visibility.Visible : Visibility.Collapsed; - NoMailSelectedPanel.Visibility = shouldDisplayNoMessagePanel ? Visibility.Visible : Visibility.Collapsed; - - if (StatePersistanceService.IsReaderNarrowed) - { - if (RenderingFrame.Visibility == Visibility.Visible && ReaderGridContainer.Visibility == Visibility.Collapsed) - { - // Extend rendering frame to full width. - Grid.SetColumn(RenderingGrid, 0); - Grid.SetColumnSpan(RenderingGrid, 2); - - Grid.SetColumn(ReaderGrid, 0); - Grid.SetColumnSpan(ReaderGrid, 2); - } - else if (RenderingFrame.Visibility == Visibility.Collapsed && NoMailSelectedPanel.Visibility == Visibility.Collapsed) - { - // Only mail list is available. - // Extend the mailing list. - Grid.SetColumn(ReaderGridContainer, 0); - Grid.SetColumnSpan(ReaderGridContainer, 2); - } - } - else - { - // Mailing list is always visible on the first part. - - Grid.SetColumn(ReaderGridContainer, 0); - Grid.SetColumnSpan(ReaderGridContainer, 1); - - // Rendering grid should take the rest of the space. - Grid.SetColumn(RenderingGrid, 1); - Grid.SetColumnSpan(RenderingGrid, 1); - } - } - - private void AdaptivenessChanged(object sender, VisualStateChangedEventArgs e) - { - StatePersistanceService.IsReaderNarrowed = e.NewState.Name == "NarrowState"; - - UpdateAdaptiveness(); - } - - #endregion - void IRecipient.Receive(ResetSingleMailItemSelectionEvent message) { // Single item in thread selected. @@ -329,7 +259,7 @@ void IRecipient.Receive(ActiveMailItemChangedEvent m } } - UpdateAdaptiveness(); + UpdateAdaptiveness1(); } private bool IsRenderingPageActive() => RenderingFrame.Content is MailRenderingPage; @@ -379,7 +309,7 @@ private WebView2 GetComposerPageWebView() public void Receive(ActiveMailFolderChangedEvent message) { - UpdateAdaptiveness(); + UpdateAdaptiveness1(); } public async void Receive(SelectMailItemContainerEvent message) @@ -433,7 +363,7 @@ await ViewModel.ExecuteUIThread(async () => public void Receive(ShellStateUpdated message) { - UpdateAdaptiveness(); + UpdateAdaptiveness1(); } private void SearchBoxFocused(object sender, RoutedEventArgs e) @@ -446,21 +376,6 @@ private void SearchBarUnfocused(object sender, RoutedEventArgs e) SearchBar.PlaceholderText = Translator.SearchBarPlaceholder; } - private void MailListPageLoaded(object sender, RoutedEventArgs e) - { - // App might open with narrowed state. - // VSM will not trigger in this case. - // Set values to force updating adaptiveness. - - var groups = VisualStateManager.GetVisualStateGroups(RootGrid); - var adaptiveState = groups.FirstOrDefault(a => a.Name == AdaptivenessStatesKey); - - if (adaptiveState == null) return; - - // This should force UpdateAdaptiveness call. - StatePersistanceService.IsReaderNarrowed = adaptiveState.CurrentState.Name == NarrowVisualStateKey; - } - private void ProcessMailItemKeyboardAccelerator(UIElement sender, ProcessKeyboardAcceleratorEventArgs args) { if (args.Key == Windows.System.VirtualKey.Delete) @@ -568,5 +483,83 @@ public void Receive(DisposeRenderingFrameRequested message) { ViewModel.NavigationService.Navigate(WinoPage.IdlePage, null, NavigationReferenceFrame.RenderingFrame, NavigationTransitionType.DrillIn); } + + private void Page_SizeChanged(object sender, SizeChangedEventArgs e) + { + ViewModel.MaxMailListLength = e.NewSize.Width - RENDERING_COLUMN_MIN_WIDTH; + + StatePersistanceService.IsReaderNarrowed = e.NewSize.Width < StatePersistanceService.MailListPaneLength + RENDERING_COLUMN_MIN_WIDTH; + + UpdateAdaptiveness1(); + } + + private void UpdateAdaptiveness1() + { + bool shouldDisplayNoMessagePanel, shouldDisplayMailingList, shouldDisplayRenderingFrame; + + // This is the smallest state UI can get. + // Either mailing list or rendering grid is visible. + if (StatePersistanceService.IsReaderNarrowed) + { + // Start visibility checks by no message panel. + + bool isMultiSelectionEnabled = ViewModel.IsMultiSelectionModeEnabled || KeyPressService.IsCtrlKeyPressed(); + + shouldDisplayMailingList = isMultiSelectionEnabled ? true : (!ViewModel.HasSelectedItems || ViewModel.HasMultipleItemSelections); + shouldDisplayNoMessagePanel = shouldDisplayMailingList ? false : !ViewModel.HasSelectedItems || ViewModel.HasMultipleItemSelections; + shouldDisplayRenderingFrame = shouldDisplayMailingList ? false : !shouldDisplayNoMessagePanel; + } + else + { + shouldDisplayMailingList = true; + shouldDisplayNoMessagePanel = !ViewModel.HasSelectedItems || ViewModel.HasMultipleItemSelections; + shouldDisplayRenderingFrame = !shouldDisplayNoMessagePanel; + } + + MailListContainer.Visibility = shouldDisplayMailingList ? Visibility.Visible : Visibility.Collapsed; + RenderingFrame.Visibility = shouldDisplayRenderingFrame ? Visibility.Visible : Visibility.Collapsed; + NoMailSelectedPanel.Visibility = shouldDisplayNoMessagePanel ? Visibility.Visible : Visibility.Collapsed; + + if (StatePersistanceService.IsReaderNarrowed == true) + { + if (ViewModel.HasSelectedItems) + { + MailListColumn.Width = new GridLength(0); + RendererColumn.Width = new GridLength(1, GridUnitType.Star); + + Grid.SetColumn(MailListContainer, 0); + Grid.SetColumnSpan(RenderingGrid, 2); + MailListContainer.Visibility = Visibility.Collapsed; + RenderingGrid.Visibility = Visibility.Visible; + } + else + { + MailListColumn.Width = new GridLength(1, GridUnitType.Star); + RendererColumn.Width = new GridLength(0); + + Grid.SetColumnSpan(MailListContainer, 2); + MailListContainer.Visibility = Visibility.Visible; + RenderingGrid.Visibility = Visibility.Collapsed; + } + } + else + { + MailListColumn.Width = new GridLength(StatePersistanceService.MailListPaneLength); + RendererColumn.Width = new GridLength(1, GridUnitType.Star); + + Grid.SetColumn(MailListContainer, 0); + Grid.SetColumn(RenderingGrid, 1); + Grid.SetColumnSpan(MailListContainer, 1); + Grid.SetColumnSpan(RenderingGrid, 1); + + MailListContainer.Visibility = Visibility.Visible; + RenderingGrid.Visibility = Visibility.Visible; + } + } + + private void PropertySizer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) + { + StatePersistanceService.MailListPaneLength = ViewModel.MailListLength; + } } } diff --git a/Wino.Mail/Wino.Mail.csproj b/Wino.Mail/Wino.Mail.csproj index 43c2a54b..47ff411a 100644 --- a/Wino.Mail/Wino.Mail.csproj +++ b/Wino.Mail/Wino.Mail.csproj @@ -246,6 +246,7 @@ + AccountEditDialog.xaml From f57c27e75597cba0de0942e262f06a31f735a735 Mon Sep 17 00:00:00 2001 From: Aleh Khantsevich Date: Mon, 19 Aug 2024 17:15:59 +0200 Subject: [PATCH 2/6] Fix multiple items selected --- Wino.Mail/Views/MailListPage.xaml.cs | 34 +++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Wino.Mail/Views/MailListPage.xaml.cs b/Wino.Mail/Views/MailListPage.xaml.cs index b54b924f..b368ce7a 100644 --- a/Wino.Mail/Views/MailListPage.xaml.cs +++ b/Wino.Mail/Views/MailListPage.xaml.cs @@ -40,11 +40,9 @@ public sealed partial class MailListPage : MailListPageAbstract, IRecipient, IRecipient { - private const string NarrowVisualStateKey = "NarrowState"; - private const string AdaptivenessStatesKey = "AdaptiveStates"; private const int RENDERING_COLUMN_MIN_WIDTH = 300; - private IStatePersistanceService StatePersistanceService { get; } = App.Current.Services.GetService(); + private IStatePersistanceService StatePersistenceService { get; } = App.Current.Services.GetService(); private IPreferencesService PreferencesService { get; } = App.Current.Services.GetService(); private IKeyPressService KeyPressService { get; } = App.Current.Services.GetService(); @@ -259,7 +257,7 @@ void IRecipient.Receive(ActiveMailItemChangedEvent m } } - UpdateAdaptiveness1(); + UpdateAdaptiveness(); } private bool IsRenderingPageActive() => RenderingFrame.Content is MailRenderingPage; @@ -309,7 +307,7 @@ private WebView2 GetComposerPageWebView() public void Receive(ActiveMailFolderChangedEvent message) { - UpdateAdaptiveness1(); + UpdateAdaptiveness(); } public async void Receive(SelectMailItemContainerEvent message) @@ -363,7 +361,7 @@ await ViewModel.ExecuteUIThread(async () => public void Receive(ShellStateUpdated message) { - UpdateAdaptiveness1(); + UpdateAdaptiveness(); } private void SearchBoxFocused(object sender, RoutedEventArgs e) @@ -488,18 +486,23 @@ private void Page_SizeChanged(object sender, SizeChangedEventArgs e) { ViewModel.MaxMailListLength = e.NewSize.Width - RENDERING_COLUMN_MIN_WIDTH; - StatePersistanceService.IsReaderNarrowed = e.NewSize.Width < StatePersistanceService.MailListPaneLength + RENDERING_COLUMN_MIN_WIDTH; + StatePersistenceService.IsReaderNarrowed = e.NewSize.Width < StatePersistenceService.MailListPaneLength + RENDERING_COLUMN_MIN_WIDTH; - UpdateAdaptiveness1(); + UpdateAdaptiveness(); } - private void UpdateAdaptiveness1() + private void PropertySizer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) + { + StatePersistenceService.MailListPaneLength = ViewModel.MailListLength; + } + + private void UpdateAdaptiveness() { bool shouldDisplayNoMessagePanel, shouldDisplayMailingList, shouldDisplayRenderingFrame; // This is the smallest state UI can get. // Either mailing list or rendering grid is visible. - if (StatePersistanceService.IsReaderNarrowed) + if (StatePersistenceService.IsReaderNarrowed) { // Start visibility checks by no message panel. @@ -520,9 +523,9 @@ private void UpdateAdaptiveness1() RenderingFrame.Visibility = shouldDisplayRenderingFrame ? Visibility.Visible : Visibility.Collapsed; NoMailSelectedPanel.Visibility = shouldDisplayNoMessagePanel ? Visibility.Visible : Visibility.Collapsed; - if (StatePersistanceService.IsReaderNarrowed == true) + if (StatePersistenceService.IsReaderNarrowed == true) { - if (ViewModel.HasSelectedItems) + if (ViewModel.HasSingleItemSelection) { MailListColumn.Width = new GridLength(0); RendererColumn.Width = new GridLength(1, GridUnitType.Star); @@ -544,7 +547,7 @@ private void UpdateAdaptiveness1() } else { - MailListColumn.Width = new GridLength(StatePersistanceService.MailListPaneLength); + MailListColumn.Width = new GridLength(StatePersistenceService.MailListPaneLength); RendererColumn.Width = new GridLength(1, GridUnitType.Star); Grid.SetColumn(MailListContainer, 0); @@ -556,10 +559,5 @@ private void UpdateAdaptiveness1() RenderingGrid.Visibility = Visibility.Visible; } } - - private void PropertySizer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) - { - StatePersistanceService.MailListPaneLength = ViewModel.MailListLength; - } } } From 68536d6c34c19dbc59dfe438fc5e1e7952f24dd2 Mon Sep 17 00:00:00 2001 From: Aleh Khantsevich Date: Mon, 19 Aug 2024 18:49:35 +0200 Subject: [PATCH 3/6] Fix padding in narrow state --- Wino.Mail.ViewModels/MailListPageViewModel.cs | 12 +++++++----- Wino.Mail/Views/MailListPage.xaml.cs | 14 ++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Wino.Mail.ViewModels/MailListPageViewModel.cs b/Wino.Mail.ViewModels/MailListPageViewModel.cs index 3a1900d5..8b50f100 100644 --- a/Wino.Mail.ViewModels/MailListPageViewModel.cs +++ b/Wino.Mail.ViewModels/MailListPageViewModel.cs @@ -121,7 +121,7 @@ public partial class MailListPageViewModel : BaseViewModel, private string barMessage; [ObservableProperty] - private double mailListLength = 300; + private double mailListLength = 420; [ObservableProperty] private double maxMailListLength = 1200; @@ -147,7 +147,7 @@ public partial class MailListPageViewModel : BaseViewModel, public MailListPageViewModel(IDialogService dialogService, IWinoNavigationService navigationService, IMailService mailService, - IStatePersistanceService statePersistanceService, + IStatePersistanceService statePersistenceService, IFolderService folderService, IThreadingStrategyProvider threadingStrategyProvider, IContextMenuItemService contextMenuItemService, @@ -158,7 +158,7 @@ public MailListPageViewModel(IDialogService dialogService, { PreferencesService = preferencesService; _winoServerConnectionManager = winoServerConnectionManager; - StatePersistanceService = statePersistanceService; + StatePersistanceService = statePersistenceService; NavigationService = navigationService; _mailService = mailService; @@ -171,6 +171,8 @@ public MailListPageViewModel(IDialogService dialogService, SelectedFilterOption = FilterOptions[0]; SelectedSortingOption = SortingOptions[0]; + mailListLength = statePersistenceService.MailListPaneLength; + selectionChangedObservable = Observable.FromEventPattern(SelectedItems, nameof(SelectedItems.CollectionChanged)); selectionChangedObservable .Throttle(TimeSpan.FromMilliseconds(100)) @@ -263,7 +265,7 @@ private async void ActiveMailItemChanged(MailItemViewModel selectedMailItemViewM { if (_activeMailItem == selectedMailItemViewModel) return; - // Don't update active mail item if Ctrl key is pressed or multi selection is ennabled. + // Don't update active mail item if Ctrl key is pressed or multi selection is enabled. // User is probably trying to select multiple items. // This is not the same behavior in Windows Mail, // but it's a trash behavior. @@ -272,7 +274,7 @@ private async void ActiveMailItemChanged(MailItemViewModel selectedMailItemViewM bool isMultiSelecting = isCtrlKeyPressed || IsMultiSelectionModeEnabled; - if (isMultiSelecting ? StatePersistanceService.IsReaderNarrowed : false) + if (isMultiSelecting && StatePersistanceService.IsReaderNarrowed) { // Don't change the active mail item if the reader is narrowed, but just update the shell. Messenger.Send(new ShellStateUpdated()); diff --git a/Wino.Mail/Views/MailListPage.xaml.cs b/Wino.Mail/Views/MailListPage.xaml.cs index b368ce7a..bfa79235 100644 --- a/Wino.Mail/Views/MailListPage.xaml.cs +++ b/Wino.Mail/Views/MailListPage.xaml.cs @@ -40,10 +40,9 @@ public sealed partial class MailListPage : MailListPageAbstract, IRecipient, IRecipient { - private const int RENDERING_COLUMN_MIN_WIDTH = 300; + private const double RENDERING_COLUMN_MIN_WIDTH = 300; private IStatePersistanceService StatePersistenceService { get; } = App.Current.Services.GetService(); - private IPreferencesService PreferencesService { get; } = App.Current.Services.GetService(); private IKeyPressService KeyPressService { get; } = App.Current.Services.GetService(); public MailListPage() @@ -89,7 +88,7 @@ private void UpdateSelectAllButtonStatus() SelectAllCheckbox.Unchecked += SelectAllCheckboxUnchecked; } - private void SelectionModeToggleChecked(object sender, Windows.UI.Xaml.RoutedEventArgs e) + private void SelectionModeToggleChecked(object sender, RoutedEventArgs e) { ChangeSelectionMode(ListViewSelectionMode.Multiple); } @@ -131,17 +130,17 @@ private void ChangeSelectionMode(ListViewSelectionMode mode) } } - private void SelectionModeToggleUnchecked(object sender, Windows.UI.Xaml.RoutedEventArgs e) + private void SelectionModeToggleUnchecked(object sender, RoutedEventArgs e) { ChangeSelectionMode(ListViewSelectionMode.Extended); } - private void SelectAllCheckboxChecked(object sender, Windows.UI.Xaml.RoutedEventArgs e) + private void SelectAllCheckboxChecked(object sender, RoutedEventArgs e) { MailListView.SelectAllWino(); } - private void SelectAllCheckboxUnchecked(object sender, Windows.UI.Xaml.RoutedEventArgs e) + private void SelectAllCheckboxUnchecked(object sender, RoutedEventArgs e) { MailListView.ClearSelections(); } @@ -541,6 +540,7 @@ private void UpdateAdaptiveness() RendererColumn.Width = new GridLength(0); Grid.SetColumnSpan(MailListContainer, 2); + MailListContainer.Margin = new Thickness(7,0,7,0); MailListContainer.Visibility = Visibility.Visible; RenderingGrid.Visibility = Visibility.Collapsed; } @@ -550,6 +550,8 @@ private void UpdateAdaptiveness() MailListColumn.Width = new GridLength(StatePersistenceService.MailListPaneLength); RendererColumn.Width = new GridLength(1, GridUnitType.Star); + MailListContainer.Margin = new Thickness(0, 0, 0, 0); + Grid.SetColumn(MailListContainer, 0); Grid.SetColumn(RenderingGrid, 1); Grid.SetColumnSpan(MailListContainer, 1); From d8705de26ffabe9362db21b6ef96a3380c8ffab8 Mon Sep 17 00:00:00 2001 From: Aleh Khantsevich Date: Mon, 19 Aug 2024 20:41:55 +0200 Subject: [PATCH 4/6] Replaced setting with reset button --- .../MailListPaneLengthPreferences.cs | 4 -- .../Translations/en_US/resources.json | 6 +- Wino.Core.Domain/Translator.Designer.cs | 20 ++++-- Wino.Mail.ViewModels/MailListPageViewModel.cs | 6 +- .../PersonalizationPageViewModel.cs | 37 ++++------- .../Views/Settings/PersonalizationPage.xaml | 64 +++++++++---------- 6 files changed, 67 insertions(+), 70 deletions(-) delete mode 100644 Wino.Core.Domain/Models/Personalization/MailListPaneLengthPreferences.cs diff --git a/Wino.Core.Domain/Models/Personalization/MailListPaneLengthPreferences.cs b/Wino.Core.Domain/Models/Personalization/MailListPaneLengthPreferences.cs deleted file mode 100644 index 23841893..00000000 --- a/Wino.Core.Domain/Models/Personalization/MailListPaneLengthPreferences.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace Wino.Core.Domain.Models.Personalization -{ - public record MailListPaneLengthPreferences(string Title, double Length); -} diff --git a/Wino.Core.Domain/Translations/en_US/resources.json b/Wino.Core.Domain/Translations/en_US/resources.json index 2f6699c7..bdb0e16f 100644 --- a/Wino.Core.Domain/Translations/en_US/resources.json +++ b/Wino.Core.Domain/Translations/en_US/resources.json @@ -42,6 +42,7 @@ "Buttons_SignIn": "Sign In", "Buttons_TryAgain": "Try Again", "Buttons_Yes": "Yes", + "Buttons_Reset": "Reset", "Center": "Center", "ComingSoon": "Coming soon...", "ComposerFrom": "From: ", @@ -253,6 +254,7 @@ "Info_UnsubscribeLinkInvalidMessage": "This unsubscribe link is invalid. Failed to unsubscribe from the list.", "Info_UnsubscribeSuccessMessage": "Successfully unsubscribed from {0}.", "Info_UnsubscribeErrorMessage": "Failed to unsubscribe", + "Info_MailListSizeResetSuccessMessage": "The Mail List size has been reset.", "ImapAdvancedSetupDialog_AuthenticationMethod": "Authentication method", "ImapAdvancedSetupDialog_ConnectionSecurity": "Connection security", "ImapAuthenticationMethod_Auto": "Auto", @@ -448,8 +450,8 @@ "SettingsNoAccountSetupMessage": "You didn't setup any accounts yet.", "SettingsNotifications_Description": "Turn on or off notifications for this account.", "SettingsNotifications_Title": "Notifications", - "SettingsPaneLength_Description": "Change the width of the mail list.", - "SettingsPaneLength_Title": "Mail List Pane Length", + "SettingsPaneLengthReset_Description": "Reset the size of the mail list to original if you have issues with it.", + "SettingsPaneLengthReset_Title": "Reset Mail List Size", "SettingsPaypal_Description": "Show much more love ❤️ All donations are appreciated.", "SettingsPaypal_Title": "Donate via PayPal", "SettingsPersonalizationMailDisplayCompactMode": "Compact Mode", diff --git a/Wino.Core.Domain/Translator.Designer.cs b/Wino.Core.Domain/Translator.Designer.cs index 6fc65a03..09ea5907 100644 --- a/Wino.Core.Domain/Translator.Designer.cs +++ b/Wino.Core.Domain/Translator.Designer.cs @@ -233,6 +233,11 @@ public class Translator /// public static string Buttons_Yes => Resources.GetTranslatedString(@"Buttons_Yes"); + /// + /// Reset + /// + public static string Buttons_Reset => Resources.GetTranslatedString(@"Buttons_Reset"); + /// /// Center /// @@ -434,7 +439,7 @@ public class Translator public static string DialogMessage_UnlinkAccountsConfirmationTitle => Resources.GetTranslatedString(@"DialogMessage_UnlinkAccountsConfirmationTitle"); /// - /// Missin Subject + /// Missing Subject /// public static string DialogMessage_EmptySubjectConfirmation => Resources.GetTranslatedString(@"DialogMessage_EmptySubjectConfirmation"); @@ -1288,6 +1293,11 @@ public class Translator /// public static string Info_UnsubscribeErrorMessage => Resources.GetTranslatedString(@"Info_UnsubscribeErrorMessage"); + /// + /// The Mail List size has been reset. + /// + public static string Info_MailListSizeResetSuccessMessage => Resources.GetTranslatedString(@"Info_MailListSizeResetSuccessMessage"); + /// /// Authentication method /// @@ -2264,14 +2274,14 @@ public class Translator public static string SettingsNotifications_Title => Resources.GetTranslatedString(@"SettingsNotifications_Title"); /// - /// Change the width of the mail list. + /// Reset the size of the mail list to original if you have issues with it. /// - public static string SettingsPaneLength_Description => Resources.GetTranslatedString(@"SettingsPaneLength_Description"); + public static string SettingsPaneLengthReset_Description => Resources.GetTranslatedString(@"SettingsPaneLengthReset_Description"); /// - /// Mail List Pane Length + /// Reset Mail List Size /// - public static string SettingsPaneLength_Title => Resources.GetTranslatedString(@"SettingsPaneLength_Title"); + public static string SettingsPaneLengthReset_Title => Resources.GetTranslatedString(@"SettingsPaneLengthReset_Title"); /// /// Show much more love ❤️ All donations are appreciated. diff --git a/Wino.Mail.ViewModels/MailListPageViewModel.cs b/Wino.Mail.ViewModels/MailListPageViewModel.cs index 8b50f100..17d2e754 100644 --- a/Wino.Mail.ViewModels/MailListPageViewModel.cs +++ b/Wino.Mail.ViewModels/MailListPageViewModel.cs @@ -68,7 +68,7 @@ public partial class MailListPageViewModel : BaseViewModel, private CancellationTokenSource listManipulationCancellationTokenSource = new CancellationTokenSource(); public IWinoNavigationService NavigationService { get; } - public IStatePersistanceService StatePersistanceService { get; } + public IStatePersistanceService StatePersistenceService { get; } public IPreferencesService PreferencesService { get; } private readonly IMailService _mailService; @@ -158,7 +158,7 @@ public MailListPageViewModel(IDialogService dialogService, { PreferencesService = preferencesService; _winoServerConnectionManager = winoServerConnectionManager; - StatePersistanceService = statePersistenceService; + StatePersistenceService = statePersistenceService; NavigationService = navigationService; _mailService = mailService; @@ -274,7 +274,7 @@ private async void ActiveMailItemChanged(MailItemViewModel selectedMailItemViewM bool isMultiSelecting = isCtrlKeyPressed || IsMultiSelectionModeEnabled; - if (isMultiSelecting && StatePersistanceService.IsReaderNarrowed) + if (isMultiSelecting && StatePersistenceService.IsReaderNarrowed) { // Don't change the active mail item if the reader is narrowed, but just update the shell. Messenger.Send(new ShellStateUpdated()); diff --git a/Wino.Mail.ViewModels/PersonalizationPageViewModel.cs b/Wino.Mail.ViewModels/PersonalizationPageViewModel.cs index 1e302f88..718cff85 100644 --- a/Wino.Mail.ViewModels/PersonalizationPageViewModel.cs +++ b/Wino.Mail.ViewModels/PersonalizationPageViewModel.cs @@ -25,37 +25,24 @@ public partial class PersonalizationPageViewModel : BaseViewModel public bool IsSelectedWindowsAccentColor => SelectedAppColor == Colors.LastOrDefault(); - public ObservableCollection Colors { get; set; } = new ObservableCollection(); + public ObservableCollection Colors { get; set; } = []; - public List ElementThemes { get; set; } = new List() - { + public List ElementThemes { get; set; } = + [ new ElementThemeContainer(ApplicationElementTheme.Light, Translator.ElementTheme_Light), new ElementThemeContainer(ApplicationElementTheme.Dark, Translator.ElementTheme_Dark), new ElementThemeContainer(ApplicationElementTheme.Default, Translator.ElementTheme_Default), - }; + ]; - public List PaneLengths { get; set; } = new List() - { - new MailListPaneLengthPreferences(Translator.PaneLengthOption_Micro, 300), - new MailListPaneLengthPreferences(Translator.PaneLengthOption_Small, 350), - new MailListPaneLengthPreferences(Translator.PaneLengthOption_Default, 420), - new MailListPaneLengthPreferences(Translator.PaneLengthOption_Medium, 700), - new MailListPaneLengthPreferences(Translator.PaneLengthOption_Large, 900), - new MailListPaneLengthPreferences(Translator.PaneLengthOption_ExtraLarge, 1200), - }; - - public List InformationDisplayModes { get; set; } = new List() - { + public List InformationDisplayModes { get; set; } = + [ MailListDisplayMode.Compact, MailListDisplayMode.Medium, MailListDisplayMode.Spacious - }; + ]; public List AppThemes { get; set; } - [ObservableProperty] - private MailListPaneLengthPreferences selectedMailListPaneLength; - [ObservableProperty] private ElementThemeContainer selectedElementTheme; @@ -123,6 +110,13 @@ public AppThemeBase SelectedAppTheme #endregion + [RelayCommand] + private void ResetMailListPaneLength() + { + StatePersistanceService.MailListPaneLength = 420; + DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.Info_MailListSizeResetSuccessMessage, InfoBarMessageType.Success); + } + public AsyncRelayCommand CreateCustomThemeCommand { get; set; } public PersonalizationPageViewModel(IDialogService dialogService, IStatePersistanceService statePersistanceService, @@ -179,7 +173,6 @@ private void SetInitialValues() { SelectedElementTheme = ElementThemes.Find(a => a.NativeTheme == _themeService.RootTheme); SelectedInfoDisplayMode = PreferencesService.MailItemDisplayMode; - SelectedMailListPaneLength = PaneLengths.Find(a => a.Length == StatePersistanceService.MailListPaneLength); var currentAccentColor = _themeService.AccentColor; @@ -289,8 +282,6 @@ private void PersonalizationSettingsUpdated(object sender, System.ComponentModel { _themeService.CurrentApplicationThemeId = SelectedAppTheme.Id; } - else if (e.PropertyName == nameof(SelectedMailListPaneLength) && SelectedMailListPaneLength != null) - StatePersistanceService.MailListPaneLength = SelectedMailListPaneLength.Length; else { if (e.PropertyName == nameof(SelectedInfoDisplayMode)) diff --git a/Wino.Mail/Views/Settings/PersonalizationPage.xaml b/Wino.Mail/Views/Settings/PersonalizationPage.xaml index 4beab950..762e8975 100644 --- a/Wino.Mail/Views/Settings/PersonalizationPage.xaml +++ b/Wino.Mail/Views/Settings/PersonalizationPage.xaml @@ -3,17 +3,17 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:abstract="using:Wino.Views.Abstract" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:ui="using:Microsoft.Toolkit.Uwp.UI" - xmlns:helpers="using:Wino.Helpers" xmlns:controls="using:CommunityToolkit.WinUI.Controls" - xmlns:selectors="using:Wino.Selectors" xmlns:controls1="using:Wino.Controls" - xmlns:viewModelData="using:Wino.Mail.ViewModels.Data" - xmlns:personalization="using:Wino.Core.UWP.Models.Personalization" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:domain="using:Wino.Core.Domain" xmlns:enums="using:Wino.Core.Domain.Enums" + xmlns:helpers="using:Wino.Helpers" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:personalization="using:Wino.Core.UWP.Models.Personalization" + xmlns:selectors="using:Wino.Selectors" + xmlns:ui="using:Microsoft.Toolkit.Uwp.UI" + xmlns:viewModelData="using:Wino.Mail.ViewModels.Data" Title="Personalization" mc:Ignorable="d"> @@ -134,35 +134,35 @@ + SystemThemeTemplate="{StaticResource SystemAppThemeTemplate}" /> + Subject="Welcome to Wino Mail" /> + Subject="Welcome to Wino Mail" /> + Subject="Welcome to Wino Mail" /> @@ -213,15 +213,15 @@ - + @@ -229,31 +229,31 @@ + Foreground="{ThemeResource InfoBarWarningSeverityIconBackground}" + Text="{x:Bind domain:Translator.SettingsElementThemeSelectionDisabled}" /> - + - + -