Swipe action implementations.
This commit is contained in:
@@ -41,7 +41,8 @@ public partial class MailListPageViewModel : MailBaseViewModel,
|
||||
IRecipient<AccountSynchronizerStateChanged>,
|
||||
IRecipient<AccountCacheResetMessage>,
|
||||
IRecipient<ThumbnailAdded>,
|
||||
IRecipient<PropertyChangedMessage<bool>>
|
||||
IRecipient<PropertyChangedMessage<bool>>,
|
||||
IRecipient<SwipeActionRequested>
|
||||
{
|
||||
private bool isChangingFolder = false;
|
||||
|
||||
@@ -1126,4 +1127,28 @@ public partial class MailListPageViewModel : MailBaseViewModel,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async void Receive(SwipeActionRequested message)
|
||||
{
|
||||
if (message.MailItem == null) return;
|
||||
|
||||
// Get mail copies based on the mail item type
|
||||
IEnumerable<MailCopy> mailCopies;
|
||||
|
||||
if (message.MailItem is MailItemViewModel singleItem)
|
||||
{
|
||||
mailCopies = new[] { singleItem.MailCopy };
|
||||
}
|
||||
else if (message.MailItem is ThreadMailItemViewModel threadItem)
|
||||
{
|
||||
mailCopies = threadItem.ThreadEmails.Select(e => e.MailCopy);
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // Unknown mail item type
|
||||
}
|
||||
|
||||
var package = new MailOperationPreperationRequest(message.Operation, mailCopies);
|
||||
await ExecuteMailOperationAsync(package);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
|
||||
namespace Wino.Mail.ViewModels.Messages;
|
||||
|
||||
/// <summary>
|
||||
/// When a swipe action is performed on a mail item container.
|
||||
/// </summary>
|
||||
public record SwipeActionRequested(MailOperation Operation, IMailListItem MailItem);
|
||||
@@ -18,6 +18,19 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:WinoThreadMailItemViewModelListViewItem">
|
||||
<SwipeControl x:Name="ThreadSwipeControl" Tag="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item}">
|
||||
<SwipeControl.LeftItems>
|
||||
<controls:WinoSwipeControlItems
|
||||
x:Name="LeftSwipeItems"
|
||||
IsRightSwipe="False"
|
||||
MailItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item}" />
|
||||
</SwipeControl.LeftItems>
|
||||
<SwipeControl.RightItems>
|
||||
<controls:WinoSwipeControlItems
|
||||
x:Name="RightSwipeItems"
|
||||
IsRightSwipe="True"
|
||||
MailItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item}" />
|
||||
</SwipeControl.RightItems>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="8" />
|
||||
@@ -37,6 +50,7 @@
|
||||
Background="{ThemeResource ListViewItemSelectionIndicatorBrush}"
|
||||
CornerRadius="4"
|
||||
Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item.IsSelected, Mode=OneWay}" />
|
||||
|
||||
<!-- Expandable Content -->
|
||||
<ContentPresenter
|
||||
x:Name="ThreadContent"
|
||||
@@ -47,6 +61,9 @@
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
|
||||
|
||||
</Grid>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Normal" />
|
||||
@@ -80,8 +97,7 @@
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
|
||||
</SwipeControl>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
@@ -95,6 +111,19 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:WinoMailItemViewModelListViewItem">
|
||||
<SwipeControl x:Name="MailSwipeControl" Tag="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item}">
|
||||
<SwipeControl.LeftItems>
|
||||
<controls:WinoSwipeControlItems
|
||||
x:Name="LeftSwipeItems"
|
||||
IsRightSwipe="False"
|
||||
MailItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item}" />
|
||||
</SwipeControl.LeftItems>
|
||||
<SwipeControl.RightItems>
|
||||
<controls:WinoSwipeControlItems
|
||||
x:Name="RightSwipeItems"
|
||||
IsRightSwipe="True"
|
||||
MailItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item}" />
|
||||
</SwipeControl.RightItems>
|
||||
<Grid
|
||||
x:Name="RootGrid"
|
||||
Margin="0,2"
|
||||
@@ -123,6 +152,9 @@
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
|
||||
|
||||
</Grid>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Normal" />
|
||||
@@ -156,7 +188,7 @@
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
</SwipeControl>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.WinUI;
|
||||
using Wino.Helpers;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
|
||||
namespace Wino.Controls;
|
||||
|
||||
public partial class WinoSwipeControlItems : SwipeItems
|
||||
{
|
||||
public static readonly DependencyProperty SwipeOperationProperty = DependencyProperty.Register(nameof(SwipeOperation), typeof(MailOperation), typeof(WinoSwipeControlItems), new PropertyMetadata(default(MailOperation), new PropertyChangedCallback(OnItemsChanged)));
|
||||
public static readonly DependencyProperty MailItemProperty = DependencyProperty.Register(nameof(MailItem), typeof(IMailListItem), typeof(WinoSwipeControlItems), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty IsRightSwipeProperty = DependencyProperty.Register(nameof(IsRightSwipe), typeof(bool), typeof(WinoSwipeControlItems), new PropertyMetadata(false, new PropertyChangedCallback(OnItemsChanged)));
|
||||
|
||||
public WinoSwipeControlItems()
|
||||
{
|
||||
var preferencesService = WinoApplication.Current.Services.GetRequiredService<IPreferencesService>();
|
||||
|
||||
SwipeOperation = IsRightSwipe ? preferencesService.RightSwipeOperation : preferencesService.LeftSwipeOperation;
|
||||
}
|
||||
|
||||
public IMailListItem MailItem
|
||||
{
|
||||
get { return (IMailListItem)GetValue(MailItemProperty); }
|
||||
set { SetValue(MailItemProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public MailOperation SwipeOperation
|
||||
{
|
||||
get { return (MailOperation)GetValue(SwipeOperationProperty); }
|
||||
set { SetValue(SwipeOperationProperty, value); }
|
||||
}
|
||||
|
||||
public bool IsRightSwipe
|
||||
{
|
||||
get { return (bool)GetValue(IsRightSwipeProperty); }
|
||||
set { SetValue(IsRightSwipeProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnItemsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (obj is WinoSwipeControlItems control)
|
||||
{
|
||||
control.BuildSwipeItems();
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildSwipeItems()
|
||||
{
|
||||
this.Clear();
|
||||
|
||||
var swipeItem = GetSwipeItem(SwipeOperation);
|
||||
|
||||
this.Add(swipeItem);
|
||||
}
|
||||
|
||||
private SwipeItem GetSwipeItem(MailOperation operation)
|
||||
{
|
||||
if (MailItem == null) return null;
|
||||
|
||||
var finalOperation = operation;
|
||||
|
||||
bool isSingleItem = MailItem is MailItemViewModel;
|
||||
|
||||
if (isSingleItem)
|
||||
{
|
||||
var singleItem = MailItem as MailItemViewModel;
|
||||
|
||||
if (operation == MailOperation.MarkAsRead && singleItem.IsRead)
|
||||
finalOperation = MailOperation.MarkAsUnread;
|
||||
else if (operation == MailOperation.MarkAsUnread && !singleItem.IsRead)
|
||||
finalOperation = MailOperation.MarkAsRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
var threadItem = MailItem as ThreadMailItemViewModel;
|
||||
|
||||
if (operation == MailOperation.MarkAsRead && threadItem.ThreadEmails.All(a => a.IsRead))
|
||||
finalOperation = MailOperation.MarkAsUnread;
|
||||
else if (operation == MailOperation.MarkAsUnread && threadItem.ThreadEmails.All(a => !a.IsRead))
|
||||
finalOperation = MailOperation.MarkAsRead;
|
||||
}
|
||||
|
||||
var item = new SwipeItem()
|
||||
{
|
||||
IconSource = new WinoFontIconSource() { Icon = XamlHelpers.GetWinoIconGlyph(finalOperation) },
|
||||
Text = XamlHelpers.GetOperationString(finalOperation),
|
||||
};
|
||||
|
||||
item.Invoked += SwipeItemInvoked;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private void SwipeItemInvoked(SwipeItem sender, SwipeItemInvokedEventArgs args)
|
||||
{
|
||||
var swipeControl = args.SwipeControl;
|
||||
swipeControl.Close();
|
||||
|
||||
if (MailItem == null) return;
|
||||
|
||||
// Determine the final operation based on current settings and mail item state
|
||||
var finalOperation = SwipeOperation;
|
||||
|
||||
bool isSingleItem = MailItem is MailItemViewModel;
|
||||
|
||||
if (isSingleItem)
|
||||
{
|
||||
var singleItem = MailItem as MailItemViewModel;
|
||||
|
||||
if (SwipeOperation == MailOperation.MarkAsRead && singleItem.IsRead)
|
||||
finalOperation = MailOperation.MarkAsUnread;
|
||||
else if (SwipeOperation == MailOperation.MarkAsUnread && !singleItem.IsRead)
|
||||
finalOperation = MailOperation.MarkAsRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
var threadItem = MailItem as ThreadMailItemViewModel;
|
||||
|
||||
if (SwipeOperation == MailOperation.MarkAsRead && threadItem.ThreadEmails.All(a => a.IsRead))
|
||||
finalOperation = MailOperation.MarkAsUnread;
|
||||
else if (SwipeOperation == MailOperation.MarkAsUnread && threadItem.ThreadEmails.All(a => !a.IsRead))
|
||||
finalOperation = MailOperation.MarkAsRead;
|
||||
}
|
||||
|
||||
// Send message to MailListPageViewModel to handle the operation
|
||||
CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger.Default.Send(new Mail.ViewModels.Messages.SwipeActionRequested(finalOperation, MailItem));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user