Options fix
clean up and fixes - Heute gefixt - Code Cleanup NotificationScheduleItemViewModel -fixed NotificationScheduleItemViewModel for Windows compat push implementation Push fixes Push benachrichtungen eingebaut - Status bei push - Push auch in background - Toggle für symtome angepasst push system change exporter update Optionen fix - Optionen aufgeteilt auf 3 tabs - Anpassungen haben jetzt Farbslider Optimierung fix
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using cfs_tracker.Data;
|
||||
using cfs_tracker.Helpers;
|
||||
using cfs_tracker.Models;
|
||||
using cfs_tracker.Services;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
@@ -42,12 +45,19 @@ public partial class OptionsViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string currentDatabasePath = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private OptionsTab selectedTab = OptionsTab.Notifications;
|
||||
|
||||
public ObservableCollection<AppearanceColorItemViewModel> AppearanceColors { get; } = new();
|
||||
public ObservableCollection<AppearanceTextItemViewModel> StatusTexts { get; } = new();
|
||||
public ObservableCollection<ActivityManageItemViewModel> Activities { get; } = new();
|
||||
public ObservableCollection<SymptomManageItemViewModel> Symptoms { get; } = new();
|
||||
public ObservableCollection<NotificationScheduleItemViewModel> NotificationSchedules { get; } = new();
|
||||
|
||||
public bool IsAppearanceTabSelected => SelectedTab == OptionsTab.Appearance;
|
||||
public bool IsNotificationsTabSelected => SelectedTab == OptionsTab.Notifications;
|
||||
public bool IsDataManagementTabSelected => SelectedTab == OptionsTab.DataManagement;
|
||||
|
||||
public IAsyncRelayCommand DeleteAllDataCommand { get; }
|
||||
public IAsyncRelayCommand SaveAppearanceCommand { get; }
|
||||
public IAsyncRelayCommand ResetAppearanceCommand { get; }
|
||||
@@ -64,6 +74,9 @@ public partial class OptionsViewModel : ObservableObject
|
||||
public IAsyncRelayCommand<NotificationScheduleItemViewModel> DeleteScheduleCommand { get; }
|
||||
public IAsyncRelayCommand SaveDatabaseLocationCommand { get; }
|
||||
public IAsyncRelayCommand ClearExportsCommand { get; }
|
||||
public IRelayCommand ShowAppearanceTabCommand { get; }
|
||||
public IRelayCommand ShowNotificationsTabCommand { get; }
|
||||
public IRelayCommand ShowDataManagementTabCommand { get; }
|
||||
|
||||
public OptionsViewModel(
|
||||
HealthEntryRepository healthEntryRepository,
|
||||
@@ -104,6 +117,10 @@ public partial class OptionsViewModel : ObservableObject
|
||||
DeleteScheduleCommand = new AsyncRelayCommand<NotificationScheduleItemViewModel>(DeleteScheduleAsync);
|
||||
SaveDatabaseLocationCommand = new AsyncRelayCommand(SaveDatabaseLocationAsync);
|
||||
ClearExportsCommand = new AsyncRelayCommand(ClearExportsAsync);
|
||||
|
||||
ShowAppearanceTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Appearance);
|
||||
ShowNotificationsTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Notifications);
|
||||
ShowDataManagementTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.DataManagement);
|
||||
}
|
||||
|
||||
partial void OnDeleteConfirmationTextChanged(string value)
|
||||
@@ -111,6 +128,13 @@ public partial class OptionsViewModel : ObservableObject
|
||||
DeleteAllDataCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
partial void OnSelectedTabChanged(OptionsTab value)
|
||||
{
|
||||
OnPropertyChanged(nameof(IsAppearanceTabSelected));
|
||||
OnPropertyChanged(nameof(IsNotificationsTabSelected));
|
||||
OnPropertyChanged(nameof(IsDataManagementTabSelected));
|
||||
}
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
await LoadAppearanceAsync();
|
||||
@@ -177,14 +201,15 @@ public partial class OptionsViewModel : ObservableObject
|
||||
{
|
||||
var fallback = AppearanceDefaults.All[key];
|
||||
var value = map.TryGetValue(key, out var stored) ? stored : fallback;
|
||||
var preview = ColorUtility.ParseColor(value, fallback);
|
||||
|
||||
AppearanceColors.Add(new AppearanceColorItemViewModel
|
||||
{
|
||||
Key = key,
|
||||
Title = title,
|
||||
Fallback = fallback,
|
||||
Value = value,
|
||||
PreviewColor = ColorUtility.ParseColor(value, fallback)
|
||||
Value = ToHex(preview),
|
||||
PreviewColor = preview
|
||||
});
|
||||
}
|
||||
|
||||
@@ -239,23 +264,37 @@ public partial class OptionsViewModel : ObservableObject
|
||||
private async Task LoadSchedulesAsync()
|
||||
{
|
||||
NotificationSchedules.Clear();
|
||||
|
||||
var schedules = await _notificationScheduleRepository.GetAllAsync();
|
||||
|
||||
foreach (var schedule in schedules)
|
||||
NotificationSchedules.Add(CreateScheduleVm(schedule.Id, schedule.DayOfWeek, new TimeSpan(schedule.Hour, schedule.Minute, 0), schedule.IsEnabled));
|
||||
{
|
||||
var vm = new NotificationScheduleItemViewModel
|
||||
{
|
||||
Id = schedule.Id,
|
||||
SelectedTime = new TimeSpan(schedule.Hour, schedule.Minute, 0),
|
||||
IsEnabled = schedule.IsEnabled
|
||||
};
|
||||
|
||||
vm.LoadFromWeekdayMask(schedule.WeekdayMask);
|
||||
NotificationSchedules.Add(vm);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAppearanceAsync()
|
||||
{
|
||||
foreach (var item in AppearanceColors)
|
||||
{
|
||||
item.PreviewColor = ColorUtility.ParseColor(item.Value, item.Fallback);
|
||||
await _appearanceService.SaveColorAsync(item.Key, item.Value);
|
||||
var normalized = ToHex(ColorUtility.ParseColor(item.Value, item.Fallback));
|
||||
item.Value = normalized;
|
||||
item.PreviewColor = ColorUtility.ParseColor(normalized, item.Fallback);
|
||||
await _appearanceService.SaveColorAsync(item.Key, normalized);
|
||||
}
|
||||
|
||||
foreach (var item in StatusTexts)
|
||||
await _appearanceService.SaveTextAsync(item.Key, item.Value);
|
||||
|
||||
await _notificationScheduler.SyncAsync();
|
||||
StatusText = "Aussehen gespeichert.";
|
||||
}
|
||||
|
||||
@@ -263,6 +302,7 @@ public partial class OptionsViewModel : ObservableObject
|
||||
{
|
||||
await _appearanceService.ResetAsync();
|
||||
await LoadAppearanceAsync();
|
||||
await _notificationScheduler.SyncAsync();
|
||||
StatusText = "Aussehen auf Standard zurückgesetzt.";
|
||||
}
|
||||
|
||||
@@ -384,17 +424,40 @@ public partial class OptionsViewModel : ObservableObject
|
||||
|
||||
private Task AddScheduleAsync()
|
||||
{
|
||||
NotificationSchedules.Add(CreateScheduleVm(0, DayOfWeek.Monday, new TimeSpan(9, 0, 0), true));
|
||||
NotificationSchedules.Add(new NotificationScheduleItemViewModel
|
||||
{
|
||||
SelectedTime = new TimeSpan(14, 0, 0),
|
||||
IsEnabled = true,
|
||||
Monday = true,
|
||||
Tuesday = true,
|
||||
Wednesday = true,
|
||||
Thursday = true,
|
||||
Friday = true
|
||||
});
|
||||
|
||||
StatusText = "Benachrichtigungszeit hinzugefügt.";
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task SaveSchedulesAsync()
|
||||
{
|
||||
var granted = await _notificationScheduler.EnsurePermissionAsync();
|
||||
if (!granted)
|
||||
{
|
||||
StatusText = "Benachrichtigungsberechtigung wurde nicht erlaubt.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (NotificationSchedules.Any(x => x.ToWeekdayMask() == 0))
|
||||
{
|
||||
StatusText = "Bitte pro Benachrichtigungszeit mindestens einen Wochentag auswählen.";
|
||||
return;
|
||||
}
|
||||
|
||||
var items = NotificationSchedules.Select(x => new NotificationSchedule
|
||||
{
|
||||
Id = x.Id,
|
||||
DayOfWeek = x.SelectedWeekday?.Value ?? DayOfWeek.Monday,
|
||||
WeekdayMask = x.ToWeekdayMask(),
|
||||
Hour = x.SelectedTime.Hours,
|
||||
Minute = x.SelectedTime.Minutes,
|
||||
IsEnabled = x.IsEnabled
|
||||
@@ -404,7 +467,7 @@ public partial class OptionsViewModel : ObservableObject
|
||||
await _notificationScheduler.SyncAsync();
|
||||
await LoadSchedulesAsync();
|
||||
|
||||
StatusText = "Benachrichtigungszeiten gespeichert. Text: 'Wie geht es dir?' mit Gelb/Rot/Grau als Schnellwahl.";
|
||||
StatusText = "Benachrichtigungszeiten gespeichert.";
|
||||
}
|
||||
|
||||
private Task DeleteScheduleAsync(NotificationScheduleItemViewModel? item)
|
||||
@@ -425,24 +488,6 @@ public partial class OptionsViewModel : ObservableObject
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static NotificationScheduleItemViewModel CreateScheduleVm(int id, DayOfWeek dayOfWeek, TimeSpan time, bool isEnabled)
|
||||
{
|
||||
var vm = new NotificationScheduleItemViewModel
|
||||
{
|
||||
Id = id,
|
||||
SelectedTime = time,
|
||||
IsEnabled = isEnabled
|
||||
};
|
||||
|
||||
foreach (var option in BuildWeekdayOptions())
|
||||
vm.WeekdayOptions.Add(option);
|
||||
|
||||
vm.SelectedWeekday = vm.WeekdayOptions.FirstOrDefault(x => x.Value == dayOfWeek)
|
||||
?? vm.WeekdayOptions.First();
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
private async Task ClearExportsAsync()
|
||||
{
|
||||
var confirm = await Shell.Current.DisplayAlertAsync(
|
||||
@@ -464,14 +509,20 @@ public partial class OptionsViewModel : ObservableObject
|
||||
"OK");
|
||||
}
|
||||
|
||||
private static IEnumerable<WeekdayOptionItemViewModel> BuildWeekdayOptions()
|
||||
private static string ToHex(Color color)
|
||||
{
|
||||
yield return new WeekdayOptionItemViewModel { Value = DayOfWeek.Monday, Name = "Montag" };
|
||||
yield return new WeekdayOptionItemViewModel { Value = DayOfWeek.Tuesday, Name = "Dienstag" };
|
||||
yield return new WeekdayOptionItemViewModel { Value = DayOfWeek.Wednesday, Name = "Mittwoch" };
|
||||
yield return new WeekdayOptionItemViewModel { Value = DayOfWeek.Thursday, Name = "Donnerstag" };
|
||||
yield return new WeekdayOptionItemViewModel { Value = DayOfWeek.Friday, Name = "Freitag" };
|
||||
yield return new WeekdayOptionItemViewModel { Value = DayOfWeek.Saturday, Name = "Samstag" };
|
||||
yield return new WeekdayOptionItemViewModel { Value = DayOfWeek.Sunday, Name = "Sonntag" };
|
||||
var red = ClampByte(color.Red * 255d);
|
||||
var green = ClampByte(color.Green * 255d);
|
||||
var blue = ClampByte(color.Blue * 255d);
|
||||
return $"#{red:X2}{green:X2}{blue:X2}";
|
||||
}
|
||||
}
|
||||
|
||||
private static int ClampByte(double value) => Math.Clamp((int)Math.Round(value), 0, 255);
|
||||
|
||||
public enum OptionsTab
|
||||
{
|
||||
Appearance,
|
||||
Notifications,
|
||||
DataManagement
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user