Files
Wino-Mail/Wino.Mail/Controls/MailItemDisplayInformationControl.xaml.cs

219 lines
9.9 KiB
C#
Raw Normal View History

2024-08-31 03:37:04 +02:00
using System.Linq;
using System.Numerics;
2024-04-18 01:44:37 +02:00
using System.Windows.Input;
feat: Enhanced sender avatars with gravatar and favicons integration (#685) * feat: Enhanced sender avatars with gravatar and favicons integration * chore: Remove unused known companies thumbnails * feat(thumbnail): add IThumbnailService and refactor usage - Introduced a new interface `IThumbnailService` for handling thumbnail-related functionalities. - Registered `IThumbnailService` with its implementation `ThumbnailService` in the service container. - Updated `NotificationBuilder` to use an instance of `IThumbnailService` instead of static methods. - Refactored `ThumbnailService` from a static class to a regular class with instance methods and variables. - Modified `ImagePreviewControl` to utilize the new `IThumbnailService` instance. - Completed integration of `IThumbnailService` in the application by registering it in `App.xaml.cs`. * style: Show favicons as squares - Changed `hintCrop` in `NotificationBuilder` to `None` for app logo display. - Added `FaviconSquircle`, `FaviconImage`, and `isFavicon` to `ImagePreviewControl` for favicon handling. - Updated `UpdateInformation` method to manage favicon visibility. - Introduced `GetBitmapImageAsync` for converting Base64 to Bitmap images. - Enhanced XAML to include `FaviconSquircle` for improved UI appearance. * refactor thumbnail service * Removed old code and added clear method * added prefetch function * Change key from host to email * Remove redundant code * Test event * Fixed an issue with the thumbnail updated event. * Fix cutted favicons * exclude some domain from favicons * add yandex.ru * fix buttons in settings * remove prefetch method * Added thumbnails propagation to mailRenderingPage * Revert MailItemViewModel to object * Remove redundant code * spaces * await load parameter added * fix spaces * fix case sensativity for mail list thumbnails * change duckdns to google * Some cleanup. --------- Co-authored-by: Aleh Khantsevich <aleh.khantsevich@gmail.com> Co-authored-by: Burak Kaan Köse <bkaankose@outlook.com>
2025-06-21 01:40:25 +02:00
using CommunityToolkit.WinUI;
2024-04-18 01:44:37 +02:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Mail;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.MailItem;
using Wino.Extensions;
using Wino.Mail.ViewModels.Data;
2025-02-16 11:54:23 +01:00
namespace Wino.Controls;
public sealed partial class MailItemDisplayInformationControl : UserControl
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
public ImagePreviewControl GetImagePreviewControl() => ContactImage;
public bool IsRunningHoverAction { get; set; }
public static readonly DependencyProperty DisplayModeProperty = DependencyProperty.Register(nameof(DisplayMode), typeof(MailListDisplayMode), typeof(MailItemDisplayInformationControl), new PropertyMetadata(MailListDisplayMode.Spacious));
public static readonly DependencyProperty ShowPreviewTextProperty = DependencyProperty.Register(nameof(ShowPreviewText), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(true));
public static readonly DependencyProperty IsCustomFocusedProperty = DependencyProperty.Register(nameof(IsCustomFocused), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
public static readonly DependencyProperty IsAvatarVisibleProperty = DependencyProperty.Register(nameof(IsAvatarVisible), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(true));
public static readonly DependencyProperty IsSubjectVisibleProperty = DependencyProperty.Register(nameof(IsSubjectVisible), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(true));
public static readonly DependencyProperty ConnectedExpanderProperty = DependencyProperty.Register(nameof(ConnectedExpander), typeof(WinoExpander), typeof(MailItemDisplayInformationControl), new PropertyMetadata(null));
public static readonly DependencyProperty LeftHoverActionProperty = DependencyProperty.Register(nameof(LeftHoverAction), typeof(MailOperation), typeof(MailItemDisplayInformationControl), new PropertyMetadata(MailOperation.None));
public static readonly DependencyProperty CenterHoverActionProperty = DependencyProperty.Register(nameof(CenterHoverAction), typeof(MailOperation), typeof(MailItemDisplayInformationControl), new PropertyMetadata(MailOperation.None));
public static readonly DependencyProperty RightHoverActionProperty = DependencyProperty.Register(nameof(RightHoverAction), typeof(MailOperation), typeof(MailItemDisplayInformationControl), new PropertyMetadata(MailOperation.None));
public static readonly DependencyProperty HoverActionExecutedCommandProperty = DependencyProperty.Register(nameof(HoverActionExecutedCommand), typeof(ICommand), typeof(MailItemDisplayInformationControl), new PropertyMetadata(null));
public static readonly DependencyProperty MailItemProperty = DependencyProperty.Register(nameof(MailItem), typeof(IMailItem), typeof(MailItemDisplayInformationControl), new PropertyMetadata(null, new PropertyChangedCallback(OnMailItemChanged)));
public static readonly DependencyProperty IsHoverActionsEnabledProperty = DependencyProperty.Register(nameof(IsHoverActionsEnabled), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(true));
public static readonly DependencyProperty Prefer24HourTimeFormatProperty = DependencyProperty.Register(nameof(Prefer24HourTimeFormat), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
public static readonly DependencyProperty IsThreadExpanderVisibleProperty = DependencyProperty.Register(nameof(IsThreadExpanderVisible), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
public static readonly DependencyProperty IsThreadExpandedProperty = DependencyProperty.Register(nameof(IsThreadExpanded), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
feat: Enhanced sender avatars with gravatar and favicons integration (#685) * feat: Enhanced sender avatars with gravatar and favicons integration * chore: Remove unused known companies thumbnails * feat(thumbnail): add IThumbnailService and refactor usage - Introduced a new interface `IThumbnailService` for handling thumbnail-related functionalities. - Registered `IThumbnailService` with its implementation `ThumbnailService` in the service container. - Updated `NotificationBuilder` to use an instance of `IThumbnailService` instead of static methods. - Refactored `ThumbnailService` from a static class to a regular class with instance methods and variables. - Modified `ImagePreviewControl` to utilize the new `IThumbnailService` instance. - Completed integration of `IThumbnailService` in the application by registering it in `App.xaml.cs`. * style: Show favicons as squares - Changed `hintCrop` in `NotificationBuilder` to `None` for app logo display. - Added `FaviconSquircle`, `FaviconImage`, and `isFavicon` to `ImagePreviewControl` for favicon handling. - Updated `UpdateInformation` method to manage favicon visibility. - Introduced `GetBitmapImageAsync` for converting Base64 to Bitmap images. - Enhanced XAML to include `FaviconSquircle` for improved UI appearance. * refactor thumbnail service * Removed old code and added clear method * added prefetch function * Change key from host to email * Remove redundant code * Test event * Fixed an issue with the thumbnail updated event. * Fix cutted favicons * exclude some domain from favicons * add yandex.ru * fix buttons in settings * remove prefetch method * Added thumbnails propagation to mailRenderingPage * Revert MailItemViewModel to object * Remove redundant code * spaces * await load parameter added * fix spaces * fix case sensativity for mail list thumbnails * change duckdns to google * Some cleanup. --------- Co-authored-by: Aleh Khantsevich <aleh.khantsevich@gmail.com> Co-authored-by: Burak Kaan Köse <bkaankose@outlook.com>
2025-06-21 01:40:25 +02:00
public static readonly DependencyProperty IsThumbnailUpdatedProperty = DependencyProperty.Register(nameof(IsThumbnailUpdated), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
public bool IsThumbnailUpdated
{
get { return (bool)GetValue(IsThumbnailUpdatedProperty); }
set { SetValue(IsThumbnailUpdatedProperty, value); }
}
2025-02-16 11:54:23 +01:00
public bool IsThreadExpanded
{
get { return (bool)GetValue(IsThreadExpandedProperty); }
set { SetValue(IsThreadExpandedProperty, value); }
}
2025-02-16 11:54:23 +01:00
public bool IsThreadExpanderVisible
{
get { return (bool)GetValue(IsThreadExpanderVisibleProperty); }
set { SetValue(IsThreadExpanderVisibleProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool Prefer24HourTimeFormat
{
get { return (bool)GetValue(Prefer24HourTimeFormatProperty); }
set { SetValue(Prefer24HourTimeFormatProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsHoverActionsEnabled
{
get { return (bool)GetValue(IsHoverActionsEnabledProperty); }
set { SetValue(IsHoverActionsEnabledProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public IMailItem MailItem
{
get { return (IMailItem)GetValue(MailItemProperty); }
set { SetValue(MailItemProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public ICommand HoverActionExecutedCommand
{
get { return (ICommand)GetValue(HoverActionExecutedCommandProperty); }
set { SetValue(HoverActionExecutedCommandProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MailOperation LeftHoverAction
{
get { return (MailOperation)GetValue(LeftHoverActionProperty); }
set { SetValue(LeftHoverActionProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MailOperation CenterHoverAction
{
get { return (MailOperation)GetValue(CenterHoverActionProperty); }
set { SetValue(CenterHoverActionProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MailOperation RightHoverAction
{
get { return (MailOperation)GetValue(RightHoverActionProperty); }
set { SetValue(RightHoverActionProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public WinoExpander ConnectedExpander
{
get { return (WinoExpander)GetValue(ConnectedExpanderProperty); }
set { SetValue(ConnectedExpanderProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsSubjectVisible
{
get { return (bool)GetValue(IsSubjectVisibleProperty); }
set { SetValue(IsSubjectVisibleProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsAvatarVisible
{
get { return (bool)GetValue(IsAvatarVisibleProperty); }
set { SetValue(IsAvatarVisibleProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsCustomFocused
{
get { return (bool)GetValue(IsCustomFocusedProperty); }
set { SetValue(IsCustomFocusedProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool ShowPreviewText
{
get { return (bool)GetValue(ShowPreviewTextProperty); }
set { SetValue(ShowPreviewTextProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MailListDisplayMode DisplayMode
{
get { return (MailListDisplayMode)GetValue(DisplayModeProperty); }
set { SetValue(DisplayModeProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MailItemDisplayInformationControl()
{
this.InitializeComponent();
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
var compositor = this.Visual().Compositor;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
var leftBackgroundVisual = compositor.CreateSpriteVisual();
RootContainerVisualWrapper.SetChildVisual(leftBackgroundVisual);
MainContentContainer.EnableImplicitAnimation(VisualPropertyType.Offset, 400);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
RootContainer.EnableImplicitAnimation(VisualPropertyType.Offset, 400);
ContentGrid.EnableImplicitAnimation(VisualPropertyType.Offset, 400);
ContentStackpanel.EnableImplicitAnimation(VisualPropertyType.Offset, 400);
IconsContainer.EnableImplicitAnimation(VisualPropertyType.Offset, 400);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
RootContainerVisualWrapper.SizeChanged += (s, e) => leftBackgroundVisual.Size = e.NewSize.ToVector2();
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private static void OnMailItemChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is MailItemDisplayInformationControl control)
{
2025-02-16 11:54:23 +01:00
control.UpdateInformation();
}
2025-02-16 11:54:23 +01:00
}
2025-02-16 11:54:23 +01:00
private void UpdateInformation()
{
if (MailItem == null) return;
2025-02-16 11:54:23 +01:00
TitleText.Text = string.IsNullOrWhiteSpace(MailItem.Subject) ? Translator.MailItemNoSubject : MailItem.Subject;
}
2025-02-16 11:54:23 +01:00
private void ControlPointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
if (IsHoverActionsEnabled)
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
HoverActionButtons.Visibility = Visibility.Visible;
2025-03-18 00:10:45 +01:00
UnreadContainer.Visibility = Visibility.Collapsed;
2024-04-18 01:44:37 +02:00
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void ControlPointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
if (IsHoverActionsEnabled)
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
HoverActionButtons.Visibility = Visibility.Collapsed;
2025-03-18 00:10:45 +01:00
UnreadContainer.Visibility = Visibility.Visible;
2024-04-18 01:44:37 +02:00
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void ExecuteHoverAction(MailOperation operation)
{
IsRunningHoverAction = true;
2024-08-31 03:37:04 +02:00
2025-02-16 11:54:23 +01:00
MailOperationPreperationRequest package = null;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (MailItem is MailCopy mailCopy)
package = new MailOperationPreperationRequest(operation, mailCopy, toggleExecution: true);
else if (MailItem is ThreadMailItemViewModel threadMailItemViewModel)
package = new MailOperationPreperationRequest(operation, threadMailItemViewModel.GetMailCopies(), toggleExecution: true);
else if (MailItem is ThreadMailItem threadMailItem)
package = new MailOperationPreperationRequest(operation, threadMailItem.ThreadItems.Cast<MailItemViewModel>().Select(a => a.MailCopy), toggleExecution: true);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (package == null) return;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
HoverActionExecutedCommand?.Execute(package);
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void FirstActionClicked(object sender, RoutedEventArgs e)
{
ExecuteHoverAction(LeftHoverAction);
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void SecondActionClicked(object sender, RoutedEventArgs e)
{
ExecuteHoverAction(CenterHoverAction);
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void ThirdActionClicked(object sender, RoutedEventArgs e)
{
ExecuteHoverAction(RightHoverAction);
2024-04-18 01:44:37 +02:00
}
}