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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user