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,6 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using cfs_tracker.Helpers;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Maui.Graphics;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
@@ -11,14 +10,16 @@ public partial class DayEntryItemViewModel : ObservableObject
|
||||
public string SlotText { get; init; } = string.Empty;
|
||||
public string StateText { get; init; } = string.Empty;
|
||||
public string ActivityText { get; init; } = string.Empty;
|
||||
public string DurationText { get; init; } = string.Empty;
|
||||
public string SymptomsText { get; init; } = string.Empty;
|
||||
public bool IsBackfill { get; init; }
|
||||
public Color StateColor { get; init; } = Colors.Transparent;
|
||||
public Color ForegroundColor { get; init; } = Colors.White;
|
||||
|
||||
public bool HasActivity => !string.IsNullOrWhiteSpace(ActivityText);
|
||||
public bool HasDuration => !string.IsNullOrWhiteSpace(DurationText);
|
||||
public bool HasSymptoms => !string.IsNullOrWhiteSpace(SymptomsText);
|
||||
public bool HasDetails => HasActivity || HasSymptoms;
|
||||
public bool HasDetails => HasActivity || HasDuration || HasSymptoms;
|
||||
public string DetailsButtonText => IsExpanded ? "Details ausblenden" : "Details anzeigen";
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -43,4 +44,4 @@ public partial class DayEntryItemViewModel : ObservableObject
|
||||
|
||||
IsExpanded = !IsExpanded;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
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.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using Microsoft.Maui.Storage;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
@@ -189,7 +187,8 @@ public partial class DayViewModel : ObservableObject
|
||||
};
|
||||
|
||||
var activityText = string.Empty;
|
||||
if (entry.ActivityId.HasValue && activityMap.TryGetValue(entry.ActivityId.Value, out var activityName) &&
|
||||
if (entry.ActivityId.HasValue &&
|
||||
activityMap.TryGetValue(entry.ActivityId.Value, out var activityName) &&
|
||||
!string.Equals(activityName, "Keine Tätigkeit", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
activityText = activityName;
|
||||
@@ -200,6 +199,10 @@ public partial class DayViewModel : ObservableObject
|
||||
? string.Join(", ", symptoms)
|
||||
: string.Empty;
|
||||
|
||||
var durationText = entry.ActivityDurationMinutes.HasValue && entry.ActivityDurationMinutes.Value > 0
|
||||
? TimeSpan.FromMinutes(entry.ActivityDurationMinutes.Value).ToString(@"hh\:mm")
|
||||
: string.Empty;
|
||||
|
||||
Entries.Add(new DayEntryItemViewModel
|
||||
{
|
||||
Id = entry.Id,
|
||||
@@ -209,6 +212,7 @@ public partial class DayViewModel : ObservableObject
|
||||
entry.State.ToAppearanceTextKey(),
|
||||
entry.State.ToFallbackText()),
|
||||
ActivityText = activityText,
|
||||
DurationText = durationText,
|
||||
SymptomsText = symptomText,
|
||||
IsBackfill = entry.DayPart.HasValue,
|
||||
StateColor = _appearanceService.GetColor(entry.State.ToAppearanceColorKey(), "#1F242B"),
|
||||
@@ -231,6 +235,7 @@ public partial class DayViewModel : ObservableObject
|
||||
await _healthEntryRepository.AddQuickEntryAsync(
|
||||
state: state,
|
||||
activityId: null,
|
||||
activityDurationMinutes: null,
|
||||
symptomIds: null,
|
||||
timestamp: DateTime.Now,
|
||||
source: EntrySource.App);
|
||||
@@ -347,4 +352,4 @@ public partial class DayViewModel : ObservableObject
|
||||
}
|
||||
|
||||
private static string BuildCounterText(string label, int count) => $"{label}\n{count}";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Maui.Graphics;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using cfs_tracker.Data;
|
||||
using cfs_tracker.Helpers;
|
||||
using cfs_tracker.Services;
|
||||
using Microsoft.Maui.Storage;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Maui.ApplicationModel;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
@@ -50,25 +50,31 @@ public partial class MonthViewModel : ObservableObject
|
||||
OpenDayCommand = new AsyncRelayCommand<MonthCellViewModel>(OpenDayAsync);
|
||||
|
||||
_calendarStateService.SelectedDateChanged += HandleSharedDateChanged;
|
||||
SelectedDate = _calendarStateService.SelectedDate;
|
||||
SelectedDate = _calendarStateService.SelectedDate.Date;
|
||||
UpdateHeader();
|
||||
}
|
||||
|
||||
partial void OnSelectedDateChanged(DateTime value)
|
||||
{
|
||||
UpdateHeader();
|
||||
}
|
||||
|
||||
public async Task RefreshAsync()
|
||||
{
|
||||
SelectedDate = _calendarStateService.SelectedDate;
|
||||
var month = new DateTime(SelectedDate.Year, SelectedDate.Month, 1);
|
||||
HeaderText = DateHelper.ToGermanMonthYear(month);
|
||||
SelectedDate = _calendarStateService.SelectedDate.Date;
|
||||
UpdateHeader();
|
||||
|
||||
var monthEnd = month.AddMonths(1);
|
||||
var monthStart = new DateTime(SelectedDate.Year, SelectedDate.Month, 1);
|
||||
var monthEnd = monthStart.AddMonths(1);
|
||||
|
||||
var entries = await _healthEntryRepository.GetEntriesBetweenAsync(month, monthEnd);
|
||||
var entries = await _healthEntryRepository.GetEntriesBetweenAsync(monthStart, monthEnd);
|
||||
Cells.Clear();
|
||||
|
||||
var daysInMonth = DateTime.DaysInMonth(month.Year, month.Month);
|
||||
var daysInMonth = DateTime.DaysInMonth(monthStart.Year, monthStart.Month);
|
||||
|
||||
for (var day = 1; day <= daysInMonth; day++)
|
||||
{
|
||||
var date = new DateTime(month.Year, month.Month, day);
|
||||
var date = new DateTime(monthStart.Year, monthStart.Month, day);
|
||||
var dayEntries = entries.Where(x => x.EntryDate.Date == date.Date).ToList();
|
||||
var average = _aggregationService.CalculateAverage(dayEntries);
|
||||
|
||||
@@ -88,12 +94,20 @@ public partial class MonthViewModel : ObservableObject
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHeader()
|
||||
{
|
||||
var month = new DateTime(SelectedDate.Year, SelectedDate.Month, 1);
|
||||
HeaderText = DateHelper.ToGermanMonthYear(month);
|
||||
}
|
||||
|
||||
private async Task OpenDayAsync(MonthCellViewModel? item)
|
||||
{
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
_calendarStateService.SelectedDate = item.Date;
|
||||
SelectedDate = item.Date.Date;
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await Shell.Current.GoToAsync("//day");
|
||||
}
|
||||
|
||||
@@ -105,25 +119,32 @@ public partial class MonthViewModel : ObservableObject
|
||||
|
||||
private async Task PreviousMonthAsync()
|
||||
{
|
||||
_calendarStateService.SelectedDate = new DateTime(SelectedDate.Year, SelectedDate.Month, 1).AddMonths(-1);
|
||||
SelectedDate = new DateTime(SelectedDate.Year, SelectedDate.Month, 1).AddMonths(-1);
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task NextMonthAsync()
|
||||
{
|
||||
_calendarStateService.SelectedDate = new DateTime(SelectedDate.Year, SelectedDate.Month, 1).AddMonths(1);
|
||||
SelectedDate = new DateTime(SelectedDate.Year, SelectedDate.Month, 1).AddMonths(1);
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task TodayAsync()
|
||||
{
|
||||
_calendarStateService.ResetToToday();
|
||||
await RefreshAsync();
|
||||
var today = DateTime.Today;
|
||||
SelectedDate = today;
|
||||
_calendarStateService.SelectedDate = today;
|
||||
await Shell.Current.GoToAsync("//day");
|
||||
}
|
||||
|
||||
private async void HandleSharedDateChanged(DateTime date)
|
||||
private void HandleSharedDateChanged(DateTime date)
|
||||
{
|
||||
SelectedDate = date;
|
||||
await RefreshAsync();
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
SelectedDate = date.Date;
|
||||
await RefreshAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,84 @@
|
||||
using cfs_tracker.Models;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
public partial class NotificationScheduleItemViewModel : ObservableObject
|
||||
{
|
||||
public int Id { get; init; }
|
||||
|
||||
public ObservableCollection<WeekdayOptionItemViewModel> WeekdayOptions { get; } = new();
|
||||
public int Id { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
private WeekdayOptionItemViewModel? selectedWeekday;
|
||||
private TimeSpan selectedTime;
|
||||
|
||||
[ObservableProperty]
|
||||
private TimeSpan selectedTime = new(9, 0, 0);
|
||||
private bool isEnabled;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isEnabled = true;
|
||||
}
|
||||
private bool monday;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool tuesday;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool wednesday;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool thursday;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool friday;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool saturday;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool sunday;
|
||||
|
||||
public IRelayCommand ToggleMondayCommand { get; }
|
||||
public IRelayCommand ToggleTuesdayCommand { get; }
|
||||
public IRelayCommand ToggleWednesdayCommand { get; }
|
||||
public IRelayCommand ToggleThursdayCommand { get; }
|
||||
public IRelayCommand ToggleFridayCommand { get; }
|
||||
public IRelayCommand ToggleSaturdayCommand { get; }
|
||||
public IRelayCommand ToggleSundayCommand { get; }
|
||||
|
||||
public NotificationScheduleItemViewModel()
|
||||
{
|
||||
ToggleMondayCommand = new RelayCommand(() => Monday = !Monday);
|
||||
ToggleTuesdayCommand = new RelayCommand(() => Tuesday = !Tuesday);
|
||||
ToggleWednesdayCommand = new RelayCommand(() => Wednesday = !Wednesday);
|
||||
ToggleThursdayCommand = new RelayCommand(() => Thursday = !Thursday);
|
||||
ToggleFridayCommand = new RelayCommand(() => Friday = !Friday);
|
||||
ToggleSaturdayCommand = new RelayCommand(() => Saturday = !Saturday);
|
||||
ToggleSundayCommand = new RelayCommand(() => Sunday = !Sunday);
|
||||
}
|
||||
|
||||
public int ToWeekdayMask()
|
||||
{
|
||||
var mask = NotificationWeekdays.None;
|
||||
|
||||
if (Monday) mask |= NotificationWeekdays.Monday;
|
||||
if (Tuesday) mask |= NotificationWeekdays.Tuesday;
|
||||
if (Wednesday) mask |= NotificationWeekdays.Wednesday;
|
||||
if (Thursday) mask |= NotificationWeekdays.Thursday;
|
||||
if (Friday) mask |= NotificationWeekdays.Friday;
|
||||
if (Saturday) mask |= NotificationWeekdays.Saturday;
|
||||
if (Sunday) mask |= NotificationWeekdays.Sunday;
|
||||
|
||||
return (int)mask;
|
||||
}
|
||||
|
||||
public void LoadFromWeekdayMask(int mask)
|
||||
{
|
||||
var flags = (NotificationWeekdays)mask;
|
||||
|
||||
Monday = flags.HasFlag(NotificationWeekdays.Monday);
|
||||
Tuesday = flags.HasFlag(NotificationWeekdays.Tuesday);
|
||||
Wednesday = flags.HasFlag(NotificationWeekdays.Wednesday);
|
||||
Thursday = flags.HasFlag(NotificationWeekdays.Thursday);
|
||||
Friday = flags.HasFlag(NotificationWeekdays.Friday);
|
||||
Saturday = flags.HasFlag(NotificationWeekdays.Saturday);
|
||||
Sunday = flags.HasFlag(NotificationWeekdays.Sunday);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
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 Microsoft.Maui.Graphics;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
@@ -20,6 +18,8 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
private readonly CalendarStateService _calendarStateService;
|
||||
|
||||
private string _dateQuery = string.Empty;
|
||||
private string _statusQuery = string.Empty;
|
||||
private bool _commitFromNotification;
|
||||
private int? _entryId;
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -67,6 +67,9 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private ActivityPickerItemViewModel? selectedActivity;
|
||||
|
||||
[ObservableProperty]
|
||||
private TimeSpan activityDuration = TimeSpan.Zero;
|
||||
|
||||
[ObservableProperty]
|
||||
private DayPartOptionItemViewModel? selectedPart;
|
||||
|
||||
@@ -95,6 +98,7 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
public IAsyncRelayCommand SaveGrayCommand { get; }
|
||||
public IAsyncRelayCommand SaveCommand { get; }
|
||||
public IAsyncRelayCommand CancelCommand { get; }
|
||||
public IRelayCommand<SelectableSymptomItemViewModel> ToggleSymptomCommand { get; }
|
||||
|
||||
public QuickEntryViewModel(
|
||||
HealthEntryRepository healthEntryRepository,
|
||||
@@ -115,6 +119,7 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
SaveGrayCommand = new AsyncRelayCommand(() => SelectOrSaveAsync(HealthState.Gray));
|
||||
SaveCommand = new AsyncRelayCommand(SaveSelectedAsync);
|
||||
CancelCommand = new AsyncRelayCommand(CancelAsync);
|
||||
ToggleSymptomCommand = new RelayCommand<SelectableSymptomItemViewModel>(ToggleSymptom);
|
||||
}
|
||||
|
||||
partial void OnIsTodayChanged(bool value) => RaiseModeChanged();
|
||||
@@ -134,14 +139,22 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
OnPropertyChanged(nameof(SelectedStateSummaryText));
|
||||
}
|
||||
|
||||
public void ApplyQuery(string date, string entryId)
|
||||
public void ApplyQuery(string date, string? entryId, string? status, string? commit)
|
||||
{
|
||||
_dateQuery = date ?? string.Empty;
|
||||
_entryId = int.TryParse(entryId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedId)
|
||||
_statusQuery = status ?? string.Empty;
|
||||
_commitFromNotification = string.Equals(commit, "true", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
_entryId = int.TryParse(entryId, out var parsedId)
|
||||
? parsedId
|
||||
: null;
|
||||
}
|
||||
|
||||
public void ApplyQuery(string date, string? entryId)
|
||||
{
|
||||
ApplyQuery(date, entryId, null, null);
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
SelectedDate = DateTime.TryParseExact(
|
||||
@@ -156,15 +169,36 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
UpdateDateMode();
|
||||
SelectedDateText = DateHelper.ToGermanDateText(SelectedDate);
|
||||
|
||||
IsEditing = false;
|
||||
SelectedState = null;
|
||||
ActivityDuration = TimeSpan.Zero;
|
||||
|
||||
LoadAppearance();
|
||||
await LoadActivitiesAsync();
|
||||
await LoadSymptomsAsync();
|
||||
LoadDayParts();
|
||||
|
||||
SelectedActivity = Activities.FirstOrDefault();
|
||||
SelectedPart = Parts.FirstOrDefault(x => x.Value == DayPart.Morning) ?? Parts.FirstOrDefault();
|
||||
|
||||
foreach (var symptom in Symptoms)
|
||||
symptom.IsSelected = false;
|
||||
|
||||
if (_entryId.HasValue)
|
||||
{
|
||||
await LoadExistingEntryAsync();
|
||||
}
|
||||
else
|
||||
SelectedPart = Parts.FirstOrDefault(x => x.Value == DayPart.Morning);
|
||||
{
|
||||
if (TryParseNotificationState(_statusQuery, out var notificationState))
|
||||
SelectedState = notificationState;
|
||||
|
||||
if (_commitFromNotification && IsToday && TryParseNotificationState(_statusQuery, out var quickState))
|
||||
{
|
||||
await SaveAsync(quickState);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(ModeText));
|
||||
OnPropertyChanged(nameof(CanSave));
|
||||
@@ -192,8 +226,6 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
Name = item.Name
|
||||
});
|
||||
}
|
||||
|
||||
SelectedActivity ??= Activities.FirstOrDefault();
|
||||
}
|
||||
|
||||
private async Task LoadSymptomsAsync()
|
||||
@@ -246,6 +278,7 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
SelectedActivity = Activities.FirstOrDefault(x => x.Id == entry.ActivityId)
|
||||
?? Activities.FirstOrDefault();
|
||||
|
||||
ActivityDuration = TimeSpan.FromMinutes(entry.ActivityDurationMinutes ?? 0);
|
||||
SelectedState = entry.State;
|
||||
|
||||
var symptomIds = await _symptomRepository.GetSymptomIdsForEntryAsync(entry.Id);
|
||||
@@ -280,6 +313,7 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
return;
|
||||
|
||||
var activityId = SelectedActivity?.Id;
|
||||
var activityDurationMinutes = ParseActivityDurationMinutes();
|
||||
var symptomIds = Symptoms.Where(x => x.IsSelected).Select(x => x.Id).ToList();
|
||||
|
||||
if (IsEditing && _entryId.HasValue)
|
||||
@@ -289,6 +323,7 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
date: SelectedDate,
|
||||
state: state,
|
||||
activityId: activityId,
|
||||
activityDurationMinutes: activityDurationMinutes,
|
||||
symptomIds: symptomIds,
|
||||
part: IsPastDate ? SelectedPart?.Value ?? DayPart.Morning : null,
|
||||
source: IsPastDate ? EntrySource.Backfill : EntrySource.App);
|
||||
@@ -300,6 +335,7 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
part: SelectedPart?.Value ?? DayPart.Morning,
|
||||
state: state,
|
||||
activityId: activityId,
|
||||
activityDurationMinutes: activityDurationMinutes,
|
||||
symptomIds: symptomIds,
|
||||
source: EntrySource.Backfill);
|
||||
}
|
||||
@@ -308,6 +344,7 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
await _healthEntryRepository.AddQuickEntryAsync(
|
||||
state: state,
|
||||
activityId: activityId,
|
||||
activityDurationMinutes: activityDurationMinutes,
|
||||
symptomIds: symptomIds,
|
||||
timestamp: DateTime.Now,
|
||||
source: EntrySource.App);
|
||||
@@ -357,4 +394,51 @@ public partial class QuickEntryViewModel : ObservableObject
|
||||
HealthState.Gray => GrayStatusText,
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
private static bool TryParseNotificationState(string? value, out HealthState state)
|
||||
{
|
||||
switch ((value ?? string.Empty).Trim().ToLowerInvariant())
|
||||
{
|
||||
case "green":
|
||||
case "gruen":
|
||||
case "grün":
|
||||
state = HealthState.Green;
|
||||
return true;
|
||||
|
||||
case "yellow":
|
||||
case "gelb":
|
||||
state = HealthState.Yellow;
|
||||
return true;
|
||||
|
||||
case "red":
|
||||
case "rot":
|
||||
state = HealthState.Red;
|
||||
return true;
|
||||
|
||||
case "gray":
|
||||
case "grey":
|
||||
case "grau":
|
||||
case "schwarz":
|
||||
state = HealthState.Gray;
|
||||
return true;
|
||||
|
||||
default:
|
||||
state = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private int? ParseActivityDurationMinutes()
|
||||
{
|
||||
var minutes = (int)Math.Round(ActivityDuration.TotalMinutes, MidpointRounding.AwayFromZero);
|
||||
return minutes > 0 ? minutes : null;
|
||||
}
|
||||
|
||||
private void ToggleSymptom(SelectableSymptomItemViewModel? item)
|
||||
{
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
item.IsSelected = !item.IsSelected;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Maui.Graphics;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
|
||||
+35
-17
@@ -1,10 +1,10 @@
|
||||
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 Microsoft.Maui.Storage;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Maui.ApplicationModel;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
@@ -60,14 +60,19 @@ public partial class WeekViewModel : ObservableObject
|
||||
OpenDayCommand = new AsyncRelayCommand<WeekDaySummaryViewModel>(OpenDayAsync);
|
||||
|
||||
_calendarStateService.SelectedDateChanged += HandleSharedDateChanged;
|
||||
SelectedDate = _calendarStateService.SelectedDate;
|
||||
SelectedDate = _calendarStateService.SelectedDate.Date;
|
||||
UpdateHeader();
|
||||
}
|
||||
|
||||
partial void OnSelectedDateChanged(DateTime value)
|
||||
{
|
||||
UpdateHeader();
|
||||
}
|
||||
|
||||
public async Task RefreshAsync()
|
||||
{
|
||||
SelectedDate = _calendarStateService.SelectedDate;
|
||||
WeekStart = DateHelper.StartOfWeekMonday(SelectedDate);
|
||||
HeaderText = $"Woche {WeekStart:dd.MM.yyyy} - {WeekStart.AddDays(6):dd.MM.yyyy}";
|
||||
SelectedDate = _calendarStateService.SelectedDate.Date;
|
||||
UpdateHeader();
|
||||
|
||||
var entries = await _healthEntryRepository.GetEntriesBetweenAsync(WeekStart, WeekStart.AddDays(7));
|
||||
var activityMap = await _activityRepository.GetNameMapAsync();
|
||||
@@ -97,12 +102,19 @@ public partial class WeekViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHeader()
|
||||
{
|
||||
WeekStart = DateHelper.StartOfWeekMonday(SelectedDate.Date);
|
||||
HeaderText = $"Woche {WeekStart:dd.MM.yyyy} - {WeekStart.AddDays(6):dd.MM.yyyy}";
|
||||
}
|
||||
|
||||
private async Task OpenDayAsync(WeekDaySummaryViewModel? item)
|
||||
{
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
_calendarStateService.SelectedDate = item.Date;
|
||||
SelectedDate = item.Date.Date;
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await Shell.Current.GoToAsync("//day");
|
||||
}
|
||||
|
||||
@@ -114,25 +126,31 @@ public partial class WeekViewModel : ObservableObject
|
||||
|
||||
private async Task PreviousWeekAsync()
|
||||
{
|
||||
_calendarStateService.SelectedDate = DateHelper.StartOfWeekMonday(SelectedDate).AddDays(-7);
|
||||
SelectedDate = DateHelper.StartOfWeekMonday(SelectedDate).AddDays(-7);
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task NextWeekAsync()
|
||||
{
|
||||
_calendarStateService.SelectedDate = DateHelper.StartOfWeekMonday(SelectedDate).AddDays(7);
|
||||
SelectedDate = DateHelper.StartOfWeekMonday(SelectedDate).AddDays(7);
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task TodayAsync()
|
||||
{
|
||||
_calendarStateService.ResetToToday();
|
||||
await RefreshAsync();
|
||||
var today = DateTime.Today;
|
||||
SelectedDate = today;
|
||||
_calendarStateService.SelectedDate = today;
|
||||
await Shell.Current.GoToAsync("//day");
|
||||
}
|
||||
|
||||
private async void HandleSharedDateChanged(DateTime date)
|
||||
private void HandleSharedDateChanged(DateTime date)
|
||||
{
|
||||
SelectedDate = date;
|
||||
await RefreshAsync();
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
SelectedDate = date.Date;
|
||||
await RefreshAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
-15
@@ -1,9 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using cfs_tracker.Data;
|
||||
using cfs_tracker.Helpers;
|
||||
using cfs_tracker.Services;
|
||||
using Microsoft.Maui.Storage;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
@@ -50,13 +49,19 @@ public partial class YearViewModel : ObservableObject
|
||||
OpenDayCommand = new AsyncRelayCommand<MonthCellViewModel>(OpenDayAsync);
|
||||
|
||||
_calendarStateService.SelectedDateChanged += HandleSharedDateChanged;
|
||||
SelectedDate = _calendarStateService.SelectedDate;
|
||||
SelectedDate = _calendarStateService.SelectedDate.Date;
|
||||
UpdateHeader();
|
||||
}
|
||||
|
||||
partial void OnSelectedDateChanged(DateTime value)
|
||||
{
|
||||
UpdateHeader();
|
||||
}
|
||||
|
||||
public async Task RefreshAsync()
|
||||
{
|
||||
SelectedDate = _calendarStateService.SelectedDate;
|
||||
HeaderText = DateHelper.ToGermanYear(SelectedDate);
|
||||
SelectedDate = _calendarStateService.SelectedDate.Date;
|
||||
UpdateHeader();
|
||||
|
||||
var yearStart = new DateTime(SelectedDate.Year, 1, 1);
|
||||
var yearEnd = yearStart.AddYears(1);
|
||||
@@ -99,12 +104,19 @@ public partial class YearViewModel : ObservableObject
|
||||
Months.Add(section);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHeader()
|
||||
{
|
||||
HeaderText = DateHelper.ToGermanYear(SelectedDate);
|
||||
}
|
||||
|
||||
private async Task OpenDayAsync(MonthCellViewModel? item)
|
||||
{
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
_calendarStateService.SelectedDate = item.Date;
|
||||
SelectedDate = item.Date.Date;
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await Shell.Current.GoToAsync("//day");
|
||||
}
|
||||
|
||||
@@ -116,25 +128,32 @@ public partial class YearViewModel : ObservableObject
|
||||
|
||||
private async Task PreviousYearAsync()
|
||||
{
|
||||
_calendarStateService.SelectedDate = new DateTime(SelectedDate.Year - 1, SelectedDate.Month, 1);
|
||||
SelectedDate = new DateTime(SelectedDate.Year - 1, SelectedDate.Month, 1);
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task NextYearAsync()
|
||||
{
|
||||
_calendarStateService.SelectedDate = new DateTime(SelectedDate.Year + 1, SelectedDate.Month, 1);
|
||||
SelectedDate = new DateTime(SelectedDate.Year + 1, SelectedDate.Month, 1);
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task TodayAsync()
|
||||
{
|
||||
_calendarStateService.ResetToToday();
|
||||
await RefreshAsync();
|
||||
var today = DateTime.Today;
|
||||
SelectedDate = today;
|
||||
_calendarStateService.SelectedDate = today;
|
||||
await Shell.Current.GoToAsync("//day");
|
||||
}
|
||||
|
||||
private async void HandleSharedDateChanged(DateTime date)
|
||||
private void HandleSharedDateChanged(DateTime date)
|
||||
{
|
||||
SelectedDate = date;
|
||||
await RefreshAsync();
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
SelectedDate = date.Date;
|
||||
await RefreshAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user