From 4ac80955541acc498e89a24bac605f963e3a70c6 Mon Sep 17 00:00:00 2001 From: Tiktack Date: Sat, 14 Sep 2024 18:41:33 +0200 Subject: [PATCH] Fixes Webview jumps when navigating emails and added Tooltips to the collapsed nav view. (#373) * Prepare To/Cc/Bcc info in advance to avoid layout shifts * Changed tooltips in nav view to apply to whole element instead of content * Revert comment --- .../MailRenderingPageViewModel.cs | 71 +++++++++++-------- Wino.Mail/AppShell.xaml | 12 ++-- Wino.Mail/Views/MailRenderingPage.xaml | 12 ++-- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/Wino.Mail.ViewModels/MailRenderingPageViewModel.cs b/Wino.Mail.ViewModels/MailRenderingPageViewModel.cs index adf10667..61c488d3 100644 --- a/Wino.Mail.ViewModels/MailRenderingPageViewModel.cs +++ b/Wino.Mail.ViewModels/MailRenderingPageViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; @@ -109,11 +110,11 @@ namespace Wino.Mail.ViewModels private DateTime creationDate; - public ObservableCollection ToItems { get; set; } = new ObservableCollection(); - public ObservableCollection CCItemsItems { get; set; } = new ObservableCollection(); - public ObservableCollection BCCItems { get; set; } = new ObservableCollection(); - public ObservableCollection Attachments { get; set; } = new ObservableCollection(); - public ObservableCollection MenuItems { get; set; } = new ObservableCollection(); + public ObservableCollection ToItems { get; set; } = []; + public ObservableCollection CcItems { get; set; } = []; + public ObservableCollection BccItems { get; set; } = []; + public ObservableCollection Attachments { get; set; } = []; + public ObservableCollection MenuItems { get; set; } = []; #endregion @@ -399,12 +400,24 @@ namespace Wino.Mail.ViewModels var renderingOptions = PreferencesService.GetRenderingOptions(); - await ExecuteUIThread(async () => + // Prepare account contacts info in advance, to avoid UI shifts after clearing collections. + var toAccountContacts = await GetAccountContacts(message.To); + var ccAccountContacts = await GetAccountContacts(message.Cc); + var bccAccountContacts = await GetAccountContacts(message.Bcc); + + await ExecuteUIThread(() => { Attachments.Clear(); ToItems.Clear(); - CCItemsItems.Clear(); - BCCItems.Clear(); + CcItems.Clear(); + BccItems.Clear(); + + foreach (var item in toAccountContacts) + ToItems.Add(item); + foreach (var item in ccAccountContacts) + CcItems.Add(item); + foreach (var item in bccAccountContacts) + BccItems.Add(item); Subject = message.Subject; @@ -414,11 +427,6 @@ namespace Wino.Mail.ViewModels CreationDate = message.Date.DateTime; ContactPicture = initializedMailItemViewModel.SenderContact?.Base64ContactPicture; - // Extract to,cc and bcc - await LoadAddressInfoAsync(message.To, ToItems); - await LoadAddressInfoAsync(message.Cc, CCItemsItems); - await LoadAddressInfoAsync(message.Bcc, BCCItems); - // Automatically disable images for Junk folder to prevent pixel tracking. // This can only work for selected mail item rendering, not for EML file rendering. if (initializedMailItemViewModel != null && @@ -448,6 +456,27 @@ namespace Wino.Mail.ViewModels }); } + private async Task> GetAccountContacts(InternetAddressList internetAddresses) + { + var accounts = new List(); + foreach (var item in internetAddresses) + { + if (item is MailboxAddress mailboxAddress) + { + var foundContact = await _contactService.GetAddressInformationByAddressAsync(mailboxAddress.Address).ConfigureAwait(false) + ?? new AccountContact() { Name = mailboxAddress.Name, Address = mailboxAddress.Address }; + + accounts.Add(foundContact); + } + else if (item is GroupAddress groupAddress) + { + accounts.AddRange(await GetAccountContacts(groupAddress.Members)); + } + } + + return accounts; + } + public override void OnNavigatedFrom(NavigationMode mode, object parameters) { base.OnNavigatedFrom(mode, parameters); @@ -463,22 +492,6 @@ namespace Wino.Mail.ViewModels StatePersistenceService.IsReadingMail = false; } - private async Task LoadAddressInfoAsync(InternetAddressList list, ObservableCollection collection) - { - foreach (var item in list) - { - if (item is MailboxAddress mailboxAddress) - { - var foundContact = await _contactService.GetAddressInformationByAddressAsync(mailboxAddress.Address).ConfigureAwait(false) - ?? new AccountContact() { Name = mailboxAddress.Name, Address = mailboxAddress.Address }; - - await ExecuteUIThread(() => { collection.Add(foundContact); }); - } - else if (item is GroupAddress groupAddress) - await LoadAddressInfoAsync(groupAddress.Members, collection); - } - } - private void ResetProgress() { CurrentDownloadPercentage = 0; diff --git a/Wino.Mail/AppShell.xaml b/Wino.Mail/AppShell.xaml index e622196c..896bc658 100644 --- a/Wino.Mail/AppShell.xaml +++ b/Wino.Mail/AppShell.xaml @@ -190,7 +190,8 @@ IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}" IsSelected="{x:Bind IsSelected, Mode=TwoWay}" MenuItemsSource="{x:Bind SubMenuItems, Mode=OneWay}" - SelectsOnInvoked="{x:Bind IsMoveTarget, Mode=OneWay}"> + SelectsOnInvoked="{x:Bind IsMoveTarget, Mode=OneWay}" + ToolTipService.ToolTip="{x:Bind FolderName, Mode=OneWay}"> @@ -210,9 +211,6 @@ x:Name="FolderBackgroundGrid" Padding="2" VerticalAlignment="Center"> - - - + SelectsOnInvoked="True" + ToolTipService.ToolTip="{x:Bind FolderName, Mode=OneWay}"> @@ -327,9 +326,6 @@ x:Name="FolderBackgroundGrid" Padding="2" VerticalAlignment="Center"> - - - + Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.CcItems.Count), Mode=OneWay}" /> + ItemsSource="{x:Bind ViewModel.CcItems, Mode=OneWay}" + Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.CcItems.Count), Mode=OneWay}"> @@ -286,13 +286,13 @@ VerticalAlignment="Center" FontWeight="SemiBold" Text="Bcc:" - Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.BCCItems.Count), Mode=OneWay}" /> + Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.BccItems.Count), Mode=OneWay}" /> + ItemsSource="{x:Bind ViewModel.BccItems, Mode=OneWay}" + Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.BccItems.Count), Mode=OneWay}">