Skip to content

Commit

Permalink
Closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Jul 13, 2024
1 parent 6ad5da6 commit e89e54c
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions Yosu/Services/PreferenceService.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text.Json.Serialization;
using Cogwheel;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Storage;
using PropertyChanged;
using Yosu.ViewModels.Components;

namespace Yosu.Services;

[AddINotifyPropertyChangedInterface]
public partial class PreferenceService : SettingsBase, INotifyPropertyChanged
// Can't use [ObservableProperty] here because System.Text.Json's source generator doesn't see
// the generated properties.
[INotifyPropertyChanged]
public partial class PreferenceService()
: SettingsBase(
Path.Combine(FileSystem.AppDataDirectory, "Preferences.json"),
SerializerContext.Default
)
{
public AppTheme AppTheme { get; set; }
private AppTheme _appTheme;
public AppTheme AppTheme
{
get => _appTheme;
set => SetProperty(ref _appTheme, value);
}

public List<DownloadItem> Downloads { get; set; } = [];
private List<DownloadItem> _downloads = [];
public List<DownloadItem> Downloads
{
get => _downloads;
set => SetProperty(ref _downloads, value);
}

public SourceType SearchSourceType { get; set; } = SourceType.Youtube;
private SourceType _searchSourceType = SourceType.Youtube;
public SourceType SearchSourceType
{
get => _searchSourceType;
set => SetProperty(ref _searchSourceType, value);
}
}

public PreferenceService()
: base(Path.Combine(FileSystem.AppDataDirectory, "Preferences.json")) { }
public partial class PreferenceService
{
[JsonSerializable(typeof(PreferenceService))]
private partial class SerializerContext : JsonSerializerContext;
}

0 comments on commit e89e54c

Please sign in to comment.