Files
Wino-Mail/Wino.Core.UWP/Services/StatePersistenceService.cs

144 lines
3.8 KiB
C#
Raw Permalink Normal View History

2024-04-18 01:44:37 +02:00
using System;
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Core.Domain.Enums;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain.Interfaces;
2025-02-16 11:54:23 +01:00
namespace Wino.Services;
public class StatePersistenceService : ObservableObject, IStatePersistanceService
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
public event EventHandler<string> StatePropertyChanged;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private const string OpenPaneLengthKey = nameof(OpenPaneLengthKey);
private const string MailListPaneLengthKey = nameof(MailListPaneLengthKey);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private readonly IConfigurationService _configurationService;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public StatePersistenceService(IConfigurationService configurationService)
{
_configurationService = configurationService;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
_openPaneLength = _configurationService.Get(OpenPaneLengthKey, 320d);
_mailListPaneLength = _configurationService.Get(MailListPaneLengthKey, 420d);
_calendarDisplayType = _configurationService.Get(nameof(CalendarDisplayType), CalendarDisplayType.Week);
_dayDisplayCount = _configurationService.Get(nameof(DayDisplayCount), 1);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
PropertyChanged += ServicePropertyChanged;
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void ServicePropertyChanged(object sender, PropertyChangedEventArgs e) => StatePropertyChanged?.Invoke(this, e.PropertyName);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsBackButtonVisible => IsReadingMail && IsReaderNarrowed;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private bool isReadingMail;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsReadingMail
{
get => isReadingMail;
set
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
if (SetProperty(ref isReadingMail, value))
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
OnPropertyChanged(nameof(IsBackButtonVisible));
2024-04-18 01:44:37 +02:00
}
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private bool shouldShiftMailRenderingDesign;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool ShouldShiftMailRenderingDesign
{
get { return shouldShiftMailRenderingDesign; }
set { shouldShiftMailRenderingDesign = value; }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private bool isReaderNarrowed;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsReaderNarrowed
{
get => isReaderNarrowed;
set
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
if (SetProperty(ref isReaderNarrowed, value))
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
OnPropertyChanged(nameof(IsBackButtonVisible));
2024-04-18 01:44:37 +02:00
}
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private string coreWindowTitle;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public string CoreWindowTitle
{
get => coreWindowTitle;
set
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
if (SetProperty(ref coreWindowTitle, value))
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
UpdateAppCoreWindowTitle();
2024-04-18 01:44:37 +02:00
}
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private double _openPaneLength;
public double OpenPaneLength
{
get => _openPaneLength;
set
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
if (SetProperty(ref _openPaneLength, value))
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
_configurationService.Set(OpenPaneLengthKey, value);
2024-04-18 01:44:37 +02:00
}
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private double _mailListPaneLength;
public double MailListPaneLength
{
get => _mailListPaneLength;
set
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
if (SetProperty(ref _mailListPaneLength, value))
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
_configurationService.Set(MailListPaneLengthKey, value);
2024-04-18 01:44:37 +02:00
}
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private CalendarDisplayType _calendarDisplayType;
public CalendarDisplayType CalendarDisplayType
{
get => _calendarDisplayType;
set
{
2025-02-16 11:54:23 +01:00
if (SetProperty(ref _calendarDisplayType, value))
{
2025-02-16 11:54:23 +01:00
_configurationService.Set(nameof(CalendarDisplayType), value);
}
2024-04-18 01:44:37 +02:00
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private int _dayDisplayCount;
public int DayDisplayCount
{
get => _dayDisplayCount;
set
{
2025-02-16 11:54:23 +01:00
if (SetProperty(ref _dayDisplayCount, value))
{
2025-02-16 11:54:23 +01:00
_configurationService.Set(nameof(DayDisplayCount), value);
}
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void UpdateAppCoreWindowTitle()
{
var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (appView != null)
appView.Title = CoreWindowTitle;
2024-04-18 01:44:37 +02:00
}
}