You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
using System.Collections.Generic; |
|
using System.Collections.Immutable; |
|
using System.Linq; |
|
using CommunityToolkit.Mvvm.ComponentModel; |
|
using FluentAvalonia.UI.Controls; |
|
using StabilityMatrix.Avalonia.ViewModels.Base; |
|
using StabilityMatrix.Avalonia.Views.Settings; |
|
using StabilityMatrix.Core.Attributes; |
|
using StabilityMatrix.Core.Models.Settings; |
|
using StabilityMatrix.Core.Services; |
|
|
|
namespace StabilityMatrix.Avalonia.ViewModels.Settings; |
|
|
|
[View(typeof(NotificationSettingsPage))] |
|
[Singleton] |
|
[ManagedService] |
|
public partial class NotificationSettingsViewModel(ISettingsManager settingsManager) : PageViewModelBase |
|
{ |
|
public override string Title => "Notifications"; |
|
public override IconSource IconSource => new SymbolIconSource { Symbol = Symbol.Alert }; |
|
|
|
[ObservableProperty] |
|
private IReadOnlyList<NotificationSettingsItem> items = []; |
|
|
|
public override void OnLoaded() |
|
{ |
|
base.OnLoaded(); |
|
|
|
Items = GetItems().OrderBy(item => item.Key?.Value).ToImmutableArray(); |
|
} |
|
|
|
private IEnumerable<NotificationSettingsItem> GetItems() |
|
{ |
|
var settingsOptions = settingsManager.Settings.NotificationOptions; |
|
|
|
foreach (var notificationKey in NotificationKey.All.Values) |
|
{ |
|
// If in settings, include settings value, otherwise default |
|
if (!settingsOptions.TryGetValue(notificationKey, out var option)) |
|
{ |
|
option = notificationKey.DefaultOption; |
|
} |
|
|
|
yield return new NotificationSettingsItem(settingsManager) |
|
{ |
|
Key = notificationKey, |
|
Option = option |
|
}; |
|
} |
|
} |
|
}
|
|
|