Settings refactoring.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -6,73 +6,22 @@ using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Translations;
|
||||
|
||||
namespace Wino.Mail.ViewModels;
|
||||
|
||||
public partial class AppPreferencesPageViewModel : MailBaseViewModel
|
||||
{
|
||||
public IPreferencesService PreferencesService { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial List<string> SearchModes { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial List<string> ApplicationModes { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorDisabled))]
|
||||
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorEnabled))]
|
||||
private StartupBehaviorResult startupBehaviorResult;
|
||||
|
||||
private int _emailSyncIntervalMinutes;
|
||||
public int EmailSyncIntervalMinutes
|
||||
{
|
||||
get => _emailSyncIntervalMinutes;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _emailSyncIntervalMinutes, value);
|
||||
|
||||
PreferencesService.EmailSyncIntervalMinutes = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsStartupBehaviorDisabled => !IsStartupBehaviorEnabled;
|
||||
public bool IsStartupBehaviorEnabled => StartupBehaviorResult == StartupBehaviorResult.Enabled;
|
||||
|
||||
private string _selectedDefaultSearchMode;
|
||||
public string SelectedDefaultSearchMode
|
||||
{
|
||||
get => _selectedDefaultSearchMode;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedDefaultSearchMode, value);
|
||||
|
||||
PreferencesService.DefaultSearchMode = (SearchMode)SearchModes.IndexOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _selectedDefaultApplicationMode;
|
||||
public string SelectedDefaultApplicationMode
|
||||
{
|
||||
get => _selectedDefaultApplicationMode;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedDefaultApplicationMode, value);
|
||||
|
||||
PreferencesService.DefaultApplicationMode = (WinoApplicationMode)ApplicationModes.IndexOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly IMailDialogService _dialogService;
|
||||
private readonly IStartupBehaviorService _startupBehaviorService;
|
||||
|
||||
public AppPreferencesPageViewModel(IMailDialogService dialogService,
|
||||
IPreferencesService preferencesService,
|
||||
IStartupBehaviorService startupBehaviorService)
|
||||
public AppPreferencesPageViewModel(
|
||||
IMailDialogService dialogService,
|
||||
IPreferencesService preferencesService,
|
||||
IStartupBehaviorService startupBehaviorService,
|
||||
ITranslationService translationService)
|
||||
{
|
||||
_dialogService = dialogService;
|
||||
PreferencesService = preferencesService;
|
||||
_startupBehaviorService = startupBehaviorService;
|
||||
_translationService = translationService;
|
||||
|
||||
SearchModes =
|
||||
[
|
||||
@@ -93,17 +42,81 @@ public partial class AppPreferencesPageViewModel : MailBaseViewModel
|
||||
EmailSyncIntervalMinutes = PreferencesService.EmailSyncIntervalMinutes;
|
||||
}
|
||||
|
||||
public IPreferencesService PreferencesService { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial List<string> SearchModes { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial List<string> ApplicationModes { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial List<AppLanguageModel> AvailableLanguages { get; set; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
public partial AppLanguageModel SelectedLanguage { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorDisabled))]
|
||||
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorEnabled))]
|
||||
private StartupBehaviorResult startupBehaviorResult;
|
||||
|
||||
private readonly IMailDialogService _dialogService;
|
||||
private readonly IStartupBehaviorService _startupBehaviorService;
|
||||
private readonly ITranslationService _translationService;
|
||||
private bool _isLanguageInitialized;
|
||||
private int _emailSyncIntervalMinutes;
|
||||
private string _selectedDefaultSearchMode;
|
||||
private string _selectedDefaultApplicationMode;
|
||||
|
||||
public int EmailSyncIntervalMinutes
|
||||
{
|
||||
get => _emailSyncIntervalMinutes;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _emailSyncIntervalMinutes, value);
|
||||
PreferencesService.EmailSyncIntervalMinutes = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsStartupBehaviorDisabled => !IsStartupBehaviorEnabled;
|
||||
public bool IsStartupBehaviorEnabled => StartupBehaviorResult == StartupBehaviorResult.Enabled;
|
||||
|
||||
public string SelectedDefaultSearchMode
|
||||
{
|
||||
get => _selectedDefaultSearchMode;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedDefaultSearchMode, value);
|
||||
PreferencesService.DefaultSearchMode = (SearchMode)SearchModes.IndexOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
public string SelectedDefaultApplicationMode
|
||||
{
|
||||
get => _selectedDefaultApplicationMode;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedDefaultApplicationMode, value);
|
||||
PreferencesService.DefaultApplicationMode = (WinoApplicationMode)ApplicationModes.IndexOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedLanguageChanged(AppLanguageModel value)
|
||||
{
|
||||
if (!_isLanguageInitialized || value == null)
|
||||
return;
|
||||
|
||||
_ = _translationService.InitializeLanguageAsync(value.Language);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ToggleStartupBehaviorAsync()
|
||||
{
|
||||
if (IsStartupBehaviorEnabled)
|
||||
{
|
||||
await DisableStartupAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await EnableStartupAsync();
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(IsStartupBehaviorEnabled));
|
||||
}
|
||||
@@ -111,14 +124,12 @@ public partial class AppPreferencesPageViewModel : MailBaseViewModel
|
||||
private async Task EnableStartupAsync()
|
||||
{
|
||||
StartupBehaviorResult = await _startupBehaviorService.ToggleStartupBehavior(true);
|
||||
|
||||
NotifyCurrentStartupState();
|
||||
}
|
||||
|
||||
private async Task DisableStartupAsync()
|
||||
{
|
||||
StartupBehaviorResult = await _startupBehaviorService.ToggleStartupBehavior(false);
|
||||
|
||||
NotifyCurrentStartupState();
|
||||
}
|
||||
|
||||
@@ -146,12 +157,15 @@ public partial class AppPreferencesPageViewModel : MailBaseViewModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override async void OnNavigatedTo(NavigationMode mode, object parameters)
|
||||
{
|
||||
base.OnNavigatedTo(mode, parameters);
|
||||
|
||||
AvailableLanguages = _translationService.GetAvailableLanguages();
|
||||
SelectedLanguage = AvailableLanguages.Find(language => language.Language == PreferencesService.CurrentLanguage)
|
||||
?? (AvailableLanguages.Count > 0 ? AvailableLanguages[0] : null);
|
||||
_isLanguageInitialized = true;
|
||||
|
||||
StartupBehaviorResult = await _startupBehaviorService.GetCurrentStartupBehaviorAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Translations;
|
||||
|
||||
namespace Wino.Mail.ViewModels;
|
||||
|
||||
public partial class LanguageTimePageViewModel(IPreferencesService preferencesService, ITranslationService translationService) : MailBaseViewModel
|
||||
{
|
||||
public IPreferencesService PreferencesService { get; } = preferencesService;
|
||||
private readonly ITranslationService _translationService = translationService;
|
||||
|
||||
[ObservableProperty]
|
||||
private List<AppLanguageModel> _availableLanguages;
|
||||
|
||||
[ObservableProperty]
|
||||
private AppLanguageModel _selectedLanguage;
|
||||
|
||||
private bool isInitialized = false;
|
||||
|
||||
public override void OnNavigatedTo(NavigationMode mode, object parameters)
|
||||
{
|
||||
base.OnNavigatedTo(mode, parameters);
|
||||
|
||||
AvailableLanguages = _translationService.GetAvailableLanguages();
|
||||
|
||||
SelectedLanguage = AvailableLanguages.FirstOrDefault(a => a.Language == PreferencesService.CurrentLanguage);
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
protected override async void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
|
||||
if (!isInitialized) return;
|
||||
|
||||
if (e.PropertyName == nameof(SelectedLanguage))
|
||||
{
|
||||
await _translationService.InitializeLanguageAsync(SelectedLanguage.Language);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
@@ -40,6 +42,10 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
Translator.HoverActionOption_MoveJunk
|
||||
];
|
||||
|
||||
public IMailItemDisplayInformation DemoPreviewMailItemInformation { get; } = new DemoMailItemDisplayInformation();
|
||||
|
||||
public MailListDisplayMode SelectedMailSpacingMode => availableMailSpacingOptions[selectedMailSpacingIndex];
|
||||
|
||||
private int selectedMarkAsOptionIndex;
|
||||
public int SelectedMarkAsOptionIndex
|
||||
{
|
||||
@@ -62,6 +68,7 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
if (SetProperty(ref selectedMailSpacingIndex, value) && value >= 0 && value < availableMailSpacingOptions.Count)
|
||||
{
|
||||
PreferencesService.MailItemDisplayMode = availableMailSpacingOptions[value];
|
||||
OnPropertyChanged(nameof(SelectedMailSpacingMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,4 +142,32 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
_statePersistenceService.MailListPaneLength = 420;
|
||||
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.Info_MailListSizeResetSuccessMessage, InfoBarMessageType.Success);
|
||||
}
|
||||
|
||||
private sealed class DemoMailItemDisplayInformation : IMailItemDisplayInformation
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged
|
||||
{
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
public string Subject => "Quarterly planning notes";
|
||||
public string FromName => "Ava Brooks";
|
||||
public string FromAddress => "ava@contoso.com";
|
||||
public string PreviewText => "Agenda draft, attendee updates, and a few follow-up items for this week.";
|
||||
public bool IsRead => false;
|
||||
public bool IsDraft => false;
|
||||
public bool HasAttachments => true;
|
||||
public bool IsCalendarEvent => false;
|
||||
public bool IsFlagged => true;
|
||||
public DateTime CreationDate => DateTime.Now.AddMinutes(-12);
|
||||
public Guid? ContactPictureFileId => null;
|
||||
public bool ThumbnailUpdatedEvent => false;
|
||||
public bool IsThreadExpanded => false;
|
||||
public AccountContact SenderContact => new()
|
||||
{
|
||||
Address = "ava@contoso.com",
|
||||
Name = "Ava Brooks"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user