Implemented a new dialog for account re-ordering and required apis.

This commit is contained in:
Burak Kaan Köse
2024-06-09 02:37:30 +02:00
parent f4e81aca9d
commit c7781d2e75
14 changed files with 241 additions and 8 deletions

View File

@@ -13,5 +13,21 @@ namespace Wino.Core.Domain.Interfaces
/// Name representation of the view model that will be used to identify the startup entity on launch.
/// </summary>
string StartupEntityTitle { get; }
/// <summary>
/// E-mail addresses that this account holds.
/// </summary>
string StartupEntityAddresses { get; }
/// <summary>
/// Represents the account order in the accounts list.
/// </summary>
int Order { get; }
/// <summary>
/// Provider details of the account.
/// </summary>
IProviderDetail ProviderDetail { get; set; }
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Enums;
@@ -32,6 +33,13 @@ namespace Wino.Core.Domain.Interfaces
Task<MailAccount> ShowEditAccountDialogAsync(MailAccount account);
Task<MailAccount> ShowAccountPickerDialogAsync(List<MailAccount> availableAccounts);
/// <summary>
/// Displays a dialog to the user for reordering accounts.
/// </summary>
/// <param name="availableAccounts">Available accounts in order.</param>
/// <returns>Result model that has dict of AccountId-AccountOrder.</returns>
Task ShowAccountReorderDialogAsync(ObservableCollection<IAccountProviderDetailViewModel> availableAccounts);
/// <summary>
/// Presents a dialog to the user for selecting folder.
/// </summary>

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
namespace Wino.Core.Messages.Accounts
{
/// <summary>
/// Emitted when account menu items are reordered.
/// </summary>
/// <param name="newOrderDictionary">New order info.</param>
public record AccountMenuItemsReordered(Dictionary<Guid, int> newOrderDictionary);
}

View File

@@ -423,7 +423,7 @@ namespace Wino.Core.Services
if (account == null)
{
_logger.Error("Could not find account with id {AccountId}", pair.Key);
_logger.Information("Could not find account with id {Key} for reordering. It may be a linked account.", pair.Key);
continue;
}
@@ -431,6 +431,8 @@ namespace Wino.Core.Services
await Connection.UpdateAsync(account);
}
Messenger.Send(new AccountMenuItemsReordered(accountIdOrderPair));
}
}
}

View File

@@ -264,11 +264,8 @@ namespace Wino.Mail.ViewModels
mergedAccountProviderDetailViewModel));
}
[RelayCommand]
private async Task ReorderAccountsAsync()
{
}
[RelayCommand(CanExecute = nameof(CanReorderAccounts))]
private Task ReorderAccountsAsync() => DialogService.ShowAccountReorderDialogAsync(availableAccounts: Accounts);
public override void OnNavigatedFrom(NavigationMode mode, object parameters)
{

View File

@@ -39,7 +39,8 @@ namespace Wino.Mail.ViewModels
IRecipient<RefreshUnreadCountsMessage>,
IRecipient<AccountsMenuRefreshRequested>,
IRecipient<MergedInboxRenamed>,
IRecipient<LanguageChanged>
IRecipient<LanguageChanged>,
IRecipient<AccountMenuItemsReordered>
{
#region Menu Items
@@ -1059,5 +1060,19 @@ namespace Wino.Mail.ViewModels
ChangeLoadedAccount(latestSelectedAccountMenuItem, navigateInbox: false);
}
private void ReorderAccountMenuItems(Dictionary<Guid, int> newAccountOrder)
{
foreach (var item in newAccountOrder)
{
var menuItem = MenuItems.GetAccountMenuItem(item.Key);
if (menuItem == null) continue;
MenuItems.Move(MenuItems.IndexOf(menuItem), item.Value);
}
}
public void Receive(AccountMenuItemsReordered message) => ReorderAccountMenuItems(message.newOrderDictionary);
}
}

View File

@@ -17,6 +17,10 @@ namespace Wino.Mail.ViewModels.Data
public string StartupEntityTitle => Account.Name;
public int Order => Account.Order;
public string StartupEntityAddresses => Account.Address;
public AccountProviderDetailViewModel(IProviderDetail providerDetail, MailAccount account)
{
ProviderDetail = providerDetail;

View File

@@ -18,6 +18,12 @@ namespace Wino.Mail.ViewModels.Data
public string StartupEntityTitle => MergedInbox.Name;
public int Order => 0;
public IProviderDetail ProviderDetail { get; set; }
public string StartupEntityAddresses => AccountAddresses;
public MergedAccountProviderDetailViewModel(MergedInbox mergedInbox, List<AccountProviderDetailViewModel> holdingAccounts)
{
MergedInbox = mergedInbox;

View File

@@ -0,0 +1,84 @@
<ContentDialog
x:Class="Wino.Dialogs.AccountReorderDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Wino.Dialogs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interfaces="using:Wino.Core.Domain.Interfaces"
xmlns:controls="using:Wino.Controls"
xmlns:helpers="using:Wino.Helpers"
xmlns:domain="using:Wino.Core.Domain"
xmlns:selectors="using:Wino.Selectors"
mc:Ignorable="d"
Title="Reorder Accounnts"
Closed="DialogClosed"
Opened="DialogOpened"
DefaultButton="Secondary"
Style="{StaticResource WinoDialogStyle}"
SecondaryButtonText="{x:Bind domain:Translator.Buttons_Cancel}">
<ContentDialog.Resources>
<DataTemplate x:Key="RootAccountReorderTemplate" x:DataType="interfaces:IAccountProviderDetailViewModel">
<Grid Padding="12" ColumnSpacing="24">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:WinoFontIcon
Icon="{x:Bind helpers:XamlHelpers.GetProviderIcon(ProviderDetail.Type)}"
FontSize="24"
Grid.RowSpan="2"
VerticalAlignment="Center" />
<TextBlock
Text="{x:Bind StartupEntityTitle}"
Grid.Column="1"
FontWeight="SemiBold" />
<TextBlock
Text="{x:Bind StartupEntityAddresses}"
Grid.Column="1"
Grid.Row="1" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="MergedAccountReorderTemplate" x:DataType="interfaces:IAccountProviderDetailViewModel">
<Grid Padding="12" ColumnSpacing="24">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<PathIcon
Grid.RowSpan="2"
VerticalAlignment="Center"
Data="F1 M 8.613281 17.5 C 8.75 17.942709 8.945312 18.359375 9.199219 18.75 L 4.921875 18.75 C 4.433594 18.75 3.966471 18.650717 3.520508 18.452148 C 3.074544 18.25358 2.683919 17.986654 2.348633 17.651367 C 2.013346 17.31608 1.746419 16.925455 1.547852 16.479492 C 1.349284 16.033529 1.25 15.566406 1.25 15.078125 L 1.25 4.921875 C 1.25 4.433594 1.349284 3.966473 1.547852 3.520508 C 1.746419 3.074545 2.013346 2.68392 2.348633 2.348633 C 2.683919 2.013348 3.074544 1.74642 3.520508 1.547852 C 3.966471 1.349285 4.433594 1.25 4.921875 1.25 L 15.078125 1.25 C 15.566406 1.25 16.033527 1.349285 16.479492 1.547852 C 16.925455 1.74642 17.31608 2.013348 17.651367 2.348633 C 17.986652 2.68392 18.25358 3.074545 18.452148 3.520508 C 18.650715 3.966473 18.75 4.433594 18.75 4.921875 L 18.75 6.572266 C 18.580729 6.344402 18.390299 6.132813 18.178711 5.9375 C 17.967121 5.742188 17.740885 5.566407 17.5 5.410156 L 17.5 4.951172 C 17.5 4.625651 17.433268 4.314779 17.299805 4.018555 C 17.16634 3.722332 16.987305 3.461914 16.762695 3.237305 C 16.538086 3.012695 16.277668 2.83366 15.981445 2.700195 C 15.685221 2.566732 15.374349 2.5 15.048828 2.5 L 4.951172 2.5 C 4.619141 2.5 4.303385 2.568359 4.003906 2.705078 C 3.704427 2.841797 3.44401 3.02409 3.222656 3.251953 C 3.001302 3.479818 2.825521 3.745117 2.695312 4.047852 C 2.565104 4.350587 2.5 4.66797 2.5 5 L 13.310547 5 C 12.60091 5.266928 11.998697 5.683594 11.503906 6.25 L 2.5 6.25 L 2.5 15.048828 C 2.5 15.38737 2.568359 15.704753 2.705078 16.000977 C 2.841797 16.297201 3.024088 16.55599 3.251953 16.777344 C 3.479818 16.998697 3.745117 17.174479 4.047852 17.304688 C 4.350586 17.434896 4.667969 17.5 5 17.5 Z M 18.125 9.443359 C 18.125 9.866537 18.040363 10.263672 17.871094 10.634766 C 17.701822 11.005859 17.473957 11.329753 17.1875 11.606445 C 16.901041 11.883139 16.56901 12.101237 16.191406 12.260742 C 15.813802 12.420248 15.416666 12.5 15 12.5 C 14.563802 12.5 14.1569 12.41862 13.779297 12.255859 C 13.401691 12.0931 13.071288 11.870117 12.788086 11.586914 C 12.504882 11.303711 12.2819 10.973308 12.119141 10.595703 C 11.95638 10.2181 11.875 9.811198 11.875 9.375 C 11.875 8.938803 11.95638 8.531901 12.119141 8.154297 C 12.2819 7.776693 12.504882 7.446289 12.788086 7.163086 C 13.071288 6.879883 13.401691 6.656901 13.779297 6.494141 C 14.1569 6.331381 14.563802 6.25 15 6.25 C 15.449218 6.25 15.864257 6.333008 16.245117 6.499023 C 16.625977 6.665039 16.956379 6.892904 17.236328 7.182617 C 17.516275 7.472331 17.734375 7.810873 17.890625 8.198242 C 18.046875 8.585612 18.125 9.000651 18.125 9.443359 Z M 20 16.25 C 20 16.666666 19.926758 17.049154 19.780273 17.397461 C 19.633789 17.745768 19.435221 18.058268 19.18457 18.334961 C 18.933918 18.611654 18.642578 18.854166 18.310547 19.0625 C 17.978516 19.270834 17.626953 19.444986 17.255859 19.584961 C 16.884766 19.724936 16.505533 19.829102 16.118164 19.897461 C 15.730794 19.96582 15.358072 20 15 20 C 14.654947 20 14.291992 19.96582 13.911133 19.897461 C 13.530273 19.829102 13.154297 19.726562 12.783203 19.589844 C 12.412109 19.453125 12.058919 19.282227 11.723633 19.077148 C 11.388346 18.87207 11.092122 18.632812 10.834961 18.359375 C 10.577799 18.085938 10.374349 17.779947 10.224609 17.441406 C 10.074869 17.102865 10 16.731771 10 16.328125 L 10 15.78125 C 10 15.501303 10.052083 15.237631 10.15625 14.990234 C 10.260416 14.742839 10.405273 14.526367 10.59082 14.34082 C 10.776367 14.155273 10.991211 14.010417 11.235352 13.90625 C 11.479492 13.802084 11.744791 13.75 12.03125 13.75 L 17.96875 13.75 C 18.248697 13.75 18.512369 13.803711 18.759766 13.911133 C 19.00716 14.018555 19.222004 14.163412 19.404297 14.345703 C 19.586588 14.527995 19.731445 14.742839 19.838867 14.990234 C 19.946289 15.237631 20 15.501303 20 15.78125 Z " />
<TextBlock
Text="{x:Bind StartupEntityTitle}"
Grid.Column="1"
FontWeight="SemiBold" />
<TextBlock
Text="{x:Bind StartupEntityAddresses}"
Grid.Column="1"
Grid.Row="1" />
</Grid>
</DataTemplate>
<selectors:AccountReorderTemplateSelector
x:Key="AccountReorderTemplateSelector"
MergedAccountReorderTemplate="{StaticResource MergedAccountReorderTemplate}"
RootAccountReorderTemplate="{StaticResource RootAccountReorderTemplate}" />
</ContentDialog.Resources>
<ListView
CanReorderItems="True"
SelectionMode="None"
AllowDrop="True"
ItemsSource="{x:Bind Accounts}"
ItemTemplateSelector="{StaticResource AccountReorderTemplateSelector}" />
</ContentDialog>

View File

@@ -0,0 +1,52 @@
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Interfaces;
namespace Wino.Dialogs
{
public sealed partial class AccountReorderDialog : ContentDialog
{
public ObservableCollection<IAccountProviderDetailViewModel> Accounts { get; }
private int count;
private bool isOrdering = false;
private readonly IAccountService _accountService = App.Current.Services.GetService<IAccountService>();
public AccountReorderDialog(ObservableCollection<IAccountProviderDetailViewModel> accounts)
{
Accounts = accounts;
count = accounts.Count;
InitializeComponent();
}
private void DialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
{
Accounts.CollectionChanged -= AccountsChanged;
Accounts.CollectionChanged += AccountsChanged;
}
private void DialogClosed(ContentDialog sender, ContentDialogClosedEventArgs args) => Accounts.CollectionChanged -= AccountsChanged;
private async void AccountsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (count - 1 == Accounts.Count)
isOrdering = true;
if (count == Accounts.Count && isOrdering)
{
// Order is completed. Apply changes.
var dict = Accounts.ToDictionary(a => a.StartupEntityId, a => Accounts.IndexOf(a));
await _accountService.UpdateAccountOrdersAsync(dict);
isOrdering = false;
}
}
}
}

View File

@@ -0,0 +1,22 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Mail.ViewModels.Data;
namespace Wino.Selectors
{
public class AccountReorderTemplateSelector : DataTemplateSelector
{
public DataTemplate MergedAccountReorderTemplate { get; set; }
public DataTemplate RootAccountReorderTemplate { get; set; }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item is MergedAccountProviderDetailViewModel)
{
return MergedAccountReorderTemplate;
}
return RootAccountReorderTemplate;
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
@@ -331,6 +332,14 @@ namespace Wino.Services
return accountPicker.PickedAccount;
}
public async Task ShowAccountReorderDialogAsync(ObservableCollection<IAccountProviderDetailViewModel> availableAccounts)
{
var accountReorderDialog = new AccountReorderDialog(availableAccounts)
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(accountReorderDialog);
}
}
}

View File

@@ -220,7 +220,6 @@
Description="{x:Bind domain:Translator.SettingsLinkAccounts_Description}">
<winuiControls:SettingsCard.HeaderIcon>
<PathIcon Data="F1 M 8.613281 17.5 C 8.75 17.942709 8.945312 18.359375 9.199219 18.75 L 4.921875 18.75 C 4.433594 18.75 3.966471 18.650717 3.520508 18.452148 C 3.074544 18.25358 2.683919 17.986654 2.348633 17.651367 C 2.013346 17.31608 1.746419 16.925455 1.547852 16.479492 C 1.349284 16.033529 1.25 15.566406 1.25 15.078125 L 1.25 4.921875 C 1.25 4.433594 1.349284 3.966473 1.547852 3.520508 C 1.746419 3.074545 2.013346 2.68392 2.348633 2.348633 C 2.683919 2.013348 3.074544 1.74642 3.520508 1.547852 C 3.966471 1.349285 4.433594 1.25 4.921875 1.25 L 15.078125 1.25 C 15.566406 1.25 16.033527 1.349285 16.479492 1.547852 C 16.925455 1.74642 17.31608 2.013348 17.651367 2.348633 C 17.986652 2.68392 18.25358 3.074545 18.452148 3.520508 C 18.650715 3.966473 18.75 4.433594 18.75 4.921875 L 18.75 6.572266 C 18.580729 6.344402 18.390299 6.132813 18.178711 5.9375 C 17.967121 5.742188 17.740885 5.566407 17.5 5.410156 L 17.5 4.951172 C 17.5 4.625651 17.433268 4.314779 17.299805 4.018555 C 17.16634 3.722332 16.987305 3.461914 16.762695 3.237305 C 16.538086 3.012695 16.277668 2.83366 15.981445 2.700195 C 15.685221 2.566732 15.374349 2.5 15.048828 2.5 L 4.951172 2.5 C 4.619141 2.5 4.303385 2.568359 4.003906 2.705078 C 3.704427 2.841797 3.44401 3.02409 3.222656 3.251953 C 3.001302 3.479818 2.825521 3.745117 2.695312 4.047852 C 2.565104 4.350587 2.5 4.66797 2.5 5 L 13.310547 5 C 12.60091 5.266928 11.998697 5.683594 11.503906 6.25 L 2.5 6.25 L 2.5 15.048828 C 2.5 15.38737 2.568359 15.704753 2.705078 16.000977 C 2.841797 16.297201 3.024088 16.55599 3.251953 16.777344 C 3.479818 16.998697 3.745117 17.174479 4.047852 17.304688 C 4.350586 17.434896 4.667969 17.5 5 17.5 Z M 18.125 9.443359 C 18.125 9.866537 18.040363 10.263672 17.871094 10.634766 C 17.701822 11.005859 17.473957 11.329753 17.1875 11.606445 C 16.901041 11.883139 16.56901 12.101237 16.191406 12.260742 C 15.813802 12.420248 15.416666 12.5 15 12.5 C 14.563802 12.5 14.1569 12.41862 13.779297 12.255859 C 13.401691 12.0931 13.071288 11.870117 12.788086 11.586914 C 12.504882 11.303711 12.2819 10.973308 12.119141 10.595703 C 11.95638 10.2181 11.875 9.811198 11.875 9.375 C 11.875 8.938803 11.95638 8.531901 12.119141 8.154297 C 12.2819 7.776693 12.504882 7.446289 12.788086 7.163086 C 13.071288 6.879883 13.401691 6.656901 13.779297 6.494141 C 14.1569 6.331381 14.563802 6.25 15 6.25 C 15.449218 6.25 15.864257 6.333008 16.245117 6.499023 C 16.625977 6.665039 16.956379 6.892904 17.236328 7.182617 C 17.516275 7.472331 17.734375 7.810873 17.890625 8.198242 C 18.046875 8.585612 18.125 9.000651 18.125 9.443359 Z M 20 16.25 C 20 16.666666 19.926758 17.049154 19.780273 17.397461 C 19.633789 17.745768 19.435221 18.058268 19.18457 18.334961 C 18.933918 18.611654 18.642578 18.854166 18.310547 19.0625 C 17.978516 19.270834 17.626953 19.444986 17.255859 19.584961 C 16.884766 19.724936 16.505533 19.829102 16.118164 19.897461 C 15.730794 19.96582 15.358072 20 15 20 C 14.654947 20 14.291992 19.96582 13.911133 19.897461 C 13.530273 19.829102 13.154297 19.726562 12.783203 19.589844 C 12.412109 19.453125 12.058919 19.282227 11.723633 19.077148 C 11.388346 18.87207 11.092122 18.632812 10.834961 18.359375 C 10.577799 18.085938 10.374349 17.779947 10.224609 17.441406 C 10.074869 17.102865 10 16.731771 10 16.328125 L 10 15.78125 C 10 15.501303 10.052083 15.237631 10.15625 14.990234 C 10.260416 14.742839 10.405273 14.526367 10.59082 14.34082 C 10.776367 14.155273 10.991211 14.010417 11.235352 13.90625 C 11.479492 13.802084 11.744791 13.75 12.03125 13.75 L 17.96875 13.75 C 18.248697 13.75 18.512369 13.803711 18.759766 13.911133 C 19.00716 14.018555 19.222004 14.163412 19.404297 14.345703 C 19.586588 14.527995 19.731445 14.742839 19.838867 14.990234 C 19.946289 15.237631 20 15.501303 20 15.78125 Z " />
</winuiControls:SettingsCard.HeaderIcon>
</winuiControls:SettingsCard>

View File

@@ -252,6 +252,9 @@
<Compile Include="Dialogs\AccountPickerDialog.xaml.cs">
<DependentUpon>AccountPickerDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\AccountReorderDialog.xaml.cs">
<DependentUpon>AccountReorderDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\BaseAccountCreationDialog.cs" />
<Compile Include="Dialogs\CustomThemeBuilderDialog.xaml.cs">
<DependentUpon>CustomThemeBuilderDialog.xaml</DependentUpon>
@@ -319,6 +322,7 @@
<Compile Include="Helpers\WinoVisualTreeHelper.cs" />
<Compile Include="Helpers\XamlHelpers.cs" />
<Compile Include="Selectors\AccountProviderViewModelTemplateSelector.cs" />
<Compile Include="Selectors\AccountReorderTemplateSelector.cs" />
<Compile Include="Selectors\AppThemePreviewTemplateSelector.cs" />
<Compile Include="Selectors\FileAttachmentTypeSelector.cs" />
<Compile Include="Selectors\MailItemContainerStyleSelector.cs" />
@@ -484,6 +488,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\AccountReorderDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\CustomThemeBuilderDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>