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

73 lines
2.3 KiB
C#
Raw Normal View History

2024-07-18 20:04:11 +02:00
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>>
2024-07-18 20:04:11 +02:00
{
2025-02-16 11:54:23 +01:00
private readonly IFontService _fontService;
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
public IPreferencesService PreferencesService { get; set; }
public List<string> AvailableFonts => _fontService.GetFonts();
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
string currentReaderFont;
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
int currentReaderFontSize;
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
string currentComposerFont;
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
[ObservableProperty]
[NotifyPropertyChangedRecipients]
int currentComposerFontSize;
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
public ReadComposePanePageViewModel(IMailDialogService dialogService,
IFontService fontService,
IPreferencesService preferencesService)
{
_fontService = fontService;
PreferencesService = preferencesService;
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
CurrentReaderFont = preferencesService.ReaderFont;
CurrentReaderFontSize = preferencesService.ReaderFontSize;
2024-07-18 20:04:11 +02:00
2025-02-16 11:54:23 +01:00
CurrentComposerFont = preferencesService.ComposerFont;
CurrentComposerFontSize = preferencesService.ComposerFontSize;
}
2024-07-18 20:04:11 +02:00
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;
}
2024-07-18 20:04:11 +02:00
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:43:30 +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))
2024-07-18 20:04:11 +02:00
{
2025-02-16 11:54:23 +01:00
PreferencesService.ComposerFontSize = CurrentComposerFontSize;
2024-07-18 20:04:11 +02:00
}
}
}