2026-04-11 12:57:51 +02:00
|
|
|
using System.Collections.Generic;
|
2024-04-18 01:44:37 +02:00
|
|
|
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;
|
2026-04-11 12:57:51 +02:00
|
|
|
using Wino.Core.Domain.Models.Synchronization;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
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-02-16 11:54:23 +01:00
|
|
|
[ObservableProperty]
|
2026-04-11 12:57:51 +02:00
|
|
|
[NotifyPropertyChangedFor(nameof(IsSynchronizationProgressVisible), nameof(IsProgressIndeterminate), nameof(SynchronizationProgress), nameof(SynchronizationProgressValue))]
|
|
|
|
|
public partial bool IsSynchronizationInProgress { get; set; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(SynchronizationProgressValue), nameof(IsProgressIndeterminate))]
|
2025-10-31 00:51:27 +01:00
|
|
|
public partial int TotalItemsToSync { get; set; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2026-04-11 12:57:51 +02:00
|
|
|
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(SynchronizationProgressValue), nameof(IsProgressIndeterminate))]
|
2025-10-31 00:51:27 +01:00
|
|
|
public partial int RemainingItemsToSync { get; set; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial string SynchronizationStatus { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public double SynchronizationProgress
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2026-04-11 12:57:51 +02:00
|
|
|
if (TotalItemsToSync <= 0)
|
|
|
|
|
return 0;
|
2025-10-31 00:51:27 +01:00
|
|
|
|
|
|
|
|
return ((double)(TotalItemsToSync - RemainingItemsToSync) / TotalItemsToSync) * 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2026-04-11 12:57:51 +02:00
|
|
|
public double SynchronizationProgressValue => SynchronizationProgress;
|
|
|
|
|
|
|
|
|
|
public bool IsSynchronizationProgressVisible => IsSynchronizationInProgress;
|
2025-10-31 01:41:51 +01:00
|
|
|
|
2026-04-11 12:57:51 +02:00
|
|
|
public bool IsProgressIndeterminate => IsSynchronizationInProgress && TotalItemsToSync <= 0;
|
2025-10-31 01:41:51 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
2026-04-11 12:57:51 +02:00
|
|
|
|
2025-10-31 00:51:27 +01:00
|
|
|
public void RefreshSynchronizationProgress()
|
|
|
|
|
{
|
2026-04-11 12:57:51 +02:00
|
|
|
var activeAccountMenuItems = SubMenuItems
|
|
|
|
|
.OfType<IAccountMenuItem>()
|
|
|
|
|
.Where(a => a.IsSynchronizationInProgress)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
IsSynchronizationInProgress = activeAccountMenuItems.Any();
|
|
|
|
|
TotalItemsToSync = activeAccountMenuItems.Sum(a => a.TotalItemsToSync);
|
|
|
|
|
RemainingItemsToSync = activeAccountMenuItems.Sum(a => a.RemainingItemsToSync);
|
|
|
|
|
SynchronizationStatus = activeAccountMenuItems
|
|
|
|
|
.Select(a => a.SynchronizationStatus)
|
|
|
|
|
.FirstOrDefault(s => !string.IsNullOrWhiteSpace(s)) ?? string.Empty;
|
2025-10-31 00:51:27 +01:00
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2026-04-11 12:57:51 +02:00
|
|
|
public void ApplySynchronizationProgress(AccountSynchronizationProgress progress)
|
2025-02-16 11:54:23 +01:00
|
|
|
{
|
2026-04-11 12:57:51 +02:00
|
|
|
if (progress == null)
|
|
|
|
|
return;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
2026-04-11 12:57:51 +02:00
|
|
|
IsSynchronizationInProgress = progress.IsInProgress;
|
|
|
|
|
TotalItemsToSync = progress.TotalUnits;
|
|
|
|
|
RemainingItemsToSync = progress.RemainingUnits;
|
|
|
|
|
SynchronizationStatus = progress.Status ?? string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateAccount(MailAccount account)
|
|
|
|
|
{
|
2024-04-18 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
}
|