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,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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user