Ground work for Wino Calendar. (#475)

Wino Calendar abstractions.
This commit is contained in:
Burak Kaan Köse
2024-11-10 23:28:25 +01:00
committed by GitHub
parent a979e8430f
commit d1d6f12f05
486 changed files with 7969 additions and 2708 deletions

View File

@@ -1,109 +0,0 @@
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;
using Wino.Core.Domain;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels
{
public partial class AboutPageViewModel : BaseViewModel
{
private readonly IStoreRatingService _storeRatingService;
private readonly INativeAppService _nativeAppService;
private readonly IApplicationConfiguration _appInitializerService;
private readonly IFileService _fileService;
private readonly ILogInitializer _logInitializer;
public string VersionName => _nativeAppService.GetFullAppVersion();
public string DiscordChannelUrl => "https://discord.gg/windows-apps-hub-714581497222398064";
public string GitHubUrl => "https://github.com/bkaankose/Wino-Mail/";
public string PrivacyPolicyUrl => "https://www.winomail.app/privacy_policy.html";
public string PaypalUrl => "https://paypal.me/bkaankose?country.x=PL&locale.x=en_US";
public IPreferencesService PreferencesService { get; }
public AboutPageViewModel(IStoreRatingService storeRatingService,
IDialogService dialogService,
INativeAppService nativeAppService,
IPreferencesService preferencesService,
IApplicationConfiguration appInitializerService,
IFileService fileService,
ILogInitializer logInitializer) : base(dialogService)
{
_storeRatingService = storeRatingService;
_nativeAppService = nativeAppService;
_logInitializer = logInitializer;
_appInitializerService = appInitializerService;
_fileService = fileService;
PreferencesService = preferencesService;
}
protected override void OnActivated()
{
base.OnActivated();
PreferencesService.PreferenceChanged -= PreferencesChanged;
PreferencesService.PreferenceChanged += PreferencesChanged;
}
protected override void OnDeactivated()
{
base.OnDeactivated();
PreferencesService.PreferenceChanged -= PreferencesChanged;
}
private void PreferencesChanged(object sender, string e)
{
if (e == nameof(PreferencesService.IsLoggingEnabled))
{
_logInitializer.RefreshLoggingLevel();
}
}
[RelayCommand]
private async Task ShareWinoLogAsync()
{
var appDataFolder = _appInitializerService.ApplicationDataFolderPath;
var selectedFolderPath = await DialogService.PickWindowsFolderAsync();
if (string.IsNullOrEmpty(selectedFolderPath)) return;
var areLogsSaved = await _fileService.SaveLogsToFolderAsync(appDataFolder, selectedFolderPath).ConfigureAwait(false);
if (areLogsSaved)
{
DialogService.InfoBarMessage(Translator.Info_LogsSavedTitle, string.Format(Translator.Info_LogsSavedMessage, Constants.LogArchiveFileName), InfoBarMessageType.Success);
}
else
{
DialogService.InfoBarMessage(Translator.Info_LogsNotFoundTitle, Translator.Info_LogsNotFoundMessage, InfoBarMessageType.Error);
}
}
[RelayCommand]
private async Task Navigate(object url)
{
if (url is string stringUrl)
{
if (stringUrl == "Store")
await ShowRateDialogAsync();
else
{
// Discord disclaimer message about server.
if (stringUrl == DiscordChannelUrl)
await DialogService.ShowMessageAsync(Translator.DiscordChannelDisclaimerMessage,
Translator.DiscordChannelDisclaimerTitle,
WinoCustomMessageDialogIcon.Warning);
await _nativeAppService.LaunchUriAsync(new Uri(stringUrl));
}
}
}
private Task ShowRateDialogAsync() => _storeRatingService.LaunchStorePageForReviewAsync();
}
}

View File

@@ -6,7 +6,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Folders;
@@ -16,8 +16,9 @@ using Wino.Messaging.UI;
namespace Wino.Mail.ViewModels
{
public partial class AccountDetailsPageViewModel : BaseViewModel
public partial class AccountDetailsPageViewModel : MailBaseViewModel
{
private readonly IMailDialogService _dialogService;
private readonly IAccountService _accountService;
private readonly IFolderService _folderService;
@@ -45,17 +46,18 @@ namespace Wino.Mail.ViewModels
public bool IsFocusedInboxSupportedForAccount => Account != null && Account.Preferences.IsFocusedInboxEnabled != null;
public AccountDetailsPageViewModel(IDialogService dialogService,
public AccountDetailsPageViewModel(IMailDialogService dialogService,
IAccountService accountService,
IFolderService folderService) : base(dialogService)
IFolderService folderService)
{
_dialogService = dialogService;
_accountService = accountService;
_folderService = folderService;
}
[RelayCommand]
private Task SetupSpecialFolders()
=> DialogService.HandleSystemFolderConfigurationDialogAsync(Account.Id, _folderService);
=> _dialogService.HandleSystemFolderConfigurationDialogAsync(Account.Id, _folderService);
[RelayCommand]
private void EditSignature()
@@ -77,7 +79,7 @@ namespace Wino.Mail.ViewModels
if (Account == null)
return;
var updatedAccount = await DialogService.ShowEditAccountDialogAsync(Account);
var updatedAccount = await _dialogService.ShowEditAccountDialogAsync(Account);
if (updatedAccount != null)
{
@@ -93,7 +95,7 @@ namespace Wino.Mail.ViewModels
if (Account == null)
return;
var confirmation = await DialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_DeleteAccountConfirmationTitle,
var confirmation = await _dialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_DeleteAccountConfirmationTitle,
string.Format(Translator.DialogMessage_DeleteAccountConfirmationMessage, Account.Name),
Translator.Buttons_Delete);
@@ -104,7 +106,7 @@ namespace Wino.Mail.ViewModels
// TODO: Server: Cancel ongoing calls from server for this account.
DialogService.InfoBarMessage(Translator.Info_AccountDeletedTitle, string.Format(Translator.Info_AccountDeletedMessage, Account.Name), InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.Info_AccountDeletedTitle, string.Format(Translator.Info_AccountDeletedMessage, Account.Name), InfoBarMessageType.Success);
Messenger.Send(new BackBreadcrumNavigationRequested());
}

View File

@@ -1,91 +1,44 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AppCenter.Crashes;
using Serilog;
using Wino.Core;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Exceptions;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.Domain.Models.Store;
using Wino.Core.Domain.Models.Synchronization;
using Wino.Core.ViewModels;
using Wino.Core.ViewModels.Data;
using Wino.Mail.ViewModels.Data;
using Wino.Messaging.Client.Authorization;
using Wino.Messaging.Client.Navigation;
using Wino.Messaging.Server;
using Wino.Messaging.UI;
namespace Wino.Mail.ViewModels
{
public partial class AccountManagementViewModel : BaseViewModel, IRecipient<ProtocolAuthorizationCallbackReceived>
public partial class AccountManagementViewModel : AccountManagementPageViewModelBase
{
public int FREE_ACCOUNT_COUNT { get; } = 3;
public IMailDialogService MailDialogService { get; }
private readonly IDialogService _dialogService;
private readonly IAccountService _accountService;
private readonly IProviderService _providerService;
private readonly IFolderService _folderService;
private readonly IStoreManagementService _storeManagementService;
private readonly IPreferencesService _preferencesService;
private readonly IAuthenticationProvider _authenticationProvider;
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
public ObservableCollection<IAccountProviderDetailViewModel> Accounts { get; set; } = [];
public bool IsPurchasePanelVisible => !HasUnlimitedAccountProduct;
public bool IsAccountCreationAlmostOnLimit => Accounts != null && Accounts.Count == FREE_ACCOUNT_COUNT - 1;
public bool HasAccountsDefined => Accounts != null && Accounts.Any();
public bool CanReorderAccounts => Accounts?.Sum(a => a.HoldingAccountCount) > 1;
public string UsedAccountsString => string.Format(Translator.WinoUpgradeRemainingAccountsMessage, Accounts.Count, FREE_ACCOUNT_COUNT);
[ObservableProperty]
private IAccountProviderDetailViewModel _startupAccount;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsPurchasePanelVisible))]
private bool hasUnlimitedAccountProduct;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsAccountCreationAlmostOnLimit))]
[NotifyPropertyChangedFor(nameof(IsPurchasePanelVisible))]
private bool isAccountCreationBlocked;
public AccountManagementViewModel(IDialogService dialogService,
IWinoNavigationService navigationService,
public AccountManagementViewModel(IMailDialogService dialogService,
IWinoServerConnectionManager winoServerConnectionManager,
INavigationService navigationService,
IAccountService accountService,
IProviderService providerService,
IFolderService folderService,
IStoreManagementService storeManagementService,
IPreferencesService preferencesService,
IAuthenticationProvider authenticationProvider,
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
IPreferencesService preferencesService) : base(dialogService, winoServerConnectionManager, navigationService, accountService, providerService, storeManagementService, authenticationProvider, preferencesService)
{
_accountService = accountService;
_dialogService = dialogService;
_providerService = providerService;
_folderService = folderService;
_storeManagementService = storeManagementService;
_preferencesService = preferencesService;
_authenticationProvider = authenticationProvider;
_winoServerConnectionManager = winoServerConnectionManager;
}
[RelayCommand]
private void NavigateAccountDetails(AccountProviderDetailViewModel accountDetails)
{
Messenger.Send(new BreadcrumbNavigationRequested(accountDetails.Account.Name,
WinoPage.AccountDetailsPage,
accountDetails.Account.Id));
MailDialogService = dialogService;
}
[RelayCommand]
@@ -109,23 +62,7 @@ namespace Wino.Mail.ViewModels
mergedAccountProviderDetailViewModel));
}
[RelayCommand]
private async Task PurchaseUnlimitedAccountAsync()
{
var purchaseResult = await _storeManagementService.PurchaseAsync(StoreProductType.UnlimitedAccounts);
if (purchaseResult == StorePurchaseResult.Succeeded)
DialogService.InfoBarMessage(Translator.Info_PurchaseThankYouTitle, Translator.Info_PurchaseThankYouMessage, InfoBarMessageType.Success);
else if (purchaseResult == StorePurchaseResult.AlreadyPurchased)
DialogService.InfoBarMessage(Translator.Info_PurchaseExistsTitle, Translator.Info_PurchaseExistsMessage, InfoBarMessageType.Warning);
bool shouldRefreshPurchasePanel = purchaseResult == StorePurchaseResult.Succeeded || purchaseResult == StorePurchaseResult.AlreadyPurchased;
if (shouldRefreshPurchasePanel)
{
await ManageStorePurchasesAsync();
}
}
[RelayCommand]
private async Task AddNewAccountAsync()
@@ -146,16 +83,16 @@ namespace Wino.Mail.ViewModels
try
{
var providers = _providerService.GetProviderDetails();
var providers = ProviderService.GetProviderDetails();
// Select provider.
var accountCreationDialogResult = await _dialogService.ShowNewAccountMailProviderDialogAsync(providers);
var accountCreationDialogResult = await MailDialogService.ShowNewAccountMailProviderDialogAsync(providers);
var accountCreationCancellationTokenSource = new CancellationTokenSource();
if (accountCreationDialogResult != null)
{
creationDialog = _dialogService.GetAccountCreationDialog(accountCreationDialogResult.ProviderType);
creationDialog = MailDialogService.GetAccountCreationDialog(accountCreationDialogResult.ProviderType);
CustomServerInformation customServerInformation = null;
@@ -194,7 +131,7 @@ namespace Wino.Mail.ViewModels
{
// For OAuth authentications, we just generate token and assign it to the MailAccount.
var tokenInformationResponse = await _winoServerConnectionManager
var tokenInformationResponse = await WinoServerConnectionManager
.GetResponseAsync<TokenInformation, AuthorizationRequested>(new AuthorizationRequested(accountCreationDialogResult.ProviderType,
createdAccount,
createdAccount.ProviderType == MailProviderType.Gmail), accountCreationCancellationTokenSource.Token);
@@ -209,7 +146,7 @@ namespace Wino.Mail.ViewModels
tokenInformation.AccountId = createdAccount.Id;
}
await _accountService.CreateAccountAsync(createdAccount, tokenInformation, customServerInformation);
await AccountService.CreateAccountAsync(createdAccount, tokenInformation, customServerInformation);
// Local account has been created.
@@ -225,7 +162,7 @@ namespace Wino.Mail.ViewModels
Type = SynchronizationType.UpdateProfile
};
var profileSynchronizationResponse = await _winoServerConnectionManager.GetResponseAsync<SynchronizationResult, NewSynchronizationRequested>(new NewSynchronizationRequested(profileSyncOptions, SynchronizationSource.Client));
var profileSynchronizationResponse = await WinoServerConnectionManager.GetResponseAsync<SynchronizationResult, NewSynchronizationRequested>(new NewSynchronizationRequested(profileSyncOptions, SynchronizationSource.Client));
var profileSynchronizationResult = profileSynchronizationResponse.Data;
@@ -235,7 +172,7 @@ namespace Wino.Mail.ViewModels
createdAccount.SenderName = profileSynchronizationResult.ProfileInformation.SenderName;
createdAccount.Base64ProfilePictureData = profileSynchronizationResult.ProfileInformation.Base64ProfilePictureData;
await _accountService.UpdateProfileInformationAsync(createdAccount.Id, profileSynchronizationResult.ProfileInformation);
await AccountService.UpdateProfileInformationAsync(createdAccount.Id, profileSynchronizationResult.ProfileInformation);
}
if (creationDialog is ICustomServerAccountCreationDialog customServerAccountCreationDialog)
@@ -250,7 +187,7 @@ namespace Wino.Mail.ViewModels
Type = SynchronizationType.FoldersOnly
};
var folderSynchronizationResponse = await _winoServerConnectionManager.GetResponseAsync<SynchronizationResult, NewSynchronizationRequested>(new NewSynchronizationRequested(folderSyncOptions, SynchronizationSource.Client));
var folderSynchronizationResponse = await WinoServerConnectionManager.GetResponseAsync<SynchronizationResult, NewSynchronizationRequested>(new NewSynchronizationRequested(folderSyncOptions, SynchronizationSource.Client));
var folderSynchronizationResult = folderSynchronizationResponse.Data;
@@ -268,7 +205,7 @@ namespace Wino.Mail.ViewModels
Type = SynchronizationType.Alias
};
var aliasSyncResponse = await _winoServerConnectionManager.GetResponseAsync<SynchronizationResult, NewSynchronizationRequested>(new NewSynchronizationRequested(aliasSyncOptions, SynchronizationSource.Client));
var aliasSyncResponse = await WinoServerConnectionManager.GetResponseAsync<SynchronizationResult, NewSynchronizationRequested>(new NewSynchronizationRequested(aliasSyncOptions, SynchronizationSource.Client));
var aliasSynchronizationResult = folderSynchronizationResponse.Data;
if (aliasSynchronizationResult.CompletedState != SynchronizationCompletedState.Success)
@@ -279,7 +216,7 @@ namespace Wino.Mail.ViewModels
// Create root primary alias for the account.
// This is only available for accounts that do not support alias synchronization.
await _accountService.CreateRootAliasAsync(createdAccount.Id, createdAccount.Address);
await AccountService.CreateRootAliasAsync(createdAccount.Id, createdAccount.Address);
}
// TODO: Temporary disabled. Is this even needed? Users can configure special folders manually later on if discovery fails.
@@ -294,7 +231,7 @@ namespace Wino.Mail.ViewModels
ReportUIChange(new AccountCreatedMessage(createdAccount));
// Notify success.
_dialogService.InfoBarMessage(Translator.Info_AccountCreatedTitle, string.Format(Translator.Info_AccountCreatedMessage, createdAccount.Address), InfoBarMessageType.Success);
DialogService.InfoBarMessage(Translator.Info_AccountCreatedTitle, string.Format(Translator.Info_AccountCreatedMessage, createdAccount.Address), InfoBarMessageType.Success);
}
}
catch (AccountSetupCanceledException)
@@ -310,12 +247,12 @@ namespace Wino.Mail.ViewModels
Log.Error(ex, WinoErrors.AccountCreation);
Crashes.TrackError(ex);
_dialogService.InfoBarMessage(Translator.Info_AccountCreationFailedTitle, ex.Message, InfoBarMessageType.Error);
DialogService.InfoBarMessage(Translator.Info_AccountCreationFailedTitle, ex.Message, InfoBarMessageType.Error);
// Delete account in case of failure.
if (createdAccount != null)
{
await _accountService.DeleteAccountAsync(createdAccount);
await AccountService.DeleteAccountAsync(createdAccount);
}
}
finally
@@ -333,7 +270,7 @@ namespace Wino.Mail.ViewModels
}
[RelayCommand(CanExecute = nameof(CanReorderAccounts))]
private Task ReorderAccountsAsync() => DialogService.ShowAccountReorderDialogAsync(availableAccounts: Accounts);
private Task ReorderAccountsAsync() => MailDialogService.ShowAccountReorderDialogAsync(availableAccounts: Accounts);
public override void OnNavigatedFrom(NavigationMode mode, object parameters)
{
@@ -357,7 +294,7 @@ namespace Wino.Mail.ViewModels
{
if (e.PropertyName == nameof(StartupAccount) && StartupAccount != null)
{
_preferencesService.StartupEntityId = StartupAccount.StartupEntityId;
PreferencesService.StartupEntityId = StartupAccount.StartupEntityId;
}
}
@@ -374,13 +311,13 @@ namespace Wino.Mail.ViewModels
PropertyChanged += PagePropertyChanged;
}
private async Task InitializeAccountsAsync()
public override async Task InitializeAccountsAsync()
{
StartupAccount = null;
Accounts.Clear();
var accounts = await _accountService.GetAccountsAsync().ConfigureAwait(false);
var accounts = await AccountService.GetAccountsAsync().ConfigureAwait(false);
// Group accounts and display merged ones at the top.
var groupedAccounts = accounts.GroupBy(a => a.MergedInboxId);
@@ -412,40 +349,14 @@ namespace Wino.Mail.ViewModels
}
// Handle startup entity.
if (_preferencesService.StartupEntityId != null)
if (PreferencesService.StartupEntityId != null)
{
StartupAccount = Accounts.FirstOrDefault(a => a.StartupEntityId == _preferencesService.StartupEntityId);
StartupAccount = Accounts.FirstOrDefault(a => a.StartupEntityId == PreferencesService.StartupEntityId);
}
});
await ManageStorePurchasesAsync().ConfigureAwait(false);
}
private async Task ManageStorePurchasesAsync()
{
await ExecuteUIThread(async () =>
{
HasUnlimitedAccountProduct = await _storeManagementService.HasProductAsync(StoreProductType.UnlimitedAccounts);
if (!HasUnlimitedAccountProduct)
IsAccountCreationBlocked = Accounts.Sum(a => a.HoldingAccountCount) >= FREE_ACCOUNT_COUNT;
else
IsAccountCreationBlocked = false;
});
}
private AccountProviderDetailViewModel GetAccountProviderDetails(MailAccount account)
{
var provider = _providerService.GetProviderDetail(account.ProviderType);
return new AccountProviderDetailViewModel(provider, account);
}
public async void Receive(ProtocolAuthorizationCallbackReceived message)
{
// Authorization must be completed in the server.
await _winoServerConnectionManager.GetResponseAsync<bool, ProtocolAuthorizationCallbackReceived>(message);
}
}
}

View File

@@ -6,7 +6,8 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using EmailValidation;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Navigation;
@@ -15,10 +16,12 @@ using Wino.Messaging.Server;
namespace Wino.Mail.ViewModels
{
public partial class AliasManagementPageViewModel : BaseViewModel
public partial class AliasManagementPageViewModel : MailBaseViewModel
{
private readonly IMailDialogService _dialogService;
private readonly IAccountService _accountService;
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CanSynchronizeAliases))]
private MailAccount account;
@@ -28,10 +31,11 @@ namespace Wino.Mail.ViewModels
public bool CanSynchronizeAliases => Account?.IsAliasSyncSupported ?? false;
public AliasManagementPageViewModel(IDialogService dialogService,
public AliasManagementPageViewModel(IMailDialogService dialogService,
IAccountService accountService,
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
IWinoServerConnectionManager winoServerConnectionManager)
{
_dialogService = dialogService;
_accountService = accountService;
_winoServerConnectionManager = winoServerConnectionManager;
}
@@ -83,13 +87,13 @@ namespace Wino.Mail.ViewModels
if (aliasSyncResponse.IsSuccess)
await LoadAliasesAsync();
else
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, aliasSyncResponse.Message, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, aliasSyncResponse.Message, InfoBarMessageType.Error);
}
[RelayCommand]
private async Task AddNewAliasAsync()
{
var createdAliasDialog = await DialogService.ShowCreateAccountAliasDialogAsync();
var createdAliasDialog = await _dialogService.ShowCreateAccountAliasDialogAsync();
if (createdAliasDialog.CreatedAccountAlias == null) return;
@@ -98,7 +102,7 @@ namespace Wino.Mail.ViewModels
// Check existence.
if (AccountAliases.Any(a => a.AliasAddress == newAlias.AliasAddress))
{
await DialogService.ShowMessageAsync(Translator.DialogMessage_AliasExistsTitle,
await _dialogService.ShowMessageAsync(Translator.DialogMessage_AliasExistsTitle,
Translator.DialogMessage_AliasExistsMessage,
WinoCustomMessageDialogIcon.Warning);
return;
@@ -107,7 +111,7 @@ namespace Wino.Mail.ViewModels
// Validate all addresses.
if (!EmailValidator.Validate(newAlias.AliasAddress) || (!string.IsNullOrEmpty(newAlias.ReplyToAddress) && !EmailValidator.Validate(newAlias.ReplyToAddress)))
{
await DialogService.ShowMessageAsync(Translator.DialogMessage_InvalidAliasMessage,
await _dialogService.ShowMessageAsync(Translator.DialogMessage_InvalidAliasMessage,
Translator.DialogMessage_InvalidAliasTitle,
WinoCustomMessageDialogIcon.Warning);
return;
@@ -118,7 +122,7 @@ namespace Wino.Mail.ViewModels
AccountAliases.Add(newAlias);
await _accountService.UpdateAccountAliasesAsync(Account.Id, AccountAliases);
DialogService.InfoBarMessage(Translator.DialogMessage_AliasCreatedTitle, Translator.DialogMessage_AliasCreatedMessage, InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.DialogMessage_AliasCreatedTitle, Translator.DialogMessage_AliasCreatedMessage, InfoBarMessageType.Success);
await LoadAliasesAsync();
}
@@ -129,7 +133,7 @@ namespace Wino.Mail.ViewModels
// Primary aliases can't be deleted.
if (alias.IsPrimary)
{
await DialogService.ShowMessageAsync(Translator.Info_CantDeletePrimaryAliasMessage,
await _dialogService.ShowMessageAsync(Translator.Info_CantDeletePrimaryAliasMessage,
Translator.GeneralTitle_Warning,
WinoCustomMessageDialogIcon.Warning);
return;
@@ -138,7 +142,7 @@ namespace Wino.Mail.ViewModels
// Root aliases can't be deleted.
if (alias.IsRootAlias)
{
await DialogService.ShowMessageAsync(Translator.DialogMessage_CantDeleteRootAliasTitle,
await _dialogService.ShowMessageAsync(Translator.DialogMessage_CantDeleteRootAliasTitle,
Translator.DialogMessage_CantDeleteRootAliasMessage,
WinoCustomMessageDialogIcon.Warning);
return;

View File

@@ -11,7 +11,7 @@ using Wino.Messaging.Server;
namespace Wino.Mail.ViewModels
{
public partial class AppPreferencesPageViewModel : BaseViewModel
public partial class AppPreferencesPageViewModel : MailBaseViewModel
{
public IPreferencesService PreferencesService { get; }
@@ -38,14 +38,16 @@ namespace Wino.Mail.ViewModels
}
}
private readonly IMailDialogService _dialogService;
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
private readonly IStartupBehaviorService _startupBehaviorService;
public AppPreferencesPageViewModel(IDialogService dialogService,
public AppPreferencesPageViewModel(IMailDialogService dialogService,
IPreferencesService preferencesService,
IWinoServerConnectionManager winoServerConnectionManager,
IStartupBehaviorService startupBehaviorService) : base(dialogService)
IStartupBehaviorService startupBehaviorService)
{
_dialogService = dialogService;
PreferencesService = preferencesService;
_winoServerConnectionManager = winoServerConnectionManager;
_startupBehaviorService = startupBehaviorService;
@@ -95,23 +97,23 @@ namespace Wino.Mail.ViewModels
{
if (StartupBehaviorResult == StartupBehaviorResult.Enabled)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Enabled, InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Enabled, InfoBarMessageType.Success);
}
else if (StartupBehaviorResult == StartupBehaviorResult.Disabled)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Disabled, InfoBarMessageType.Warning);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Disabled, InfoBarMessageType.Warning);
}
else if (StartupBehaviorResult == StartupBehaviorResult.DisabledByPolicy)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByPolicy, InfoBarMessageType.Warning);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByPolicy, InfoBarMessageType.Warning);
}
else if (StartupBehaviorResult == StartupBehaviorResult.DisabledByUser)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByUser, InfoBarMessageType.Warning);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByUser, InfoBarMessageType.Warning);
}
else
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, Translator.SettingsAppPreferences_StartupBehavior_FatalError, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, Translator.SettingsAppPreferences_StartupBehavior_FatalError, InfoBarMessageType.Error);
}
}
@@ -125,7 +127,7 @@ namespace Wino.Mail.ViewModels
if (!terminationModeChangedResult.IsSuccess)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, terminationModeChangedResult.Message, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, terminationModeChangedResult.Message, InfoBarMessageType.Error);
}
}
}

View File

@@ -12,7 +12,8 @@ using MoreLinq.Extensions;
using Serilog;
using Wino.Core;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Folders;
@@ -29,8 +30,8 @@ using Wino.Messaging.UI;
namespace Wino.Mail.ViewModels
{
public partial class AppShellViewModel : BaseViewModel,
IRecipient<NavigateSettingsRequested>,
public partial class AppShellViewModel : MailBaseViewModel,
IRecipient<NavigateManageAccountsRequested>,
IRecipient<MailtoProtocolMessageRequested>,
IRecipient<RefreshUnreadCountsMessage>,
IRecipient<AccountsMenuRefreshRequested>,
@@ -52,9 +53,6 @@ namespace Wino.Mail.ViewModels
public MenuItemCollection MenuItems { get; set; }
private readonly SettingsItem SettingsItem = new SettingsItem();
private readonly RateMenuItem RatingItem = new RateMenuItem();
private readonly ManageAccountsMenuItem ManageAccountsMenuItem = new ManageAccountsMenuItem();
public NewMailMenuItem CreateMailMenuItem = new NewMailMenuItem();
@@ -66,7 +64,7 @@ namespace Wino.Mail.ViewModels
public IStatePersistanceService StatePersistenceService { get; }
public IWinoServerConnectionManager ServerConnectionManager { get; }
public IPreferencesService PreferencesService { get; }
public IWinoNavigationService NavigationService { get; }
public INavigationService NavigationService { get; }
private readonly IFolderService _folderService;
private readonly IConfigurationService _configurationService;
@@ -77,7 +75,7 @@ namespace Wino.Mail.ViewModels
private readonly ILaunchProtocolService _launchProtocolService;
private readonly INotificationBuilder _notificationBuilder;
private readonly IWinoRequestDelegator _winoRequestDelegator;
private readonly IMailDialogService _dialogService;
private readonly IBackgroundTaskService _backgroundTaskService;
private readonly IMimeFileService _mimeFileService;
@@ -89,8 +87,8 @@ namespace Wino.Mail.ViewModels
[ObservableProperty]
private WinoServerConnectionStatus activeConnectionStatus;
public AppShellViewModel(IDialogService dialogService,
IWinoNavigationService navigationService,
public AppShellViewModel(IMailDialogService dialogService,
INavigationService navigationService,
IBackgroundTaskService backgroundTaskService,
IMimeFileService mimeFileService,
INativeAppService nativeAppService,
@@ -106,7 +104,7 @@ namespace Wino.Mail.ViewModels
IStatePersistanceService statePersistanceService,
IWinoServerConnectionManager serverConnectionManager,
IConfigurationService configurationService,
IStartupBehaviorService startupBehaviorService) : base(dialogService)
IStartupBehaviorService startupBehaviorService)
{
StatePersistenceService = statePersistanceService;
ServerConnectionManager = serverConnectionManager;
@@ -121,6 +119,7 @@ namespace Wino.Mail.ViewModels
};
PreferencesService = preferencesService;
_dialogService = dialogService;
NavigationService = navigationService;
_configurationService = configurationService;
@@ -263,7 +262,7 @@ namespace Wino.Mail.ViewModels
return;
}
bool isAccepted = await DialogService.ShowWinoCustomMessageDialogAsync(Translator.DialogMessage_EnableStartupLaunchTitle,
bool isAccepted = await _dialogService.ShowWinoCustomMessageDialogAsync(Translator.DialogMessage_EnableStartupLaunchTitle,
Translator.DialogMessage_EnableStartupLaunchMessage,
Translator.Buttons_Yes,
WinoCustomMessageDialogIcon.Information,
@@ -280,7 +279,7 @@ namespace Wino.Mail.ViewModels
if (shouldDisplayLaterOnMessage)
{
await DialogService.ShowWinoCustomMessageDialogAsync(Translator.DialogMessage_EnableStartupLaunchTitle,
await _dialogService.ShowWinoCustomMessageDialogAsync(Translator.DialogMessage_EnableStartupLaunchTitle,
Translator.DialogMessage_EnableStartupLaunchDeniedMessage,
Translator.Buttons_Close,
WinoCustomMessageDialogIcon.Information);
@@ -303,7 +302,7 @@ namespace Wino.Mail.ViewModels
{
Crashes.TrackError(ex);
DialogService.InfoBarMessage(Translator.Info_BackgroundExecutionUnknownErrorTitle, Translator.Info_BackgroundExecutionUnknownErrorMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_BackgroundExecutionUnknownErrorTitle, Translator.Info_BackgroundExecutionUnknownErrorMessage, InfoBarMessageType.Error);
}
}
@@ -421,11 +420,11 @@ namespace Wino.Mail.ViewModels
SelectedMenuItem = baseFolderMenuItem;
baseFolderMenuItem.IsSelected = true;
if (folderInitAwaitTask == null) folderInitAwaitTask = new TaskCompletionSource<bool>();
folderInitAwaitTask ??= new TaskCompletionSource<bool>();
var args = new NavigateMailFolderEventArgs(baseFolderMenuItem, folderInitAwaitTask);
NavigationService.NavigateFolder(args);
NavigationService.Navigate(WinoPage.MailListPage, args, NavigationReferenceFrame.ShellFrame);
UpdateWindowTitleForFolder(baseFolderMenuItem);
});
@@ -535,7 +534,7 @@ namespace Wino.Mail.ViewModels
// Ask confirmation for cleaning up the folder.
if (operation == FolderOperation.Empty)
{
var result = await DialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_CleanupFolderMessage, Translator.DialogMessage_CleanupFolderTitle, Translator.Buttons_Yes);
var result = await _dialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_CleanupFolderMessage, Translator.DialogMessage_CleanupFolderTitle, Translator.Buttons_Yes);
if (!result) return;
}
@@ -567,15 +566,15 @@ namespace Wino.Mail.ViewModels
if (account.AttentionReason == AccountAttentionReason.InvalidCredentials)
await _accountService.FixTokenIssuesAsync(account.Id);
else if (account.AttentionReason == AccountAttentionReason.MissingSystemFolderConfiguration)
await DialogService.HandleSystemFolderConfigurationDialogAsync(account.Id, _folderService);
await _dialogService.HandleSystemFolderConfigurationDialogAsync(account.Id, _folderService);
await _accountService.ClearAccountAttentionAsync(account.Id);
DialogService.InfoBarMessage(Translator.Info_AccountIssueFixFailedTitle, Translator.Info_AccountIssueFixSuccessMessage, InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.Info_AccountIssueFixFailedTitle, Translator.Info_AccountIssueFixSuccessMessage, InfoBarMessageType.Success);
}
catch (Exception ex)
{
DialogService.InfoBarMessage(Translator.Info_AccountIssueFixFailedTitle, ex.Message, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_AccountIssueFixFailedTitle, ex.Message, InfoBarMessageType.Error);
}
}
@@ -781,7 +780,7 @@ namespace Wino.Mail.ViewModels
if (!accounts.Any())
{
var isManageAccountClicked = await DialogService.ShowWinoCustomMessageDialogAsync(Translator.DialogMessage_NoAccountsForCreateMailTitle,
var isManageAccountClicked = await _dialogService.ShowWinoCustomMessageDialogAsync(Translator.DialogMessage_NoAccountsForCreateMailTitle,
Translator.DialogMessage_NoAccountsForCreateMailMessage,
Translator.MenuManageAccounts,
WinoCustomMessageDialogIcon.Information,
@@ -837,13 +836,13 @@ namespace Wino.Mail.ViewModels
if (draftFolder == null)
{
DialogService.InfoBarMessage(Translator.Info_DraftFolderMissingTitle,
_dialogService.InfoBarMessage(Translator.Info_DraftFolderMissingTitle,
Translator.Info_DraftFolderMissingMessage,
InfoBarMessageType.Error,
Translator.SettingConfigureSpecialFolders_Button,
() =>
{
DialogService.HandleSystemFolderConfigurationDialogAsync(account.Id, _folderService);
_dialogService.HandleSystemFolderConfigurationDialogAsync(account.Id, _folderService);
});
return;
}
@@ -919,7 +918,7 @@ namespace Wino.Mail.ViewModels
accountMenuItem.UpdateAccount(accountModel);
}
public void Receive(NavigateSettingsRequested message) => SelectedMenuItem = ManageAccountsMenuItem;
public void Receive(NavigateManageAccountsRequested message) => SelectedMenuItem = ManageAccountsMenuItem;
public async void Receive(MailtoProtocolMessageRequested message)
{
@@ -929,7 +928,7 @@ namespace Wino.Mail.ViewModels
if (!accounts.Any())
{
await DialogService.ShowMessageAsync(Translator.DialogMessage_NoAccountsForCreateMailMessage,
await _dialogService.ShowMessageAsync(Translator.DialogMessage_NoAccountsForCreateMailMessage,
Translator.DialogMessage_NoAccountsForCreateMailTitle,
WinoCustomMessageDialogIcon.Warning);
}
@@ -941,7 +940,7 @@ namespace Wino.Mail.ViewModels
{
// User must pick an account.
targetAccount = await DialogService.ShowAccountPickerDialogAsync(accounts);
targetAccount = await _dialogService.ShowAccountPickerDialogAsync(accounts);
}
if (targetAccount == null) return;

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Collections;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Comparers;

View File

@@ -9,7 +9,8 @@ using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using MimeKit;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Exceptions;
using Wino.Core.Domain.Interfaces;
@@ -23,7 +24,7 @@ using Wino.Messaging.Server;
namespace Wino.Mail.ViewModels
{
public partial class ComposePageViewModel : BaseViewModel
public partial class ComposePageViewModel : MailBaseViewModel
{
public Func<Task<string>> GetHTMLBodyFunction;
@@ -92,6 +93,7 @@ namespace Wino.Mail.ViewModels
public INativeAppService NativeAppService { get; }
private readonly IMailDialogService _dialogService;
private readonly IMailService _mailService;
private readonly IMimeFileService _mimeFileService;
private readonly IFolderService _folderService;
@@ -102,7 +104,7 @@ namespace Wino.Mail.ViewModels
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
public readonly IContactService ContactService;
public ComposePageViewModel(IDialogService dialogService,
public ComposePageViewModel(IMailDialogService dialogService,
IMailService mailService,
IMimeFileService mimeFileService,
INativeAppService nativeAppService,
@@ -112,7 +114,7 @@ namespace Wino.Mail.ViewModels
IContactService contactService,
IFontService fontService,
IPreferencesService preferencesService,
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
IWinoServerConnectionManager winoServerConnectionManager)
{
NativeAppService = nativeAppService;
ContactService = contactService;
@@ -120,6 +122,7 @@ namespace Wino.Mail.ViewModels
PreferencesService = preferencesService;
_folderService = folderService;
_dialogService = dialogService;
_mailService = mailService;
_mimeFileService = mimeFileService;
_accountService = accountService;
@@ -138,7 +141,7 @@ namespace Wino.Mail.ViewModels
if (!ToItems.Any())
{
await DialogService.ShowMessageAsync(Translator.DialogMessage_ComposerMissingRecipientMessage,
await _dialogService.ShowMessageAsync(Translator.DialogMessage_ComposerMissingRecipientMessage,
Translator.DialogMessage_ComposerValidationFailedTitle,
WinoCustomMessageDialogIcon.Warning);
return;
@@ -146,14 +149,14 @@ namespace Wino.Mail.ViewModels
if (string.IsNullOrEmpty(Subject))
{
var isConfirmed = await DialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_EmptySubjectConfirmationMessage, Translator.DialogMessage_EmptySubjectConfirmation, Translator.Buttons_Yes);
var isConfirmed = await _dialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_EmptySubjectConfirmationMessage, Translator.DialogMessage_EmptySubjectConfirmation, Translator.Buttons_Yes);
if (!isConfirmed) return;
}
if (SelectedAlias == null)
{
DialogService.InfoBarMessage(Translator.DialogMessage_AliasNotSelectedTitle, Translator.DialogMessage_AliasNotSelectedMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.DialogMessage_AliasNotSelectedTitle, Translator.DialogMessage_AliasNotSelectedMessage, InfoBarMessageType.Error);
return;
}
@@ -255,11 +258,11 @@ namespace Wino.Mail.ViewModels
{
if (ComposingAccount == null)
{
DialogService.InfoBarMessage(Translator.Info_MessageCorruptedTitle, Translator.Info_MessageCorruptedMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_MessageCorruptedTitle, Translator.Info_MessageCorruptedMessage, InfoBarMessageType.Error);
return;
}
var confirmation = await DialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_DiscardDraftConfirmationMessage,
var confirmation = await _dialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_DiscardDraftConfirmationMessage,
Translator.DialogMessage_DiscardDraftConfirmationTitle,
Translator.Buttons_Yes);
@@ -369,17 +372,17 @@ namespace Wino.Mail.ViewModels
}
}
else
DialogService.InfoBarMessage(Translator.Info_ComposerMissingMIMETitle, Translator.Info_ComposerMissingMIMEMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_ComposerMissingMIMETitle, Translator.Info_ComposerMissingMIMEMessage, InfoBarMessageType.Error);
return;
}
catch (IOException)
{
DialogService.InfoBarMessage(Translator.Busy, Translator.Exception_MailProcessing, InfoBarMessageType.Warning);
_dialogService.InfoBarMessage(Translator.Busy, Translator.Exception_MailProcessing, InfoBarMessageType.Warning);
}
catch (ComposerMimeNotFoundException)
{
DialogService.InfoBarMessage(Translator.Info_ComposerMissingMIMETitle, Translator.Info_ComposerMissingMIMEMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_ComposerMissingMIMETitle, Translator.Info_ComposerMissingMIMEMessage, InfoBarMessageType.Error);
}
if (mimeMessageInformation == null)
@@ -494,12 +497,12 @@ namespace Wino.Mail.ViewModels
public void NotifyAddressExists()
{
DialogService.InfoBarMessage(Translator.Info_ContactExistsTitle, Translator.Info_ContactExistsMessage, InfoBarMessageType.Warning);
_dialogService.InfoBarMessage(Translator.Info_ContactExistsTitle, Translator.Info_ContactExistsMessage, InfoBarMessageType.Warning);
}
public void NotifyInvalidEmail(string address)
{
DialogService.InfoBarMessage(Translator.Info_InvalidAddressTitle, string.Format(Translator.Info_InvalidAddressMessage, address), InfoBarMessageType.Warning);
_dialogService.InfoBarMessage(Translator.Info_InvalidAddressTitle, string.Format(Translator.Info_InvalidAddressMessage, address), InfoBarMessageType.Warning);
}
protected override async void OnMailUpdated(MailCopy updatedMail)

View File

@@ -1,34 +0,0 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels.Data
{
public partial class AccountProviderDetailViewModel : ObservableObject, IAccountProviderDetailViewModel
{
[ObservableProperty]
private MailAccount account;
public IProviderDetail ProviderDetail { get; set; }
public Guid StartupEntityId => Account.Id;
public string StartupEntityTitle => Account.Name;
public int Order => Account.Order;
public string StartupEntityAddresses => Account.Address;
public int HoldingAccountCount => 1;
public bool HasProfilePicture => !string.IsNullOrEmpty(Account.Base64ProfilePictureData);
public AccountProviderDetailViewModel(IProviderDetail providerDetail, MailAccount account)
{
ProviderDetail = providerDetail;
Account = account;
}
}
}

View File

@@ -1,23 +0,0 @@
using CommunityToolkit.Mvvm.ComponentModel;
namespace Wino.Mail.ViewModels.Data
{
public class AppColorViewModel : ObservableObject
{
private string _hex;
public string Hex
{
get => _hex;
set => SetProperty(ref _hex, value);
}
public bool IsAccentColor { get; }
public AppColorViewModel(string hex, bool isAccentColor = false)
{
IsAccentColor = isAccentColor;
Hex = hex;
}
}
}

View File

@@ -1,23 +0,0 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Messaging.Client.Navigation;
namespace Wino.Mail.ViewModels.Data
{
public partial class BreadcrumbNavigationItemViewModel : ObservableObject
{
[ObservableProperty]
private string title;
[ObservableProperty]
private bool isActive;
public BreadcrumbNavigationRequested Request { get; set; }
public BreadcrumbNavigationItemViewModel(BreadcrumbNavigationRequested request, bool isActive)
{
Request = request;
Title = request.PageTitle;
IsActive = isActive;
}
}
}

View File

@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Models.MailItem;
namespace Wino.Mail.ViewModels.Data

View File

@@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels.Data
{
public partial class MergedAccountProviderDetailViewModel : ObservableObject, IAccountProviderDetailViewModel
{
public List<AccountProviderDetailViewModel> HoldingAccounts { get; }
public MergedInbox MergedInbox { get; }
public string AccountAddresses => string.Join(", ", HoldingAccounts.Select(a => a.Account.Address));
public Guid StartupEntityId => MergedInbox.Id;
public string StartupEntityTitle => MergedInbox.Name;
public int Order => 0;
public IProviderDetail ProviderDetail { get; set; }
public string StartupEntityAddresses => AccountAddresses;
public int HoldingAccountCount => HoldingAccounts.Count;
public MergedAccountProviderDetailViewModel(MergedInbox mergedInbox, List<AccountProviderDetailViewModel> holdingAccounts)
{
MergedInbox = mergedInbox;
HoldingAccounts = holdingAccounts;
}
}
}

View File

@@ -4,7 +4,8 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Models.MailItem;
namespace Wino.Mail.ViewModels.Data

View File

@@ -1,9 +1,10 @@
using Wino.Core.Domain.Interfaces;
using Wino.Core.ViewModels;
namespace Wino.Mail.ViewModels
{
public partial class IdlePageViewModel : BaseViewModel
public partial class IdlePageViewModel : CoreBaseViewModel
{
public IdlePageViewModel(IDialogService dialogService) : base(dialogService) { }
public IdlePageViewModel(IMailDialogService dialogService) { }
}
}

View File

@@ -8,9 +8,7 @@ using Wino.Core.Domain.Models.Translations;
namespace Wino.Mail.ViewModels
{
public partial class LanguageTimePageViewModel(IDialogService dialogService,
IPreferencesService preferencesService,
ITranslationService translationService) : BaseViewModel(dialogService)
public partial class LanguageTimePageViewModel(IPreferencesService preferencesService, ITranslationService translationService) : MailBaseViewModel
{
public IPreferencesService PreferencesService { get; } = preferencesService;
private readonly ITranslationService _translationService = translationService;

View File

@@ -1,20 +1,13 @@
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Interfaces;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Models.Folders;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.ViewModels;
using Wino.Messaging.UI;
namespace Wino.Mail.ViewModels
{
public class BaseViewModel : ObservableRecipient,
INavigationAware,
IRecipient<AccountCreatedMessage>,
IRecipient<AccountRemovedMessage>,
IRecipient<AccountUpdatedMessage>,
public class MailBaseViewModel : CoreBaseViewModel,
IRecipient<MailAddedMessage>,
IRecipient<MailRemovedMessage>,
IRecipient<MailUpdatedMessage>,
@@ -25,58 +18,16 @@ namespace Wino.Mail.ViewModels
IRecipient<FolderRenamed>,
IRecipient<FolderSynchronizationEnabled>
{
private IDispatcher _dispatcher;
public IDispatcher Dispatcher
{
get
{
return _dispatcher;
}
set
{
_dispatcher = value;
if (value != null)
{
OnDispatcherAssigned();
}
}
}
protected IDialogService DialogService { get; }
public BaseViewModel(IDialogService dialogService) => DialogService = dialogService ?? throw new ArgumentNullException(nameof(dialogService));
public async Task ExecuteUIThread(Action action) => await Dispatcher?.ExecuteOnUIThread(action);
public virtual void OnNavigatedTo(NavigationMode mode, object parameters) { IsActive = true; }
public virtual void OnNavigatedFrom(NavigationMode mode, object parameters) { IsActive = false; }
protected virtual void OnDispatcherAssigned() { }
protected virtual void OnMailAdded(MailCopy addedMail) { }
protected virtual void OnMailRemoved(MailCopy removedMail) { }
protected virtual void OnMailUpdated(MailCopy updatedMail) { }
protected virtual void OnMailDownloaded(MailCopy downloadedMail) { }
protected virtual void OnAccountCreated(MailAccount createdAccount) { }
protected virtual void OnAccountRemoved(MailAccount removedAccount) { }
protected virtual void OnAccountUpdated(MailAccount updatedAccount) { }
protected virtual void OnDraftCreated(MailCopy draftMail, MailAccount account) { }
protected virtual void OnDraftFailed(MailCopy draftMail, MailAccount account) { }
protected virtual void OnDraftMapped(string localDraftCopyId, string remoteDraftCopyId) { }
protected virtual void OnFolderRenamed(IMailItemFolder mailItemFolder) { }
protected virtual void OnFolderSynchronizationEnabled(IMailItemFolder mailItemFolder) { }
public void ReportUIChange<TMessage>(TMessage message) where TMessage : class, IUIMessage => Messenger.Send(message);
void IRecipient<AccountCreatedMessage>.Receive(AccountCreatedMessage message) => OnAccountCreated(message.Account);
void IRecipient<AccountRemovedMessage>.Receive(AccountRemovedMessage message) => OnAccountRemoved(message.Account);
void IRecipient<AccountUpdatedMessage>.Receive(AccountUpdatedMessage message) => OnAccountUpdated(message.Account);
void IRecipient<MailAddedMessage>.Receive(MailAddedMessage message) => OnMailAdded(message.AddedMail);
void IRecipient<MailRemovedMessage>.Receive(MailRemovedMessage message) => OnMailRemoved(message.RemovedMail);
void IRecipient<MailUpdatedMessage>.Receive(MailUpdatedMessage message) => OnMailUpdated(message.UpdatedMail);

View File

@@ -16,7 +16,8 @@ using Nito.AsyncEx;
using Serilog;
using Wino.Core;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Folders;
@@ -33,7 +34,7 @@ using Wino.Messaging.UI;
namespace Wino.Mail.ViewModels
{
public partial class MailListPageViewModel : BaseViewModel,
public partial class MailListPageViewModel : MailBaseViewModel,
IRecipient<MailItemNavigationRequested>,
IRecipient<ActiveMailFolderChangedEvent>,
IRecipient<MailItemSelectedEvent>,
@@ -66,7 +67,7 @@ namespace Wino.Mail.ViewModels
private readonly SemaphoreSlim listManipulationSemepahore = new SemaphoreSlim(1);
private CancellationTokenSource listManipulationCancellationTokenSource = new CancellationTokenSource();
public IWinoNavigationService NavigationService { get; }
public INavigationService NavigationService { get; }
public IStatePersistanceService StatePersistenceService { get; }
public IPreferencesService PreferencesService { get; }
@@ -143,8 +144,8 @@ namespace Wino.Mail.ViewModels
[NotifyPropertyChangedFor(nameof(CanSynchronize))]
private bool isAccountSynchronizerInSynchronization;
public MailListPageViewModel(IDialogService dialogService,
IWinoNavigationService navigationService,
public MailListPageViewModel(IMailDialogService dialogService,
INavigationService navigationService,
IMailService mailService,
IStatePersistanceService statePersistenceService,
IFolderService folderService,
@@ -153,7 +154,7 @@ namespace Wino.Mail.ViewModels
IWinoRequestDelegator winoRequestDelegator,
IKeyPressService keyPressService,
IPreferencesService preferencesService,
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
IWinoServerConnectionManager winoServerConnectionManager)
{
PreferencesService = preferencesService;
_winoServerConnectionManager = winoServerConnectionManager;

View File

@@ -14,7 +14,8 @@ using MimeKit;
using Serilog;
using Wino.Core;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.MailItem;
@@ -30,10 +31,11 @@ using IMailService = Wino.Core.Domain.Interfaces.IMailService;
namespace Wino.Mail.ViewModels
{
public partial class MailRenderingPageViewModel : BaseViewModel,
public partial class MailRenderingPageViewModel : MailBaseViewModel,
IRecipient<NewMailItemRenderingRequestedEvent>,
ITransferProgress // For listening IMAP message download progress.
{
private readonly IMailDialogService _dialogService;
private readonly IUnderlyingThemeService _underlyingThemeService;
private readonly IMimeFileService _mimeFileService;
@@ -129,7 +131,7 @@ namespace Wino.Mail.ViewModels
public IPreferencesService PreferencesService { get; }
public IPrintService PrintService { get; }
public MailRenderingPageViewModel(IDialogService dialogService,
public MailRenderingPageViewModel(IMailDialogService dialogService,
INativeAppService nativeAppService,
IUnderlyingThemeService underlyingThemeService,
IMimeFileService mimeFileService,
@@ -143,8 +145,9 @@ namespace Wino.Mail.ViewModels
IPreferencesService preferencesService,
IPrintService printService,
IApplicationConfiguration applicationConfiguration,
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
IWinoServerConnectionManager winoServerConnectionManager)
{
_dialogService = dialogService;
NativeAppService = nativeAppService;
StatePersistenceService = statePersistenceService;
_contactService = contactService;
@@ -168,11 +171,11 @@ namespace Wino.Mail.ViewModels
{
await _clipboardService.CopyClipboardAsync(copyText);
DialogService.InfoBarMessage(Translator.ClipboardTextCopied_Title, string.Format(Translator.ClipboardTextCopied_Message, copyText), InfoBarMessageType.Information);
_dialogService.InfoBarMessage(Translator.ClipboardTextCopied_Title, string.Format(Translator.ClipboardTextCopied_Message, copyText), InfoBarMessageType.Information);
}
catch (Exception)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, string.Format(Translator.ClipboardTextCopyFailed_Message, copyText), InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, string.Format(Translator.ClipboardTextCopyFailed_Message, copyText), InfoBarMessageType.Error);
}
}
@@ -196,7 +199,7 @@ namespace Wino.Mail.ViewModels
{
if (!Uri.IsWellFormedUriString(CurrentRenderModel.UnsubscribeInfo.HttpLink, UriKind.RelativeOrAbsolute))
{
DialogService.InfoBarMessage(Translator.Info_UnsubscribeLinkInvalidTitle, Translator.Info_UnsubscribeLinkInvalidMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_UnsubscribeLinkInvalidTitle, Translator.Info_UnsubscribeLinkInvalidMessage, InfoBarMessageType.Error);
return;
}
@@ -204,23 +207,23 @@ namespace Wino.Mail.ViewModels
// https://datatracker.ietf.org/doc/html/rfc8058
if (CurrentRenderModel.UnsubscribeInfo.IsOneClick)
{
confirmed = await DialogService.ShowConfirmationDialogAsync(string.Format(Translator.DialogMessage_UnsubscribeConfirmationOneClickMessage, FromName), Translator.DialogMessage_UnsubscribeConfirmationTitle, Translator.Unsubscribe);
confirmed = await _dialogService.ShowConfirmationDialogAsync(string.Format(Translator.DialogMessage_UnsubscribeConfirmationOneClickMessage, FromName), Translator.DialogMessage_UnsubscribeConfirmationTitle, Translator.Unsubscribe);
if (!confirmed) return;
bool isOneClickUnsubscribed = await _unsubscriptionService.OneClickUnsubscribeAsync(CurrentRenderModel.UnsubscribeInfo);
if (isOneClickUnsubscribed)
{
DialogService.InfoBarMessage(Translator.Unsubscribe, string.Format(Translator.Info_UnsubscribeSuccessMessage, FromName), InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.Unsubscribe, string.Format(Translator.Info_UnsubscribeSuccessMessage, FromName), InfoBarMessageType.Success);
}
else
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, Translator.Info_UnsubscribeErrorMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, Translator.Info_UnsubscribeErrorMessage, InfoBarMessageType.Error);
}
}
else
{
confirmed = await DialogService.ShowConfirmationDialogAsync(string.Format(Translator.DialogMessage_UnsubscribeConfirmationGoToWebsiteMessage, FromName), Translator.DialogMessage_UnsubscribeConfirmationTitle, Translator.DialogMessage_UnsubscribeConfirmationGoToWebsiteConfirmButton);
confirmed = await _dialogService.ShowConfirmationDialogAsync(string.Format(Translator.DialogMessage_UnsubscribeConfirmationGoToWebsiteMessage, FromName), Translator.DialogMessage_UnsubscribeConfirmationTitle, Translator.DialogMessage_UnsubscribeConfirmationGoToWebsiteConfirmButton);
if (!confirmed) return;
await NativeAppService.LaunchUriAsync(new Uri(CurrentRenderModel.UnsubscribeInfo.HttpLink));
@@ -228,7 +231,7 @@ namespace Wino.Mail.ViewModels
}
else if (CurrentRenderModel.UnsubscribeInfo.MailToLink is not null)
{
confirmed = await DialogService.ShowConfirmationDialogAsync(string.Format(Translator.DialogMessage_UnsubscribeConfirmationMailtoMessage, FromName, new string(CurrentRenderModel.UnsubscribeInfo.MailToLink.Skip(7).ToArray())), Translator.DialogMessage_UnsubscribeConfirmationTitle, Translator.Unsubscribe);
confirmed = await _dialogService.ShowConfirmationDialogAsync(string.Format(Translator.DialogMessage_UnsubscribeConfirmationMailtoMessage, FromName, new string(CurrentRenderModel.UnsubscribeInfo.MailToLink.Skip(7).ToArray())), Translator.DialogMessage_UnsubscribeConfirmationTitle, Translator.Unsubscribe);
if (!confirmed) return;
@@ -337,7 +340,7 @@ namespace Wino.Mail.ViewModels
}
catch (Exception ex)
{
DialogService.InfoBarMessage(Translator.Info_MailRenderingFailedTitle, string.Format(Translator.Info_MailRenderingFailedMessage, ex.Message), InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_MailRenderingFailedTitle, string.Format(Translator.Info_MailRenderingFailedMessage, ex.Message), InfoBarMessageType.Error);
Crashes.TrackError(ex);
Log.Error(ex, "Render Failed");
@@ -360,7 +363,7 @@ namespace Wino.Mail.ViewModels
}
catch (Exception ex)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, ex.Message, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, ex.Message, InfoBarMessageType.Error);
}
finally
{
@@ -385,7 +388,7 @@ namespace Wino.Mail.ViewModels
if (mimeMessageInformation == null)
{
DialogService.InfoBarMessage(Translator.Info_MessageCorruptedTitle, Translator.Info_MessageCorruptedMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_MessageCorruptedTitle, Translator.Info_MessageCorruptedMessage, InfoBarMessageType.Error);
return;
}
@@ -608,7 +611,7 @@ namespace Wino.Mail.ViewModels
Log.Error(ex, WinoErrors.OpenAttachment);
Crashes.TrackError(ex);
DialogService.InfoBarMessage(Translator.Info_AttachmentOpenFailedTitle, Translator.Info_AttachmentOpenFailedMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_AttachmentOpenFailedTitle, Translator.Info_AttachmentOpenFailedMessage, InfoBarMessageType.Error);
}
}
@@ -622,20 +625,20 @@ namespace Wino.Mail.ViewModels
{
attachmentViewModel.IsBusy = true;
var pickedPath = await DialogService.PickWindowsFolderAsync();
var pickedPath = await _dialogService.PickWindowsFolderAsync();
if (string.IsNullOrEmpty(pickedPath)) return;
await SaveAttachmentInternalAsync(attachmentViewModel, pickedPath);
DialogService.InfoBarMessage(Translator.Info_AttachmentSaveSuccessTitle, Translator.Info_AttachmentSaveSuccessMessage, InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.Info_AttachmentSaveSuccessTitle, Translator.Info_AttachmentSaveSuccessMessage, InfoBarMessageType.Success);
}
catch (Exception ex)
{
Log.Error(ex, WinoErrors.SaveAttachment);
Crashes.TrackError(ex);
DialogService.InfoBarMessage(Translator.Info_AttachmentSaveFailedTitle, Translator.Info_AttachmentSaveFailedMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_AttachmentSaveFailedTitle, Translator.Info_AttachmentSaveFailedMessage, InfoBarMessageType.Error);
}
finally
{
@@ -646,7 +649,7 @@ namespace Wino.Mail.ViewModels
[RelayCommand]
private async Task SaveAllAttachmentsAsync()
{
var pickedPath = await DialogService.PickWindowsFolderAsync();
var pickedPath = await _dialogService.PickWindowsFolderAsync();
if (string.IsNullOrEmpty(pickedPath)) return;
@@ -658,14 +661,14 @@ namespace Wino.Mail.ViewModels
await SaveAttachmentInternalAsync(attachmentViewModel, pickedPath);
}
DialogService.InfoBarMessage(Translator.Info_AttachmentSaveSuccessTitle, Translator.Info_AttachmentSaveSuccessMessage, InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.Info_AttachmentSaveSuccessTitle, Translator.Info_AttachmentSaveSuccessMessage, InfoBarMessageType.Success);
}
catch (Exception ex)
{
Log.Error(ex, WinoErrors.SaveAttachment);
Crashes.TrackError(ex);
DialogService.InfoBarMessage(Translator.Info_AttachmentSaveFailedTitle, Translator.Info_AttachmentSaveFailedMessage, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_AttachmentSaveFailedTitle, Translator.Info_AttachmentSaveFailedMessage, InfoBarMessageType.Error);
}
}
@@ -688,17 +691,17 @@ namespace Wino.Mail.ViewModels
if (result == PrintingResult.Submitted)
{
DialogService.InfoBarMessage(Translator.DialogMessage_PrintingSuccessTitle, Translator.DialogMessage_PrintingSuccessMessage, InfoBarMessageType.Success);
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingSuccessTitle, Translator.DialogMessage_PrintingSuccessMessage, InfoBarMessageType.Success);
}
else
{
var message = string.Format(Translator.DialogMessage_PrintingFailedMessage, result);
DialogService.InfoBarMessage(Translator.DialogMessage_PrintingFailedTitle, message, InfoBarMessageType.Warning);
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingFailedTitle, message, InfoBarMessageType.Warning);
}
}
catch (Exception ex)
{
DialogService.InfoBarMessage(string.Empty, ex.Message, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(string.Empty, ex.Message, InfoBarMessageType.Error);
Crashes.TrackError(ex);
}
}
@@ -707,7 +710,7 @@ namespace Wino.Mail.ViewModels
{
try
{
var pickedFolder = await DialogService.PickWindowsFolderAsync();
var pickedFolder = await _dialogService.PickWindowsFolderAsync();
if (string.IsNullOrEmpty(pickedFolder)) return;
@@ -717,14 +720,14 @@ namespace Wino.Mail.ViewModels
if (isSaved)
{
DialogService.InfoBarMessage(Translator.Info_PDFSaveSuccessTitle,
_dialogService.InfoBarMessage(Translator.Info_PDFSaveSuccessTitle,
string.Format(Translator.Info_PDFSaveSuccessMessage, pdfFilePath),
InfoBarMessageType.Success);
}
}
catch (Exception ex)
{
DialogService.InfoBarMessage(Translator.Info_PDFSaveFailedTitle, ex.Message, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_PDFSaveFailedTitle, ex.Message, InfoBarMessageType.Error);
Crashes.TrackError(ex);
}
}
@@ -751,7 +754,7 @@ namespace Wino.Mail.ViewModels
}
catch (Exception ex)
{
DialogService.InfoBarMessage(Translator.Info_FileLaunchFailedTitle, ex.Message, InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_FileLaunchFailedTitle, ex.Message, InfoBarMessageType.Error);
}
}
@@ -773,7 +776,7 @@ namespace Wino.Mail.ViewModels
}
catch (Exception ex)
{
DialogService.InfoBarMessage(Translator.Info_MailRenderingFailedTitle, string.Format(Translator.Info_MailRenderingFailedMessage, ex.Message), InfoBarMessageType.Error);
_dialogService.InfoBarMessage(Translator.Info_MailRenderingFailedTitle, string.Format(Translator.Info_MailRenderingFailedMessage, ex.Message), InfoBarMessageType.Error);
Crashes.TrackError(ex);
Log.Error(ex, "Render Failed");

View File

@@ -8,13 +8,14 @@ using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.ViewModels.Data;
using Wino.Mail.ViewModels.Data;
using Wino.Messaging.Client.Navigation;
using Wino.Messaging.UI;
namespace Wino.Mail.ViewModels
{
public partial class MergedAccountDetailsPageViewModel : BaseViewModel,
public partial class MergedAccountDetailsPageViewModel : MailBaseViewModel,
IRecipient<MergedInboxRenamed>
{
[ObservableProperty]
@@ -49,15 +50,17 @@ namespace Wino.Mail.ViewModels
}
}
private readonly IMailDialogService _dialogService;
private readonly IAccountService _accountService;
private readonly IPreferencesService _preferencesService;
private readonly IProviderService _providerService;
public MergedAccountDetailsPageViewModel(IDialogService dialogService,
public MergedAccountDetailsPageViewModel(IMailDialogService dialogService,
IAccountService accountService,
IPreferencesService preferencesService,
IProviderService providerService) : base(dialogService)
IProviderService providerService)
{
_dialogService = dialogService;
_accountService = accountService;
_preferencesService = preferencesService;
_providerService = providerService;
@@ -68,7 +71,7 @@ namespace Wino.Mail.ViewModels
{
if (EditingMergedAccount == null) return;
var isConfirmed = await DialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_UnlinkAccountsConfirmationMessage, Translator.DialogMessage_UnlinkAccountsConfirmationTitle, Translator.Buttons_Yes);
var isConfirmed = await _dialogService.ShowConfirmationDialogAsync(Translator.DialogMessage_UnlinkAccountsConfirmationMessage, Translator.DialogMessage_UnlinkAccountsConfirmationTitle, Translator.Buttons_Yes);
if (!isConfirmed) return;
@@ -110,7 +113,7 @@ namespace Wino.Mail.ViewModels
{
if (EditingMergedAccount == null) return;
var newName = await DialogService.ShowTextInputDialogAsync(EditingMergedAccount.MergedInbox.Name,
var newName = await _dialogService.ShowTextInputDialogAsync(EditingMergedAccount.MergedInbox.Name,
Translator.DialogMessage_RenameLinkedAccountsTitle,
Translator.DialogMessage_RenameLinkedAccountsMessage,
Translator.FolderOperation_Rename);

View File

@@ -6,7 +6,7 @@ using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels
{
public class MessageListPageViewModel : BaseViewModel
public class MessageListPageViewModel : MailBaseViewModel
{
public IPreferencesService PreferencesService { get; }
@@ -92,8 +92,8 @@ namespace Wino.Mail.ViewModels
#endregion
public MessageListPageViewModel(IDialogService dialogService,
IPreferencesService preferencesService) : base(dialogService)
public MessageListPageViewModel(IMailDialogService dialogService,
IPreferencesService preferencesService)
{
PreferencesService = preferencesService;

View File

@@ -1,11 +0,0 @@
using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels
{
public class NewAccountManagementPageViewModel : BaseViewModel
{
public NewAccountManagementPageViewModel(IDialogService dialogService) : base(dialogService)
{
}
}
}

View File

@@ -1,290 +0,0 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Personalization;
using Wino.Mail.ViewModels.Data;
namespace Wino.Mail.ViewModels
{
public partial class PersonalizationPageViewModel : BaseViewModel
{
public IStatePersistanceService StatePersistanceService { get; }
public IPreferencesService PreferencesService { get; }
private readonly IThemeService _themeService;
private bool isPropChangeDisabled = false;
// Sample mail copy to use in previewing mail display modes.
public MailCopy DemoPreviewMailCopy { get; } = new MailCopy()
{
FromName = "Sender Name",
Subject = "Mail Subject",
PreviewText = "Thank you for using Wino Mail. We hope you enjoy the experience.",
};
#region Personalization
public bool IsSelectedWindowsAccentColor => SelectedAppColor == Colors.LastOrDefault();
public ObservableCollection<AppColorViewModel> Colors { get; set; } = [];
public List<ElementThemeContainer> ElementThemes { get; set; } =
[
new ElementThemeContainer(ApplicationElementTheme.Light, Translator.ElementTheme_Light),
new ElementThemeContainer(ApplicationElementTheme.Dark, Translator.ElementTheme_Dark),
new ElementThemeContainer(ApplicationElementTheme.Default, Translator.ElementTheme_Default),
];
public List<MailListDisplayMode> InformationDisplayModes { get; set; } =
[
MailListDisplayMode.Compact,
MailListDisplayMode.Medium,
MailListDisplayMode.Spacious
];
public List<AppThemeBase> AppThemes { get; set; }
[ObservableProperty]
private ElementThemeContainer selectedElementTheme;
[ObservableProperty]
private MailListDisplayMode selectedInfoDisplayMode;
private AppColorViewModel _selectedAppColor;
public AppColorViewModel SelectedAppColor
{
get => _selectedAppColor;
set
{
if (SetProperty(ref _selectedAppColor, value))
{
UseAccentColor = value == Colors?.LastOrDefault();
}
}
}
private bool _useAccentColor;
public bool UseAccentColor
{
get => _useAccentColor;
set
{
if (SetProperty(ref _useAccentColor, value))
{
if (value)
{
SelectedAppColor = Colors?.LastOrDefault();
}
else if (SelectedAppColor == Colors?.LastOrDefault())
{
// Unchecking from accent color.
SelectedAppColor = Colors?.FirstOrDefault();
}
}
}
}
// Allow app theme change for system themes.
public bool CanSelectElementTheme => SelectedAppTheme != null &&
(SelectedAppTheme.AppThemeType == AppThemeType.System || SelectedAppTheme.AppThemeType == AppThemeType.Custom);
private AppThemeBase _selectedAppTheme;
public AppThemeBase SelectedAppTheme
{
get => _selectedAppTheme;
set
{
if (SetProperty(ref _selectedAppTheme, value))
{
OnPropertyChanged(nameof(CanSelectElementTheme));
if (!CanSelectElementTheme)
{
SelectedElementTheme = null;
}
}
}
}
#endregion
[RelayCommand]
private void ResetMailListPaneLength()
{
StatePersistanceService.MailListPaneLength = 420;
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.Info_MailListSizeResetSuccessMessage, InfoBarMessageType.Success);
}
public AsyncRelayCommand CreateCustomThemeCommand { get; set; }
public PersonalizationPageViewModel(IDialogService dialogService,
IStatePersistanceService statePersistanceService,
IThemeService themeService,
IPreferencesService preferencesService) : base(dialogService)
{
CreateCustomThemeCommand = new AsyncRelayCommand(CreateCustomThemeAsync);
StatePersistanceService = statePersistanceService;
_themeService = themeService;
PreferencesService = preferencesService;
}
private async Task CreateCustomThemeAsync()
{
bool isThemeCreated = await DialogService.ShowCustomThemeBuilderDialogAsync();
if (isThemeCreated)
{
// Reload themes.
await InitializeSettingsAsync();
}
}
private void InitializeColors()
{
Colors.Add(new AppColorViewModel("#0078d7"));
Colors.Add(new AppColorViewModel("#00838c"));
Colors.Add(new AppColorViewModel("#e3008c"));
Colors.Add(new AppColorViewModel("#ca4f07"));
Colors.Add(new AppColorViewModel("#e81123"));
Colors.Add(new AppColorViewModel("#00819e"));
Colors.Add(new AppColorViewModel("#10893e"));
Colors.Add(new AppColorViewModel("#881798"));
Colors.Add(new AppColorViewModel("#c239b3"));
Colors.Add(new AppColorViewModel("#767676"));
Colors.Add(new AppColorViewModel("#e1b12c"));
Colors.Add(new AppColorViewModel("#16a085"));
Colors.Add(new AppColorViewModel("#0984e3"));
Colors.Add(new AppColorViewModel("#4a69bd"));
Colors.Add(new AppColorViewModel("#05c46b"));
// Add system accent color as last item.
Colors.Add(new AppColorViewModel(_themeService.GetSystemAccentColorHex(), true));
}
/// <summary>
/// Set selections from settings service.
/// </summary>
private void SetInitialValues()
{
SelectedElementTheme = ElementThemes.Find(a => a.NativeTheme == _themeService.RootTheme);
SelectedInfoDisplayMode = PreferencesService.MailItemDisplayMode;
var currentAccentColor = _themeService.AccentColor;
bool isWindowsColor = string.IsNullOrEmpty(currentAccentColor);
if (isWindowsColor)
{
SelectedAppColor = Colors.LastOrDefault();
UseAccentColor = true;
}
else
SelectedAppColor = Colors.FirstOrDefault(a => a.Hex == currentAccentColor);
SelectedAppTheme = AppThemes.Find(a => a.Id == _themeService.CurrentApplicationThemeId);
}
protected override async void OnActivated()
{
base.OnActivated();
await InitializeSettingsAsync();
}
private async Task InitializeSettingsAsync()
{
Deactivate();
AppThemes = await _themeService.GetAvailableThemesAsync();
OnPropertyChanged(nameof(AppThemes));
InitializeColors();
SetInitialValues();
PropertyChanged -= PersonalizationSettingsUpdated;
PropertyChanged += PersonalizationSettingsUpdated;
_themeService.AccentColorChanged -= AccentColorChanged;
_themeService.ElementThemeChanged -= ElementThemeChanged;
_themeService.AccentColorChanged += AccentColorChanged;
_themeService.ElementThemeChanged += ElementThemeChanged;
}
private void AccentColorChanged(object sender, string e)
{
isPropChangeDisabled = true;
SelectedAppColor = Colors.FirstOrDefault(a => a.Hex == e);
isPropChangeDisabled = false;
}
private void ElementThemeChanged(object sender, ApplicationElementTheme e)
{
isPropChangeDisabled = true;
SelectedElementTheme = ElementThemes.Find(a => a.NativeTheme == e);
isPropChangeDisabled = false;
}
protected override void OnDeactivated()
{
base.OnDeactivated();
Deactivate();
}
private void Deactivate()
{
PropertyChanged -= PersonalizationSettingsUpdated;
_themeService.AccentColorChanged -= AccentColorChanged;
_themeService.ElementThemeChanged -= ElementThemeChanged;
if (AppThemes != null)
{
AppThemes.Clear();
AppThemes = null;
}
}
private void PersonalizationSettingsUpdated(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (isPropChangeDisabled)
return;
if (e.PropertyName == nameof(SelectedElementTheme) && SelectedElementTheme != null)
{
_themeService.RootTheme = SelectedElementTheme.NativeTheme;
}
else if (e.PropertyName == nameof(SelectedAppTheme))
{
_themeService.CurrentApplicationThemeId = SelectedAppTheme.Id;
}
else
{
if (e.PropertyName == nameof(SelectedInfoDisplayMode))
PreferencesService.MailItemDisplayMode = SelectedInfoDisplayMode;
else if (e.PropertyName == nameof(SelectedAppColor))
_themeService.AccentColor = SelectedAppColor.Hex;
}
}
}
}

View File

@@ -6,7 +6,7 @@ using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels
{
public partial class ReadComposePanePageViewModel : BaseViewModel,
public partial class ReadComposePanePageViewModel : MailBaseViewModel,
IRecipient<PropertyChangedMessage<string>>,
IRecipient<PropertyChangedMessage<int>>
{
@@ -31,9 +31,9 @@ namespace Wino.Mail.ViewModels
[NotifyPropertyChangedRecipients]
int currentComposerFontSize;
public ReadComposePanePageViewModel(IDialogService dialogService,
public ReadComposePanePageViewModel(IMailDialogService dialogService,
IFontService fontService,
IPreferencesService preferencesService) : base(dialogService)
IPreferencesService preferencesService)
{
_fontService = fontService;
PreferencesService = preferencesService;

View File

@@ -1,36 +0,0 @@
using System;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Messaging.Client.Navigation;
namespace Wino.Mail.ViewModels
{
public partial class SettingOptionsPageViewModel(IDialogService dialogService) : BaseViewModel(dialogService)
{
[RelayCommand]
private void GoAccountSettings() => Messenger.Send<NavigateSettingsRequested>();
[RelayCommand]
public void NavigateSubDetail(object type)
{
if (type is WinoPage pageType)
{
string pageTitle = pageType switch
{
WinoPage.PersonalizationPage => Translator.SettingsPersonalization_Title,
WinoPage.AboutPage => Translator.SettingsAbout_Title,
WinoPage.MessageListPage => Translator.SettingsMessageList_Title,
WinoPage.ReadComposePanePage => Translator.SettingsReadComposePane_Title,
WinoPage.LanguageTimePage => Translator.SettingsLanguageTime_Title,
WinoPage.AppPreferencesPage => Translator.SettingsAppPreferences_Title,
_ => throw new NotImplementedException()
};
Messenger.Send(new BreadcrumbNavigationRequested(pageTitle, pageType));
}
}
}
}

View File

@@ -1,11 +0,0 @@
using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels
{
public class SettingsPageViewModel : BaseViewModel
{
public SettingsPageViewModel(IDialogService dialogService) : base(dialogService)
{
}
}
}

View File

@@ -1,11 +0,0 @@
using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels
{
public class SettingsDialogViewModel : BaseViewModel
{
public SettingsDialogViewModel(IDialogService dialogService) : base(dialogService)
{
}
}
}

View File

@@ -8,15 +8,16 @@ using CommunityToolkit.Mvvm.Input;
using MoreLinq;
using MoreLinq.Extensions;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Navigation;
namespace Wino.Mail.ViewModels
{
public partial class SignatureManagementPageViewModel(IDialogService dialogService,
public partial class SignatureManagementPageViewModel(IMailDialogService dialogService,
ISignatureService signatureService,
IAccountService accountService) : BaseViewModel(dialogService)
IAccountService accountService) : MailBaseViewModel
{
public ObservableCollection<AccountSignature> Signatures { get; set; } = [];
@@ -63,6 +64,7 @@ namespace Wino.Mail.ViewModels
private MailAccount Account { get; set; }
private readonly IMailDialogService _dialogService = dialogService;
private readonly ISignatureService _signatureService = signatureService;
private readonly IAccountService _accountService = accountService;
@@ -114,7 +116,7 @@ namespace Wino.Mail.ViewModels
[RelayCommand]
private async Task OpenSignatureEditorCreateAsync()
{
var dialogResult = await DialogService.ShowSignatureEditorDialog();
var dialogResult = await _dialogService.ShowSignatureEditorDialog();
if (dialogResult == null) return;
@@ -126,7 +128,7 @@ namespace Wino.Mail.ViewModels
[RelayCommand]
private async Task OpenSignatureEditorEditAsync(AccountSignature signatureModel)
{
var dialogResult = await DialogService.ShowSignatureEditorDialog(signatureModel);
var dialogResult = await _dialogService.ShowSignatureEditorDialog(signatureModel);
if (dialogResult == null) return;
@@ -150,7 +152,7 @@ namespace Wino.Mail.ViewModels
[RelayCommand]
private async Task DeleteSignatureAsync(AccountSignature signatureModel)
{
var shouldRemove = await DialogService.ShowConfirmationDialogAsync(string.Format(Translator.SignatureDeleteDialog_Message, signatureModel.Name), Translator.SignatureDeleteDialog_Title, Translator.Buttons_Delete);
var shouldRemove = await _dialogService.ShowConfirmationDialogAsync(string.Format(Translator.SignatureDeleteDialog_Message, signatureModel.Name), Translator.SignatureDeleteDialog_Title, Translator.Buttons_Delete);
if (!shouldRemove) return;

View File

@@ -6,17 +6,18 @@ using Wino.Core.Domain.Models.Navigation;
namespace Wino.Mail.ViewModels
{
public partial class WelcomePageViewModel : BaseViewModel
public partial class WelcomePageViewModel : MailBaseViewModel
{
public const string VersionFile = "190.md";
private readonly IMailDialogService _dialogService;
private readonly IFileService _fileService;
[ObservableProperty]
private string currentVersionNotes;
public WelcomePageViewModel(IDialogService dialogService, IFileService fileService) : base(dialogService)
public WelcomePageViewModel(IMailDialogService dialogService, IFileService fileService)
{
_dialogService = dialogService;
_fileService = fileService;
}
@@ -30,7 +31,7 @@ namespace Wino.Mail.ViewModels
}
catch (Exception)
{
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, "Can't find the patch notes.", Core.Domain.Enums.InfoBarMessageType.Information);
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, "Can't find the patch notes.", Core.Domain.Enums.InfoBarMessageType.Information);
}
}
}

View File

@@ -12,12 +12,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.5" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.6" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wino.Core.Domain\Wino.Core.Domain.csproj" />
<ProjectReference Include="..\Wino.Core.ViewModels\Wino.Core.ViewModels.csproj" />
<ProjectReference Include="..\Wino.Core\Wino.Core.csproj" />
<ProjectReference Include="..\Wino.Messages\Wino.Messaging.csproj" />
</ItemGroup>