Removed the INC registrations for list view items.
This commit is contained in:
@@ -42,6 +42,15 @@ public partial class MailItemViewModel(MailCopy mailCopy) : ObservableRecipient,
|
|||||||
[NotifyPropertyChangedRecipients]
|
[NotifyPropertyChangedRecipients]
|
||||||
public partial bool IsSelected { get; set; }
|
public partial bool IsSelected { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Direct callback invoked when <see cref="IsSelected"/> changes.
|
||||||
|
/// Used by the ListViewItem container to update its IsCustomSelected DP
|
||||||
|
/// without subscribing to INotifyPropertyChanged (faster, AOT-safe).
|
||||||
|
/// </summary>
|
||||||
|
public Action<bool> OnSelectionChanged { get; set; }
|
||||||
|
|
||||||
|
partial void OnIsSelectedChanged(bool value) => OnSelectionChanged?.Invoke(value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates if this mail item is currently being processed by a network operation.
|
/// Indicates if this mail item is currently being processed by a network operation.
|
||||||
/// Used to show loading state in the UI.
|
/// Used to show loading state in the UI.
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ namespace Wino.Mail.ViewModels.Data;
|
|||||||
public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListItem
|
public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListItem
|
||||||
{
|
{
|
||||||
private readonly string _threadId;
|
private readonly string _threadId;
|
||||||
|
private readonly HashSet<Guid> _uniqueIdSet = [];
|
||||||
|
private MailItemViewModel _cachedLatestMailViewModel;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
[NotifyPropertyChangedRecipients]
|
[NotifyPropertyChangedRecipients]
|
||||||
@@ -25,6 +27,15 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
[NotifyPropertyChangedFor(nameof(IsSelectedOrExpanded))]
|
[NotifyPropertyChangedFor(nameof(IsSelectedOrExpanded))]
|
||||||
public partial bool IsSelected { get; set; }
|
public partial bool IsSelected { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Direct callback invoked when <see cref="IsSelected"/> changes.
|
||||||
|
/// Used by the ListViewItem container to update its IsCustomSelected DP
|
||||||
|
/// without subscribing to INotifyPropertyChanged (faster, AOT-safe).
|
||||||
|
/// </summary>
|
||||||
|
public Action<bool> OnSelectionChanged { get; set; }
|
||||||
|
|
||||||
|
partial void OnIsSelectedChanged(bool value) => OnSelectionChanged?.Invoke(value);
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public partial bool IsBusy { get; set; }
|
public partial bool IsBusy { get; set; }
|
||||||
|
|
||||||
@@ -168,7 +179,7 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
[NotifyPropertyChangedFor(nameof(Base64ContactPicture))]
|
[NotifyPropertyChangedFor(nameof(Base64ContactPicture))]
|
||||||
public partial ObservableCollection<MailItemViewModel> ThreadEmails { get; set; } = [];
|
public partial ObservableCollection<MailItemViewModel> ThreadEmails { get; set; } = [];
|
||||||
|
|
||||||
private MailItemViewModel latestMailViewModel => ThreadEmails.OrderByDescending(e => e.MailCopy?.CreationDate).FirstOrDefault()!;
|
private MailItemViewModel latestMailViewModel => _cachedLatestMailViewModel;
|
||||||
|
|
||||||
public DateTime SortingDate => CreationDate;
|
public DateTime SortingDate => CreationDate;
|
||||||
|
|
||||||
@@ -200,6 +211,8 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThreadEmails.Insert(insertIndex, email);
|
ThreadEmails.Insert(insertIndex, email);
|
||||||
|
_uniqueIdSet.Add(email.MailCopy.UniqueId);
|
||||||
|
_cachedLatestMailViewModel = ThreadEmails[0];
|
||||||
// Reassign to trigger property change notifications
|
// Reassign to trigger property change notifications
|
||||||
ThreadEmails = ThreadEmails;
|
ThreadEmails = ThreadEmails;
|
||||||
}
|
}
|
||||||
@@ -211,6 +224,8 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
{
|
{
|
||||||
if (ThreadEmails.Remove(email))
|
if (ThreadEmails.Remove(email))
|
||||||
{
|
{
|
||||||
|
_uniqueIdSet.Remove(email.MailCopy.UniqueId);
|
||||||
|
_cachedLatestMailViewModel = ThreadEmails.Count > 0 ? ThreadEmails[0] : null;
|
||||||
// Reassign to trigger property change notifications
|
// Reassign to trigger property change notifications
|
||||||
ThreadEmails = ThreadEmails;
|
ThreadEmails = ThreadEmails;
|
||||||
}
|
}
|
||||||
@@ -253,7 +268,7 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if this thread contains an email with the specified unique ID
|
/// Checks if this thread contains an email with the specified unique ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasUniqueId(Guid uniqueId) => ThreadEmails.Any(email => email.MailCopy.UniqueId == uniqueId);
|
public bool HasUniqueId(Guid uniqueId) => _uniqueIdSet.Contains(uniqueId);
|
||||||
|
|
||||||
public IEnumerable<Guid> GetContainingIds() => ThreadEmails.Select(a => a.MailCopy.UniqueId);
|
public IEnumerable<Guid> GetContainingIds() => ThreadEmails.Select(a => a.MailCopy.UniqueId);
|
||||||
|
|
||||||
|
|||||||
@@ -69,14 +69,12 @@ public partial class WinoListView : Microsoft.UI.Xaml.Controls.ListView
|
|||||||
&& container.Item != mailItemViewModel)
|
&& container.Item != mailItemViewModel)
|
||||||
{
|
{
|
||||||
container.Item = mailItemViewModel;
|
container.Item = mailItemViewModel;
|
||||||
container.IsCustomSelected = mailItemViewModel.IsSelected;
|
|
||||||
}
|
}
|
||||||
else if (item is ThreadMailItemViewModel threadMailItemViewModel
|
else if (item is ThreadMailItemViewModel threadMailItemViewModel
|
||||||
&& element is WinoThreadMailItemViewModelListViewItem threadContainer
|
&& element is WinoThreadMailItemViewModelListViewItem threadContainer
|
||||||
&& threadContainer.Item != threadMailItemViewModel)
|
&& threadContainer.Item != threadMailItemViewModel)
|
||||||
{
|
{
|
||||||
threadContainer.Item = threadMailItemViewModel;
|
threadContainer.Item = threadMailItemViewModel;
|
||||||
threadContainer.IsSelected = threadMailItemViewModel.IsSelected;
|
|
||||||
threadContainer.IsThreadExpanded = threadMailItemViewModel.IsThreadExpanded;
|
threadContainer.IsThreadExpanded = threadMailItemViewModel.IsThreadExpanded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,12 +86,10 @@ public partial class WinoListView : Microsoft.UI.Xaml.Controls.ListView
|
|||||||
if (item is MailItemViewModel mailItemViewModel && element is WinoMailItemViewModelListViewItem container)
|
if (item is MailItemViewModel mailItemViewModel && element is WinoMailItemViewModelListViewItem container)
|
||||||
{
|
{
|
||||||
container.Item = null;
|
container.Item = null;
|
||||||
container.IsCustomSelected = false;
|
|
||||||
}
|
}
|
||||||
else if (item is ThreadMailItemViewModel threadMailItemViewModel && element is WinoThreadMailItemViewModelListViewItem threadContainer)
|
else if (item is ThreadMailItemViewModel threadMailItemViewModel && element is WinoThreadMailItemViewModelListViewItem threadContainer)
|
||||||
{
|
{
|
||||||
threadContainer.Item = null;
|
threadContainer.Item = null;
|
||||||
threadContainer.IsSelected = false;
|
|
||||||
threadContainer.IsThreadExpanded = false;
|
threadContainer.IsThreadExpanded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.ComponentModel;
|
|
||||||
using CommunityToolkit.WinUI;
|
using CommunityToolkit.WinUI;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
@@ -23,26 +22,17 @@ public partial class WinoMailItemViewModelListViewItem : ListViewItem
|
|||||||
|
|
||||||
partial void OnItemPropertyChanged(DependencyPropertyChangedEventArgs e)
|
partial void OnItemPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
// TODO: This slows down. Optimize later.
|
if (e.OldValue is MailItemViewModel oldItem)
|
||||||
if (e.OldValue is MailItemViewModel oldMailItemViewModel) UnregisterPropertyChanged(oldMailItemViewModel);
|
oldItem.OnSelectionChanged = null;
|
||||||
if (e.NewValue is MailItemViewModel newMailItemViewModel) RegisterPropertyChanged(newMailItemViewModel);
|
|
||||||
|
|
||||||
if (e.NewValue is MailItemViewModel mailItemViewModel)
|
if (e.NewValue is MailItemViewModel newItem)
|
||||||
IsCustomSelected = mailItemViewModel.IsSelected;
|
|
||||||
else
|
|
||||||
IsCustomSelected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RegisterPropertyChanged(MailItemViewModel model) => model.PropertyChanged += ModelPropertyChanged;
|
|
||||||
private void UnregisterPropertyChanged(MailItemViewModel model) => model.PropertyChanged -= ModelPropertyChanged;
|
|
||||||
|
|
||||||
private void ModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (sender is not MailItemViewModel mailItemViewModel) return;
|
|
||||||
|
|
||||||
if (e.PropertyName == nameof(MailItemViewModel.IsSelected))
|
|
||||||
{
|
{
|
||||||
IsCustomSelected = mailItemViewModel.IsSelected;
|
newItem.OnSelectionChanged = (selected) => IsCustomSelected = selected;
|
||||||
|
IsCustomSelected = newItem.IsSelected;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsCustomSelected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using CommunityToolkit.WinUI;
|
using CommunityToolkit.WinUI;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
@@ -40,20 +39,17 @@ public partial class WinoThreadMailItemViewModelListViewItem : ListViewItem
|
|||||||
|
|
||||||
partial void OnItemPropertyChanged(DependencyPropertyChangedEventArgs e)
|
partial void OnItemPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.OldValue is ThreadMailItemViewModel oldMailItemViewModel) UnregisterPropertyChanged(oldMailItemViewModel);
|
if (e.OldValue is ThreadMailItemViewModel oldItem)
|
||||||
if (e.NewValue is ThreadMailItemViewModel newMailItemViewModel) RegisterPropertyChanged(newMailItemViewModel);
|
oldItem.OnSelectionChanged = null;
|
||||||
}
|
|
||||||
|
|
||||||
private void RegisterPropertyChanged(ThreadMailItemViewModel model) => model.PropertyChanged += ModelPropertyChanged;
|
if (e.NewValue is ThreadMailItemViewModel newItem)
|
||||||
private void UnregisterPropertyChanged(ThreadMailItemViewModel model) => model.PropertyChanged -= ModelPropertyChanged;
|
|
||||||
|
|
||||||
private void ModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (sender is not ThreadMailItemViewModel mailItemViewModel) return;
|
|
||||||
|
|
||||||
if (e.PropertyName == nameof(ThreadMailItemViewModel.IsSelected))
|
|
||||||
{
|
{
|
||||||
IsCustomSelected = mailItemViewModel.IsSelected;
|
newItem.OnSelectionChanged = (selected) => IsCustomSelected = selected;
|
||||||
|
IsCustomSelected = newItem.IsSelected;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsCustomSelected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user