Files
Wino-Mail/Wino.Mail.ViewModels/ReadComposePanePageViewModel.cs

73 lines
2.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Wino.Core.Domain.Interfaces;
2025-02-16 11:54:23 +01:00
namespace Wino.Mail.ViewModels;
public partial class ReadComposePanePageViewModel : MailBaseViewModel,
IRecipient<PropertyChangedMessage<string>>,
IRecipient<PropertyChangedMessage<int>>
{
2025-02-16 11:54:23 +01:00
private readonly IFontService _fontService;
2025-02-16 11:54:23 +01:00
public IPreferencesService PreferencesService { get; set; }
public List<string> AvailableFonts => _fontService.GetFonts();
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
string currentReaderFont;
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
int currentReaderFontSize;
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
string currentComposerFont;
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
int currentComposerFontSize;
2025-02-16 11:54:23 +01:00
public ReadComposePanePageViewModel(IMailDialogService dialogService,
IFontService fontService,
IPreferencesService preferencesService)
{
_fontService = fontService;
PreferencesService = preferencesService;
2025-02-16 11:54:23 +01:00
CurrentReaderFont = preferencesService.ReaderFont;
CurrentReaderFontSize = preferencesService.ReaderFontSize;
2025-02-16 11:54:23 +01:00
CurrentComposerFont = preferencesService.ComposerFont;
CurrentComposerFontSize = preferencesService.ComposerFontSize;
}
2025-02-16 11:54:23 +01:00
public void Receive(PropertyChangedMessage<string> message)
{
if (message.PropertyName == nameof(CurrentReaderFont) && message.OldValue != message.NewValue)
2025-02-16 11:35:43 +01:00
{
2025-02-16 11:54:23 +01:00
PreferencesService.ReaderFont = message.NewValue;
}
2025-02-16 11:54:23 +01:00
if (message.PropertyName == nameof(CurrentComposerFont) && message.OldValue != message.NewValue)
{
PreferencesService.ComposerFont = message.NewValue;
2025-02-16 11:35:43 +01:00
}
2025-02-16 11:54:23 +01:00
}
2025-02-16 11:54:23 +01:00
public void Receive(PropertyChangedMessage<int> message)
{
if (message.PropertyName == nameof(CurrentReaderFontSize))
{
PreferencesService.ReaderFontSize = CurrentReaderFontSize;
}
else if (message.PropertyName == nameof(CurrentComposerFontSize))
{
2025-02-16 11:54:23 +01:00
PreferencesService.ComposerFontSize = CurrentComposerFontSize;
}
}
}