2024-04-18 01:44:37 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-11-10 23:28:25 +01:00
|
|
|
|
using Wino.Core.Domain.Entities.Shared;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
|
using Wino.Core.Domain.Models.Folders;
|
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
namespace Wino.Core.Domain.MenuItems;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class AccountMenuItem : MenuItemBase<MailAccount, MenuItemBase<IMailItemFolder, FolderMenuItem>>, IAccountMenuItem
|
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]
|
|
|
|
|
|
[NotifyPropertyChangedFor(nameof(IsSynchronizationProgressVisible))]
|
|
|
|
|
|
private double synchronizationProgress;
|
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 bool IsAttentionRequired => AttentionReason != AccountAttentionReason.None;
|
|
|
|
|
|
public bool IsSynchronizationProgressVisible => SynchronizationProgress > 0 && SynchronizationProgress < 100;
|
2024-11-26 23:44:32 +01:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// We can't determine the progress for gmail synchronization since it is based on history changes.
|
|
|
|
|
|
public bool IsProgressIndeterminate => Parameter?.ProviderType == MailProviderType.Gmail;
|
|
|
|
|
|
public Guid AccountId => Parameter.Id;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
private AccountAttentionReason attentionReason;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public AccountAttentionReason AttentionReason
|
|
|
|
|
|
{
|
|
|
|
|
|
get => attentionReason;
|
|
|
|
|
|
set
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
if (SetProperty(ref attentionReason, value))
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
OnPropertyChanged(nameof(IsAttentionRequired));
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
UpdateFixAccountIssueMenuItem();
|
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
|
|
|
|
public string AccountName
|
|
|
|
|
|
{
|
|
|
|
|
|
get => Parameter.Name;
|
|
|
|
|
|
set => SetProperty(Parameter.Name, value, Parameter, (u, n) => u.Name = n);
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public string Base64ProfilePicture
|
|
|
|
|
|
{
|
|
|
|
|
|
get => Parameter.Name;
|
|
|
|
|
|
set => SetProperty(Parameter.Base64ProfilePictureData, value, Parameter, (u, n) => u.Base64ProfilePictureData = n);
|
|
|
|
|
|
}
|
2024-08-15 23:57:45 +02:00
|
|
|
|
|
2025-03-01 01:17:04 +01:00
|
|
|
|
public string AccountColorHex
|
|
|
|
|
|
{
|
|
|
|
|
|
get => Parameter.AccountColorHex;
|
|
|
|
|
|
set => SetProperty(Parameter.AccountColorHex, value, Parameter, (u, n) => u.AccountColorHex = n);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public IEnumerable<MailAccount> HoldingAccounts => new List<MailAccount> { Parameter };
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public AccountMenuItem(MailAccount account, IMenuItem parent = null) : base(account, account.Id, parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateAccount(account);
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public void UpdateAccount(MailAccount account)
|
|
|
|
|
|
{
|
|
|
|
|
|
Parameter = account;
|
2025-03-01 01:17:04 +01:00
|
|
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(AccountName));
|
|
|
|
|
|
OnPropertyChanged(nameof(Base64ProfilePicture));
|
|
|
|
|
|
OnPropertyChanged(nameof(AccountColorHex));
|
|
|
|
|
|
OnPropertyChanged(nameof(IsAttentionRequired));
|
2024-06-09 02:59:07 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
if (SubMenuItems == null) return;
|
2024-06-09 02:59:07 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
foreach (var item in SubMenuItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item is IFolderMenuItem folderMenuItem)
|
2024-06-09 02:59:07 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
folderMenuItem.UpdateParentAccounnt(account);
|
2024-06-09 02:59:07 +02:00
|
|
|
|
}
|
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 UpdateFixAccountIssueMenuItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (AttentionReason != AccountAttentionReason.None && !SubMenuItems.Any(a => a is FixAccountIssuesMenuItem))
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// Add fix issue item if not exists.
|
|
|
|
|
|
SubMenuItems.Insert(0, new FixAccountIssuesMenuItem(Parameter, this));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Remove existing if issue is resolved.
|
|
|
|
|
|
var fixAccountIssueItem = SubMenuItems.FirstOrDefault(a => a is FixAccountIssuesMenuItem);
|
2025-02-16 11:43:30 +01:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
if (fixAccountIssueItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
SubMenuItems.Remove(fixAccountIssueItem);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|