Files
cfs-Tracker/ViewModels/OptionsViewModel.cs
T
Djagor 2b0797f50f Details ausgearbeitet
Linked colors to options menu

Options extension

Aussehen aufgebohrt:
 - erlaubt text von status zu ändern,
 - bessere beschriftung von Farben

desing änderung und bedienung

- heute status felder anklickbar,
- Farbpalette verdunkelt und kontrast reduziert
- Kalender Tage anklickbar gemacht
- Optionen überarbeitet
2026-03-22 23:09:12 +01:00

129 lines
4.3 KiB
C#

using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using cfs_tracker.Data;
using cfs_tracker.Services;
namespace cfs_tracker.ViewModels;
public partial class OptionsViewModel : ObservableObject
{
private readonly HealthEntryRepository _healthRepository;
private readonly AppearanceRepository _appearanceRepository;
private readonly AppearanceService _appearanceService;
[ObservableProperty]
private string deleteConfirmationText = string.Empty;
[ObservableProperty]
private string statusText = string.Empty;
public ObservableCollection<AppearanceColorItemViewModel> AppearanceColors { get; } = new();
public ObservableCollection<AppearanceTextItemViewModel> StatusTexts { get; } = new();
public IAsyncRelayCommand DeleteAllDataCommand { get; }
public IAsyncRelayCommand SaveAppearanceCommand { get; }
public IAsyncRelayCommand ResetAppearanceCommand { get; }
public OptionsViewModel(
HealthEntryRepository healthRepository,
AppearanceRepository appearanceRepository,
AppearanceService appearanceService)
{
_healthRepository = healthRepository;
_appearanceRepository = appearanceRepository;
_appearanceService = appearanceService;
DeleteAllDataCommand = new AsyncRelayCommand(DeleteAllDataAsync, CanDeleteAllData);
SaveAppearanceCommand = new AsyncRelayCommand(SaveAppearanceAsync);
ResetAppearanceCommand = new AsyncRelayCommand(ResetAppearanceAsync);
}
partial void OnDeleteConfirmationTextChanged(string value)
{
DeleteAllDataCommand.NotifyCanExecuteChanged();
}
public async Task LoadAsync()
{
await LoadAppearanceAsync();
}
private bool CanDeleteAllData()
{
return string.Equals(DeleteConfirmationText?.Trim(), "löschen", StringComparison.OrdinalIgnoreCase);
}
private async Task DeleteAllDataAsync()
{
await _healthRepository.DeleteAllAsync();
DeleteConfirmationText = string.Empty;
StatusText = "Alle gespeicherten Einträge wurden gelöscht.";
}
private async Task LoadAppearanceAsync()
{
AppearanceColors.Clear();
StatusTexts.Clear();
var all = await _appearanceRepository.GetAllAsync();
AddColor(all, "AppBackground", "App-Hintergrund");
AddColor(all, "PanelBackground", "Panel-Hintergrund");
AddColor(all, "PanelBackground2", "Sekundäre Fläche");
AddColor(all, "PanelBorder", "Panel-Rand");
AddColor(all, "TextPrimary", "Haupttext");
AddColor(all, "TextMuted", "Gedimmter Text");
AddColor(all, "StateGreen", "Statusfarbe Grün");
AddColor(all, "StateYellow", "Statusfarbe Gelb");
AddColor(all, "StateRed", "Statusfarbe Rot");
AddColor(all, "StateGray", "Statusfarbe Grau");
AddText(all, "StatusGreenText", "Text für Grün");
AddText(all, "StatusYellowText", "Text für Gelb");
AddText(all, "StatusRedText", "Text für Rot");
AddText(all, "StatusGrayText", "Text für Grau");
}
private void AddColor(List<Models.AppearanceSetting> all, string key, string title)
{
var value = all.FirstOrDefault(x => x.Key == key)?.Value ?? string.Empty;
AppearanceColors.Add(new AppearanceColorItemViewModel
{
Key = key,
Title = title,
Value = value
});
}
private void AddText(List<Models.AppearanceSetting> all, string key, string title)
{
var value = all.FirstOrDefault(x => x.Key == key)?.Value ?? string.Empty;
StatusTexts.Add(new AppearanceTextItemViewModel
{
Key = key,
Title = title,
Value = value
});
}
private async Task SaveAppearanceAsync()
{
foreach (var item in AppearanceColors)
await _appearanceService.SaveColorAsync(item.Key, item.Value);
foreach (var item in StatusTexts)
await _appearanceService.SaveTextAsync(item.Key, item.Value);
StatusText = "Aussehen wurde gespeichert.";
}
private async Task ResetAppearanceAsync()
{
await _appearanceService.ResetAsync();
await LoadAppearanceAsync();
StatusText = "Aussehen wurde auf Standard zurückgesetzt.";
}
}