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
This commit is contained in:
Tiktack
2024-09-14 18:41:33 +02:00
committed by GitHub
parent 12f821fd6b
commit 4ac8095554
3 changed files with 52 additions and 43 deletions

View File

@@ -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<AccountContact> ToItems { get; set; } = new ObservableCollection<AccountContact>();
public ObservableCollection<AccountContact> CCItemsItems { get; set; } = new ObservableCollection<AccountContact>();
public ObservableCollection<AccountContact> BCCItems { get; set; } = new ObservableCollection<AccountContact>();
public ObservableCollection<MailAttachmentViewModel> Attachments { get; set; } = new ObservableCollection<MailAttachmentViewModel>();
public ObservableCollection<MailOperationMenuItem> MenuItems { get; set; } = new ObservableCollection<MailOperationMenuItem>();
public ObservableCollection<AccountContact> ToItems { get; set; } = [];
public ObservableCollection<AccountContact> CcItems { get; set; } = [];
public ObservableCollection<AccountContact> BccItems { get; set; } = [];
public ObservableCollection<MailAttachmentViewModel> Attachments { get; set; } = [];
public ObservableCollection<MailOperationMenuItem> 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<List<AccountContact>> GetAccountContacts(InternetAddressList internetAddresses)
{
var accounts = new List<AccountContact>();
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<AccountContact> 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;

View File

@@ -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}">
<animations:Implicit.Animations>
<animations:ScaleAnimation Duration="0:0:0.5" />
</animations:Implicit.Animations>
@@ -210,9 +211,6 @@
x:Name="FolderBackgroundGrid"
Padding="2"
VerticalAlignment="Center">
<ToolTipService.ToolTip>
<ToolTip Content="{x:Bind FolderName, Mode=OneWay}" />
</ToolTipService.ToolTip>
<Grid
x:Name="BackgroundColorGrid"
x:Load="{x:Bind HasTextColor, Mode=OneWay}"
@@ -308,7 +306,8 @@
FontWeight="{x:Bind helpers:XamlHelpers.GetFontWeightByChildSelectedState(IsSelected), Mode=OneWay}"
IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}"
IsSelected="{x:Bind IsSelected, Mode=TwoWay}"
SelectsOnInvoked="True">
SelectsOnInvoked="True"
ToolTipService.ToolTip="{x:Bind FolderName, Mode=OneWay}">
<animations:Implicit.Animations>
<animations:ScaleAnimation Duration="0:0:0.5" />
</animations:Implicit.Animations>
@@ -327,9 +326,6 @@
x:Name="FolderBackgroundGrid"
Padding="2"
VerticalAlignment="Center">
<ToolTipService.ToolTip>
<ToolTip Content="{x:Bind FolderName, Mode=OneWay}" />
</ToolTipService.ToolTip>
<TextBlock
x:Name="NormalTitle"
VerticalAlignment="Center"

View File

@@ -263,12 +263,12 @@
VerticalAlignment="Center"
FontWeight="SemiBold"
Text="Cc:"
Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.CCItemsItems.Count), Mode=OneWay}" />
Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.CcItems.Count), Mode=OneWay}" />
<ItemsControl
Grid.Column="1"
ItemTemplate="{StaticResource InternetAddressTemplate}"
ItemsSource="{x:Bind ViewModel.CCItemsItems, Mode=OneWay}"
Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.CCItemsItems.Count), Mode=OneWay}">
ItemsSource="{x:Bind ViewModel.CcItems, Mode=OneWay}"
Visibility="{x:Bind helpers:XamlHelpers.CountToVisibilityConverter(ViewModel.CcItems.Count), Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" />
@@ -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}" />
<ItemsControl
Grid.Column="1"
ItemTemplate="{StaticResource InternetAddressTemplate}"
ItemsSource="{x:Bind ViewModel.BCCItems, 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}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" />