2024-04-18 01:44:37 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-11-10 23:28:25 +01:00
|
|
|
using Wino.Core.Domain.Entities.Mail;
|
|
|
|
|
using Wino.Core.Domain.Entities.Shared;
|
2024-04-18 01:44:37 +02:00
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
namespace Wino.Core.Domain.MenuItems;
|
|
|
|
|
|
|
|
|
|
public partial class MergedAccountMenuItem : MenuItemBase<MergedInbox, IMenuItem>, IMergedAccountMenuItem
|
2024-04-18 01:44:37 +02:00
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
public int MergedAccountCount => HoldingAccounts?.Count() ?? 0;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public IEnumerable<MailAccount> HoldingAccounts { get; }
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
[ObservableProperty]
|
|
|
|
|
private int unreadItemCount;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2025-10-31 00:51:27 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Total items to sync across all merged accounts.
|
|
|
|
|
/// </summary>
|
2025-02-16 11:54:23 +01:00
|
|
|
[ObservableProperty]
|
2025-10-31 01:41:51 +01:00
|
|
|
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(IsSynchronizationProgressVisible), nameof(IsProgressIndeterminate))]
|
2025-10-31 00:51:27 +01:00
|
|
|
public partial int TotalItemsToSync { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remaining items to sync across all merged accounts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ObservableProperty]
|
2025-10-31 01:41:51 +01:00
|
|
|
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(IsSynchronizationProgressVisible), nameof(IsProgressIndeterminate))]
|
2025-10-31 00:51:27 +01:00
|
|
|
public partial int RemainingItemsToSync { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Current synchronization status message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial string SynchronizationStatus { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calculated synchronization progress for merged accounts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double SynchronizationProgress
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (TotalItemsToSync == 0 || RemainingItemsToSync == 0)
|
|
|
|
|
return -1; // Indeterminate
|
|
|
|
|
|
|
|
|
|
return ((double)(TotalItemsToSync - RemainingItemsToSync) / TotalItemsToSync) * 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2025-10-31 01:41:51 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether synchronization progress should be visible.
|
|
|
|
|
/// Visible when there's active synchronization (TotalItemsToSync > 0 or RemainingItemsToSync > 0).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsSynchronizationProgressVisible => TotalItemsToSync > 0 || RemainingItemsToSync > 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether progress should be indeterminate.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsProgressIndeterminate => TotalItemsToSync == 0 && IsSynchronizationProgressVisible;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
[ObservableProperty]
|
|
|
|
|
private string mergedAccountName;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool _isEnabled = true;
|
2024-07-09 01:05:16 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public MergedAccountMenuItem(MergedInbox mergedInbox, IEnumerable<MailAccount> holdingAccounts, IMenuItem parent) : base(mergedInbox, mergedInbox.Id, parent)
|
|
|
|
|
{
|
|
|
|
|
MergedAccountName = mergedInbox.Name;
|
|
|
|
|
HoldingAccounts = holdingAccounts;
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public void RefreshFolderItemCount()
|
|
|
|
|
{
|
|
|
|
|
UnreadItemCount = SubMenuItems.OfType<IAccountMenuItem>().Sum(a => a.UnreadItemCount);
|
|
|
|
|
}
|
2025-10-31 00:51:27 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Aggregates synchronization progress from all child account menu items.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RefreshSynchronizationProgress()
|
|
|
|
|
{
|
|
|
|
|
var accountMenuItems = SubMenuItems.OfType<IAccountMenuItem>().ToList();
|
|
|
|
|
|
|
|
|
|
TotalItemsToSync = accountMenuItems.Sum(a => a.TotalItemsToSync);
|
|
|
|
|
RemainingItemsToSync = accountMenuItems.Sum(a => a.RemainingItemsToSync);
|
|
|
|
|
|
|
|
|
|
// Use first non-empty status message
|
|
|
|
|
SynchronizationStatus = accountMenuItems.FirstOrDefault(a => !string.IsNullOrEmpty(a.SynchronizationStatus))?.SynchronizationStatus ?? string.Empty;
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public void UpdateAccount(MailAccount account)
|
|
|
|
|
{
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|