Ability to set composer default font (#287)

* Added ability to set Composer font

* Added missing translations and refactoring

* Remove unused methods

* Small fixes
This commit is contained in:
Tiktack
2024-07-18 20:04:11 +02:00
committed by GitHub
parent 76375c9471
commit cf2f0ec936
30 changed files with 424 additions and 316 deletions

View File

@@ -108,35 +108,38 @@ namespace Wino.Mail.ViewModels
private readonly IMailService _mailService;
private readonly ILaunchProtocolService _launchProtocolService;
private readonly IMimeFileService _mimeFileService;
private readonly IStatePersistanceService _statePersistanceService;
private readonly IFolderService _folderService;
private readonly IAccountService _accountService;
private readonly IWinoRequestDelegator _worker;
public readonly IFontService FontService;
public readonly IPreferencesService PreferencesService;
public readonly IContactService ContactService;
public ComposePageViewModel(IDialogService dialogService,
IMailService mailService,
ILaunchProtocolService launchProtocolService,
IMimeFileService mimeFileService,
IStatePersistanceService statePersistanceService,
INativeAppService nativeAppService,
IFolderService folderService,
IAccountService accountService,
IWinoRequestDelegator worker,
IContactService contactService) : base(dialogService)
IContactService contactService,
IFontService fontService,
IPreferencesService preferencesService) : base(dialogService)
{
NativeAppService = nativeAppService;
_folderService = folderService;
ContactService = contactService;
FontService = fontService;
_mailService = mailService;
_launchProtocolService = launchProtocolService;
_mimeFileService = mimeFileService;
_statePersistanceService = statePersistanceService;
_accountService = accountService;
_worker = worker;
SelectedToolbarSection = ToolbarSections[0];
PreferencesService = preferencesService;
}
[RelayCommand]

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Wino.Core.Domain;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
@@ -9,23 +10,40 @@ namespace Wino.Mail.ViewModels
{
public IPreferencesService PreferencesService { get; }
private List<MailOperation> availableHoverActions = new List<MailOperation>
private int selectedMarkAsOptionIndex;
public int SelectedMarkAsOptionIndex
{
get => selectedMarkAsOptionIndex;
set
{
if (SetProperty(ref selectedMarkAsOptionIndex, value))
{
if (value >= 0)
{
PreferencesService.MarkAsPreference = (MailMarkAsOption)Enum.GetValues(typeof(MailMarkAsOption)).GetValue(value);
}
}
}
}
private readonly List<MailOperation> availableHoverActions =
[
MailOperation.Archive,
MailOperation.SoftDelete,
MailOperation.SetFlag,
MailOperation.MarkAsRead,
MailOperation.MoveToJunk
};
];
public List<string> AvailableHoverActionsTranslations { get; set; } = new List<string>()
{
public List<string> AvailableHoverActionsTranslations { get; set; } =
[
Translator.HoverActionOption_Archive,
Translator.HoverActionOption_Delete,
Translator.HoverActionOption_ToggleFlag,
Translator.HoverActionOption_ToggleRead,
Translator.HoverActionOption_MoveJunk
};
];
#region Properties
@@ -82,6 +100,8 @@ namespace Wino.Mail.ViewModels
leftHoverActionIndex = availableHoverActions.IndexOf(PreferencesService.LeftHoverAction);
centerHoverActionIndex = availableHoverActions.IndexOf(PreferencesService.CenterHoverAction);
rightHoverActionIndex = availableHoverActions.IndexOf(PreferencesService.RightHoverAction);
SelectedMarkAsOptionIndex = Array.IndexOf(Enum.GetValues(typeof(MailMarkAsOption)), PreferencesService.MarkAsPreference);
}
}
}

View File

@@ -0,0 +1,73 @@
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Wino.Core.Domain.Interfaces;
namespace Wino.Mail.ViewModels
{
public partial class ReadComposePanePageViewModel : BaseViewModel,
IRecipient<PropertyChangedMessage<string>>,
IRecipient<PropertyChangedMessage<int>>
{
private readonly IFontService _fontService;
public IPreferencesService PreferencesService { get; set; }
public List<string> AvailableFonts => _fontService.GetFonts();
[ObservableProperty]
[NotifyPropertyChangedRecipients]
string currentReaderFont;
[ObservableProperty]
[NotifyPropertyChangedRecipients]
int currentReaderFontSize;
[ObservableProperty]
[NotifyPropertyChangedRecipients]
string currentComposerFont;
[ObservableProperty]
[NotifyPropertyChangedRecipients]
int currentComposerFontSize;
public ReadComposePanePageViewModel(IDialogService dialogService,
IFontService fontService,
IPreferencesService preferencesService) : base(dialogService)
{
_fontService = fontService;
PreferencesService = preferencesService;
CurrentReaderFont = fontService.GetCurrentReaderFont();
CurrentReaderFontSize = fontService.GetCurrentReaderFontSize();
CurrentComposerFont = fontService.GetCurrentComposerFont();
CurrentComposerFontSize = fontService.GetCurrentComposerFontSize();
}
public void Receive(PropertyChangedMessage<string> message)
{
if (message.PropertyName == nameof(CurrentReaderFont) && message.OldValue != message.NewValue)
{
_fontService.SetReaderFont(message.NewValue);
}
if (message.PropertyName == nameof(CurrentComposerFont) && message.OldValue != message.NewValue)
{
_fontService.SetComposerFont(message.NewValue);
}
}
public void Receive(PropertyChangedMessage<int> message)
{
if (message.PropertyName == nameof(CurrentReaderFontSize))
{
_fontService.SetReaderFontSize(CurrentReaderFontSize);
}
else if (message.PropertyName == nameof(CurrentComposerFontSize))
{
_fontService.SetComposerFontSize(CurrentComposerFontSize);
}
}
}
}

View File

@@ -1,77 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Reader;
namespace Wino.Mail.ViewModels
{
public partial class ReadingPanePageViewModel : BaseViewModel,
IRecipient<PropertyChangedMessage<ReaderFontModel>>,
IRecipient<PropertyChangedMessage<int>>
{
public IPreferencesService PreferencesService { get; set; }
private int selectedMarkAsOptionIndex;
private readonly IFontService _fontService;
public int SelectedMarkAsOptionIndex
{
get => selectedMarkAsOptionIndex;
set
{
if (SetProperty(ref selectedMarkAsOptionIndex, value))
{
if (value >= 0)
{
PreferencesService.MarkAsPreference = (MailMarkAsOption)Enum.GetValues(typeof(MailMarkAsOption)).GetValue(value);
}
}
}
}
public List<ReaderFontModel> ReaderFonts => _fontService.GetReaderFonts();
[ObservableProperty]
[NotifyPropertyChangedRecipients]
ReaderFontModel currentReaderFont;
[ObservableProperty]
[NotifyPropertyChangedRecipients]
int currentReaderFontSize;
public ReadingPanePageViewModel(IDialogService dialogService,
IFontService fontService,
IPreferencesService preferencesService) : base(dialogService)
{
_fontService = fontService;
PreferencesService = preferencesService;
SelectedMarkAsOptionIndex = Array.IndexOf(Enum.GetValues(typeof(MailMarkAsOption)), PreferencesService.MarkAsPreference);
CurrentReaderFont = fontService.GetCurrentReaderFont();
CurrentReaderFontSize = fontService.GetCurrentReaderFontSize();
}
public void Receive(PropertyChangedMessage<ReaderFontModel> message)
{
if (message.OldValue != message.NewValue)
{
_fontService.ChangeReaderFont(message.NewValue.Font);
Debug.WriteLine("Changed reader font.");
}
}
public void Receive(PropertyChangedMessage<int> message)
{
if (message.PropertyName == nameof(CurrentReaderFontSize))
{
_fontService.ChangeReaderFontSize(CurrentReaderFontSize);
}
}
}
}

View File

@@ -9,18 +9,11 @@ using Wino.Core.Messages.Navigation;
namespace Wino.Mail.ViewModels
{
public partial class SettingOptionsPageViewModel : BaseViewModel
public partial class SettingOptionsPageViewModel(IDialogService dialogService) : BaseViewModel(dialogService)
{
public SettingOptionsPageViewModel(IDialogService dialogService) : base(dialogService) { }
[RelayCommand]
private void GoAccountSettings() => Messenger.Send<NavigateSettingsRequested>();
public override void OnNavigatedTo(NavigationMode mode, object parameters)
{
base.OnNavigatedTo(mode, parameters);
}
[RelayCommand]
public void NavigateSubDetail(object type)
{
@@ -31,7 +24,7 @@ namespace Wino.Mail.ViewModels
WinoPage.PersonalizationPage => Translator.SettingsPersonalization_Title,
WinoPage.AboutPage => Translator.SettingsAbout_Title,
WinoPage.MessageListPage => Translator.SettingsMessageList_Title,
WinoPage.ReadingPanePage => Translator.SettingsReadingPane_Title,
WinoPage.ReadComposePanePage => Translator.SettingsReadComposePane_Title,
WinoPage.LanguageTimePage => Translator.SettingsLanguageTime_Title,
_ => throw new NotImplementedException()
};