Layout and Push Fix
This commit is contained in:
@@ -9,12 +9,11 @@ public partial class MonthCellViewModel : ObservableObject
|
||||
public bool IsCurrentMonth { get; init; }
|
||||
public bool IsToday { get; init; }
|
||||
public bool HasEntries { get; init; }
|
||||
public string AverageStateText { get; init; } = string.Empty;
|
||||
public Color StateColor { get; init; } = Colors.Transparent;
|
||||
|
||||
public Color BackgroundColor { get; init; } = Colors.Transparent;
|
||||
public Color TextColor { get; init; } = Colors.White;
|
||||
public Color BorderColor { get; init; } = Colors.Transparent;
|
||||
|
||||
public bool IsPlaceholder => !IsCurrentMonth;
|
||||
public bool ShowDayNumber => IsCurrentMonth;
|
||||
public bool ShowAverage => IsCurrentMonth && HasEntries;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
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 Microsoft.Maui.ApplicationModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
@@ -13,7 +13,6 @@ public partial class MonthViewModel : ObservableObject
|
||||
{
|
||||
private readonly HealthEntryRepository _healthEntryRepository;
|
||||
private readonly AppearanceService _appearanceService;
|
||||
private readonly AggregationService _aggregationService;
|
||||
private readonly CalendarStateService _calendarStateService;
|
||||
private readonly IPdfExportService _pdfExportService;
|
||||
|
||||
@@ -34,13 +33,11 @@ public partial class MonthViewModel : ObservableObject
|
||||
public MonthViewModel(
|
||||
HealthEntryRepository healthEntryRepository,
|
||||
AppearanceService appearanceService,
|
||||
AggregationService aggregationService,
|
||||
CalendarStateService calendarStateService,
|
||||
IPdfExportService pdfExportService)
|
||||
{
|
||||
_healthEntryRepository = healthEntryRepository;
|
||||
_appearanceService = appearanceService;
|
||||
_aggregationService = aggregationService;
|
||||
_calendarStateService = calendarStateService;
|
||||
_pdfExportService = pdfExportService;
|
||||
|
||||
@@ -80,7 +77,7 @@ public partial class MonthViewModel : ObservableObject
|
||||
{
|
||||
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);
|
||||
var worstState = CalculateWorstState(dayEntries);
|
||||
|
||||
Cells.Add(new MonthCellViewModel
|
||||
{
|
||||
@@ -89,9 +86,8 @@ public partial class MonthViewModel : ObservableObject
|
||||
IsCurrentMonth = true,
|
||||
IsToday = date.Date == DateTime.Today,
|
||||
HasEntries = dayEntries.Count > 0,
|
||||
AverageStateText = _aggregationService.ToDisplayText(average, _appearanceService),
|
||||
StateColor = _appearanceService.GetColor(average.State.ToAppearanceColorKey(), "#1F242B"),
|
||||
TextColor = _appearanceService.GetColor(AppearanceKeys.TextPrimary, "#DCE7F3"),
|
||||
BackgroundColor = GetCellBackgroundColor(worstState),
|
||||
TextColor = GetCellTextColor(worstState),
|
||||
BorderColor = date.Date == DateTime.Today
|
||||
? _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42")
|
||||
: _appearanceService.GetColor(AppearanceKeys.Border, "#2A3E55")
|
||||
@@ -154,11 +150,46 @@ public partial class MonthViewModel : ObservableObject
|
||||
});
|
||||
}
|
||||
|
||||
private Color GetCellBackgroundColor(HealthState? state) => state switch
|
||||
{
|
||||
HealthState.Green => _appearanceService.GetColor(AppearanceKeys.StateGreen, "#4E8B69"),
|
||||
HealthState.Yellow => _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42"),
|
||||
HealthState.Red => _appearanceService.GetColor(AppearanceKeys.StateRed, "#A85C5C"),
|
||||
HealthState.Gray => _appearanceService.GetColor(AppearanceKeys.StateGray, "#1F242B"),
|
||||
_ => _appearanceService.GetColor(AppearanceKeys.SurfaceBackgroundAlt, "#1F242B")
|
||||
};
|
||||
|
||||
private Color GetCellTextColor(HealthState? state) => state switch
|
||||
{
|
||||
HealthState.Yellow => Colors.Black,
|
||||
HealthState.Green => Colors.White,
|
||||
HealthState.Red => Colors.White,
|
||||
HealthState.Gray => Colors.White,
|
||||
_ => _appearanceService.GetColor(AppearanceKeys.TextPrimary, "#DCE7F3")
|
||||
};
|
||||
|
||||
private static int GetMondayBasedColumnIndex(DayOfWeek dayOfWeek)
|
||||
{
|
||||
return dayOfWeek == DayOfWeek.Sunday ? 6 : ((int)dayOfWeek - 1);
|
||||
}
|
||||
|
||||
private static HealthState? CalculateWorstState(IReadOnlyCollection<HealthEntry> entries)
|
||||
{
|
||||
if (entries.Count == 0)
|
||||
return null;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Gray))
|
||||
return HealthState.Gray;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Red))
|
||||
return HealthState.Red;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Yellow))
|
||||
return HealthState.Yellow;
|
||||
|
||||
return HealthState.Green;
|
||||
}
|
||||
|
||||
private static MonthCellViewModel CreatePlaceholderCell()
|
||||
{
|
||||
return new MonthCellViewModel
|
||||
@@ -168,10 +199,9 @@ public partial class MonthViewModel : ObservableObject
|
||||
IsCurrentMonth = false,
|
||||
IsToday = false,
|
||||
HasEntries = false,
|
||||
AverageStateText = string.Empty,
|
||||
StateColor = Colors.Transparent,
|
||||
BackgroundColor = Colors.Transparent,
|
||||
TextColor = Colors.Transparent,
|
||||
BorderColor = Colors.Transparent
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,9 @@ public partial class NotificationScheduleItemViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool sunday;
|
||||
|
||||
public string IsEnabledButtonText => IsEnabled ? "Aktiv" : "Inaktiv";
|
||||
|
||||
public IRelayCommand ToggleIsEnabledCommand { get; }
|
||||
public IRelayCommand ToggleMondayCommand { get; }
|
||||
public IRelayCommand ToggleTuesdayCommand { get; }
|
||||
public IRelayCommand ToggleWednesdayCommand { get; }
|
||||
@@ -45,6 +48,7 @@ public partial class NotificationScheduleItemViewModel : ObservableObject
|
||||
|
||||
public NotificationScheduleItemViewModel()
|
||||
{
|
||||
ToggleIsEnabledCommand = new RelayCommand(() => IsEnabled = !IsEnabled);
|
||||
ToggleMondayCommand = new RelayCommand(() => Monday = !Monday);
|
||||
ToggleTuesdayCommand = new RelayCommand(() => Tuesday = !Tuesday);
|
||||
ToggleWednesdayCommand = new RelayCommand(() => Wednesday = !Wednesday);
|
||||
@@ -54,6 +58,11 @@ public partial class NotificationScheduleItemViewModel : ObservableObject
|
||||
ToggleSundayCommand = new RelayCommand(() => Sunday = !Sunday);
|
||||
}
|
||||
|
||||
partial void OnIsEnabledChanged(bool value)
|
||||
{
|
||||
OnPropertyChanged(nameof(IsEnabledButtonText));
|
||||
}
|
||||
|
||||
public int ToWeekdayMask()
|
||||
{
|
||||
var mask = NotificationWeekdays.None;
|
||||
|
||||
@@ -58,6 +58,8 @@ public partial class OptionsViewModel : ObservableObject
|
||||
public bool IsNotificationsTabSelected => SelectedTab == OptionsTab.Notifications;
|
||||
public bool IsDataManagementTabSelected => SelectedTab == OptionsTab.DataManagement;
|
||||
|
||||
public string NotificationVibrationButtonText => NotificationVibrationEnabled ? "Aktiv" : "Inaktiv";
|
||||
|
||||
public IAsyncRelayCommand DeleteAllDataCommand { get; }
|
||||
public IAsyncRelayCommand SaveAppearanceCommand { get; }
|
||||
public IAsyncRelayCommand ResetAppearanceCommand { get; }
|
||||
@@ -74,6 +76,7 @@ public partial class OptionsViewModel : ObservableObject
|
||||
public IAsyncRelayCommand<NotificationScheduleItemViewModel> DeleteScheduleCommand { get; }
|
||||
public IAsyncRelayCommand SaveDatabaseLocationCommand { get; }
|
||||
public IAsyncRelayCommand ClearExportsCommand { get; }
|
||||
public IRelayCommand ToggleNotificationVibrationCommand { get; }
|
||||
public IRelayCommand ShowAppearanceTabCommand { get; }
|
||||
public IRelayCommand ShowNotificationsTabCommand { get; }
|
||||
public IRelayCommand ShowDataManagementTabCommand { get; }
|
||||
@@ -118,6 +121,11 @@ public partial class OptionsViewModel : ObservableObject
|
||||
SaveDatabaseLocationCommand = new AsyncRelayCommand(SaveDatabaseLocationAsync);
|
||||
ClearExportsCommand = new AsyncRelayCommand(ClearExportsAsync);
|
||||
|
||||
ToggleNotificationVibrationCommand = new RelayCommand(() =>
|
||||
{
|
||||
NotificationVibrationEnabled = !NotificationVibrationEnabled;
|
||||
});
|
||||
|
||||
ShowAppearanceTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Appearance);
|
||||
ShowNotificationsTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Notifications);
|
||||
ShowDataManagementTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.DataManagement);
|
||||
@@ -135,6 +143,11 @@ public partial class OptionsViewModel : ObservableObject
|
||||
OnPropertyChanged(nameof(IsDataManagementTabSelected));
|
||||
}
|
||||
|
||||
partial void OnNotificationVibrationEnabledChanged(bool value)
|
||||
{
|
||||
OnPropertyChanged(nameof(NotificationVibrationButtonText));
|
||||
}
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
await LoadAppearanceAsync();
|
||||
@@ -447,7 +460,10 @@ public partial class OptionsViewModel : ObservableObject
|
||||
var granted = await _notificationScheduler.EnsurePermissionAsync();
|
||||
if (!granted)
|
||||
{
|
||||
StatusText = "Benachrichtigungsberechtigung wurde nicht erlaubt.";
|
||||
StatusText = OperatingSystem.IsAndroidVersionAtLeast(31)
|
||||
? "Bitte Benachrichtigungen und exakte Alarme erlauben und danach erneut speichern."
|
||||
: "Benachrichtigungsberechtigung wurde nicht erlaubt.";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -530,4 +546,4 @@ public partial class OptionsViewModel : ObservableObject
|
||||
Notifications,
|
||||
DataManagement
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,17 +85,20 @@ public partial class WeekViewModel : ObservableObject
|
||||
var date = WeekStart.AddDays(i);
|
||||
var dayEntries = entries.Where(x => x.EntryDate.Date == date.Date).ToList();
|
||||
|
||||
var morningAverage = _aggregationService.CalculateAverage(_aggregationService.FilterForDayPart(dayEntries, DayPart.Morning));
|
||||
var afternoonAverage = _aggregationService.CalculateAverage(_aggregationService.FilterForDayPart(dayEntries, DayPart.Afternoon));
|
||||
var morningEntries = _aggregationService.FilterForDayPart(dayEntries, DayPart.Morning).ToList();
|
||||
var afternoonEntries = _aggregationService.FilterForDayPart(dayEntries, DayPart.Afternoon).ToList();
|
||||
|
||||
var morningWorstState = CalculateWorstState(morningEntries);
|
||||
var afternoonWorstState = CalculateWorstState(afternoonEntries);
|
||||
|
||||
Days.Add(new WeekDaySummaryViewModel
|
||||
{
|
||||
Date = date,
|
||||
DateText = DateHelper.ToGermanShortDay(date),
|
||||
MorningText = _aggregationService.ToDisplayText(morningAverage, _appearanceService),
|
||||
AfternoonText = _aggregationService.ToDisplayText(afternoonAverage, _appearanceService),
|
||||
MorningColor = _appearanceService.GetColor(morningAverage.State.ToAppearanceColorKey(), "#1F242B"),
|
||||
AfternoonColor = _appearanceService.GetColor(afternoonAverage.State.ToAppearanceColorKey(), "#1F242B"),
|
||||
MorningText = GetStateText(morningWorstState),
|
||||
AfternoonText = GetStateText(afternoonWorstState),
|
||||
MorningColor = GetStateColor(morningWorstState),
|
||||
AfternoonColor = GetStateColor(afternoonWorstState),
|
||||
ActivitiesText = _aggregationService.BuildDistinctActivityText(dayEntries, activityMap),
|
||||
SymptomsText = _aggregationService.BuildDistinctSymptomText(dayEntries, symptomsMap)
|
||||
});
|
||||
@@ -137,6 +140,7 @@ public partial class WeekViewModel : ObservableObject
|
||||
_calendarStateService.SelectedDate = SelectedDate;
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task TodayAsync()
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
@@ -153,4 +157,37 @@ public partial class WeekViewModel : ObservableObject
|
||||
await RefreshAsync();
|
||||
});
|
||||
}
|
||||
|
||||
private string GetStateText(HealthState? state) => state switch
|
||||
{
|
||||
HealthState.Green => _appearanceService.GetText(AppearanceKeys.StatusGreenText, "Grün"),
|
||||
HealthState.Yellow => _appearanceService.GetText(AppearanceKeys.StatusYellowText, "Gelb"),
|
||||
HealthState.Red => _appearanceService.GetText(AppearanceKeys.StatusRedText, "Rot"),
|
||||
HealthState.Gray => _appearanceService.GetText(AppearanceKeys.StatusGrayText, "Schwarz"),
|
||||
_ => "-"
|
||||
};
|
||||
|
||||
private Color GetStateColor(HealthState? state)
|
||||
{
|
||||
return state.HasValue
|
||||
? _appearanceService.GetColor(state.Value.ToAppearanceColorKey(), "#1F242B")
|
||||
: Colors.Transparent;
|
||||
}
|
||||
|
||||
private static HealthState? CalculateWorstState(IReadOnlyCollection<HealthEntry> entries)
|
||||
{
|
||||
if (entries.Count == 0)
|
||||
return null;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Gray))
|
||||
return HealthState.Gray;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Red))
|
||||
return HealthState.Red;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Yellow))
|
||||
return HealthState.Yellow;
|
||||
|
||||
return HealthState.Green;
|
||||
}
|
||||
}
|
||||
+43
-13
@@ -1,11 +1,11 @@
|
||||
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 Microsoft.Maui.ApplicationModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace cfs_tracker.ViewModels;
|
||||
|
||||
@@ -13,7 +13,6 @@ public partial class YearViewModel : ObservableObject
|
||||
{
|
||||
private readonly HealthEntryRepository _healthEntryRepository;
|
||||
private readonly AppearanceService _appearanceService;
|
||||
private readonly AggregationService _aggregationService;
|
||||
private readonly CalendarStateService _calendarStateService;
|
||||
private readonly IPdfExportService _pdfExportService;
|
||||
|
||||
@@ -34,13 +33,11 @@ public partial class YearViewModel : ObservableObject
|
||||
public YearViewModel(
|
||||
HealthEntryRepository healthEntryRepository,
|
||||
AppearanceService appearanceService,
|
||||
AggregationService aggregationService,
|
||||
CalendarStateService calendarStateService,
|
||||
IPdfExportService pdfExportService)
|
||||
{
|
||||
_healthEntryRepository = healthEntryRepository;
|
||||
_appearanceService = appearanceService;
|
||||
_aggregationService = aggregationService;
|
||||
_calendarStateService = calendarStateService;
|
||||
_pdfExportService = pdfExportService;
|
||||
|
||||
@@ -78,7 +75,7 @@ public partial class YearViewModel : ObservableObject
|
||||
|
||||
var section = new MonthSectionViewModel
|
||||
{
|
||||
Title = DateHelper.ToGermanMonthYear(monthStart)
|
||||
Title = monthStart.ToString("MMMM")
|
||||
};
|
||||
|
||||
var leadingEmptyCells = GetMondayBasedColumnIndex(monthStart.DayOfWeek);
|
||||
@@ -89,7 +86,7 @@ public partial class YearViewModel : ObservableObject
|
||||
{
|
||||
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);
|
||||
var worstState = CalculateWorstState(dayEntries);
|
||||
|
||||
section.Cells.Add(new MonthCellViewModel
|
||||
{
|
||||
@@ -98,9 +95,8 @@ public partial class YearViewModel : ObservableObject
|
||||
IsCurrentMonth = true,
|
||||
IsToday = date.Date == DateTime.Today,
|
||||
HasEntries = dayEntries.Count > 0,
|
||||
AverageStateText = _aggregationService.ToDisplayText(average, _appearanceService),
|
||||
StateColor = _appearanceService.GetColor(average.State.ToAppearanceColorKey(), "#1F242B"),
|
||||
TextColor = _appearanceService.GetColor(AppearanceKeys.TextPrimary, "#DCE7F3"),
|
||||
BackgroundColor = GetCellBackgroundColor(worstState),
|
||||
TextColor = GetCellTextColor(worstState),
|
||||
BorderColor = date.Date == DateTime.Today
|
||||
? _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42")
|
||||
: _appearanceService.GetColor(AppearanceKeys.Border, "#2A3E55")
|
||||
@@ -116,7 +112,7 @@ public partial class YearViewModel : ObservableObject
|
||||
|
||||
private void UpdateHeader()
|
||||
{
|
||||
HeaderText = DateHelper.ToGermanYear(SelectedDate);
|
||||
HeaderText = SelectedDate.Year.ToString();
|
||||
}
|
||||
|
||||
private async Task OpenDayAsync(MonthCellViewModel? item)
|
||||
@@ -166,11 +162,46 @@ public partial class YearViewModel : ObservableObject
|
||||
});
|
||||
}
|
||||
|
||||
private Color GetCellBackgroundColor(HealthState? state) => state switch
|
||||
{
|
||||
HealthState.Green => _appearanceService.GetColor(AppearanceKeys.StateGreen, "#4E8B69"),
|
||||
HealthState.Yellow => _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42"),
|
||||
HealthState.Red => _appearanceService.GetColor(AppearanceKeys.StateRed, "#A85C5C"),
|
||||
HealthState.Gray => _appearanceService.GetColor(AppearanceKeys.StateGray, "#1F242B"),
|
||||
_ => _appearanceService.GetColor(AppearanceKeys.SurfaceBackgroundAlt, "#1F242B")
|
||||
};
|
||||
|
||||
private Color GetCellTextColor(HealthState? state) => state switch
|
||||
{
|
||||
HealthState.Yellow => Colors.Black,
|
||||
HealthState.Green => Colors.White,
|
||||
HealthState.Red => Colors.White,
|
||||
HealthState.Gray => Colors.White,
|
||||
_ => _appearanceService.GetColor(AppearanceKeys.TextPrimary, "#DCE7F3")
|
||||
};
|
||||
|
||||
private static int GetMondayBasedColumnIndex(DayOfWeek dayOfWeek)
|
||||
{
|
||||
return dayOfWeek == DayOfWeek.Sunday ? 6 : ((int)dayOfWeek - 1);
|
||||
}
|
||||
|
||||
private static HealthState? CalculateWorstState(IReadOnlyCollection<HealthEntry> entries)
|
||||
{
|
||||
if (entries.Count == 0)
|
||||
return null;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Gray))
|
||||
return HealthState.Gray;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Red))
|
||||
return HealthState.Red;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Yellow))
|
||||
return HealthState.Yellow;
|
||||
|
||||
return HealthState.Green;
|
||||
}
|
||||
|
||||
private static MonthCellViewModel CreatePlaceholderCell()
|
||||
{
|
||||
return new MonthCellViewModel
|
||||
@@ -180,10 +211,9 @@ public partial class YearViewModel : ObservableObject
|
||||
IsCurrentMonth = false,
|
||||
IsToday = false,
|
||||
HasEntries = false,
|
||||
AverageStateText = string.Empty,
|
||||
StateColor = Colors.Transparent,
|
||||
BackgroundColor = Colors.Transparent,
|
||||
TextColor = Colors.Transparent,
|
||||
BorderColor = Colors.Transparent
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user