small bug fixes

This commit is contained in:
2026-10-11 22:19:34 +02:00
parent c6391a384c
commit 4af7385804
36 changed files with 1558 additions and 399 deletions
+3 -2
View File
@@ -1,3 +1,4 @@
using cfs_tracker.Services;
using CommunityToolkit.Mvvm.ComponentModel;
namespace cfs_tracker.ViewModels;
@@ -15,6 +16,6 @@ public partial class ActivityManageItemViewModel : ObservableObject
public bool IsUsed { get; init; }
public string UsageHint => IsUsed
? "Bereits verwendet – kann nur deaktiviert werden."
: "Kann gelöscht werden, solange unbenutzt.";
? LocalizationService.Translate("Options_UsageHint_Used")
: LocalizationService.Translate("Options_UsageHint_Unused");
}
+8 -2
View File
@@ -1,3 +1,4 @@
using cfs_tracker.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -20,7 +21,12 @@ public partial class DayEntryItemViewModel : ObservableObject
public bool HasDuration => !string.IsNullOrWhiteSpace(DurationText);
public bool HasSymptoms => !string.IsNullOrWhiteSpace(SymptomsText);
public bool HasDetails => HasActivity || HasDuration || HasSymptoms;
public string DetailsButtonText => IsExpanded ? "Details ausblenden" : "Details anzeigen";
public string DetailsButtonText => IsExpanded
? LocalizationService.Translate("DayPage_DetailsHide")
: LocalizationService.Translate("DayPage_DetailsShow");
public string ActivitySummaryText => LocalizationService.Format("DayPage_ActivityFormat", ActivityText);
public string DurationSummaryText => LocalizationService.Format("DayPage_DurationFormat", DurationText);
public string SymptomsSummaryText => LocalizationService.Format("DayPage_SymptomsFormat", SymptomsText);
[ObservableProperty]
private bool isExpanded;
@@ -44,4 +50,4 @@ public partial class DayEntryItemViewModel : ObservableObject
IsExpanded = !IsExpanded;
}
}
}
+31 -20
View File
@@ -46,16 +46,16 @@ public partial class DayViewModel : ObservableObject
private int grayCount;
[ObservableProperty]
private string greenStatusText = "Grün";
private string greenStatusText = "Green";
[ObservableProperty]
private string yellowStatusText = "Gelb";
private string yellowStatusText = "Yellow";
[ObservableProperty]
private string redStatusText = "Rot";
private string redStatusText = "Red";
[ObservableProperty]
private string grayStatusText = "Schwarz";
private string grayStatusText = "Black";
[ObservableProperty]
private Color greenStateColor = Color.FromArgb("#4E8B69");
@@ -82,15 +82,18 @@ public partial class DayViewModel : ObservableObject
public string RedCounterText => BuildCounterText(RedStatusText, RedCount);
public string GrayCounterText => BuildCounterText(GrayStatusText, GrayCount);
public string AddEntryButtonText => IsPastDate ? "+ Nachtrag" : "+ Eintrag";
public string AddEntryButtonText => IsPastDate
? LocalizationService.Translate("DayPage_AddBackfillButton")
: LocalizationService.Translate("DayPage_AddEntryButton");
public bool CanAddEntry => !IsFutureDate;
public bool HasNoEntries => !HasEntries;
public string DayHintText => IsToday
? "Heute kannst du Schnellstatus oder einen Eintrag mit Tätigkeit und Symptomen setzen."
? LocalizationService.Translate("DayPage_HintToday")
: IsPastDate
? "Für vergangene Tage legst du einen Nachtrag für Vormittag oder Nachmittag an."
: "Für zukünftige Tage sind keine Einträge möglich.";
? LocalizationService.Translate("DayPage_HintPast")
: LocalizationService.Translate("DayPage_HintFuture");
public IAsyncRelayCommand PreviousDayCommand { get; }
public IAsyncRelayCommand NextDayCommand { get; }
@@ -181,15 +184,15 @@ public partial class DayViewModel : ObservableObject
{
var slotText = entry.DayPart switch
{
DayPart.Morning => "Vormittag",
DayPart.Afternoon => "Nachmittag",
DayPart.Morning => LocalizationService.Translate("Common_Morning"),
DayPart.Afternoon => LocalizationService.Translate("Common_Afternoon"),
_ => entry.Timestamp.ToString("HH:mm", CultureInfo.InvariantCulture)
};
var activityText = string.Empty;
if (entry.ActivityId.HasValue &&
activityMap.TryGetValue(entry.ActivityId.Value, out var activityName) &&
!string.Equals(activityName, "Keine Tätigkeit", StringComparison.OrdinalIgnoreCase))
!LocalizationService.IsNoActivityLabel(activityName))
{
activityText = activityName;
}
@@ -267,10 +270,10 @@ public partial class DayViewModel : ObservableObject
return;
var accepted = await Application.Current!.Windows[0].Page!.DisplayAlertAsync(
"Eintrag löschen",
"Soll dieser Eintrag wirklich gelöscht werden?",
"Ja",
"Nein");
LocalizationService.Translate("DayPage_DeleteAlert_Title"),
LocalizationService.Translate("DayPage_DeleteAlert_Message"),
LocalizationService.Translate("Common_Yes"),
LocalizationService.Translate("Common_No"));
if (!accepted)
return;
@@ -324,10 +327,18 @@ public partial class DayViewModel : ObservableObject
private void LoadAppearance()
{
GreenStatusText = _appearanceService.GetText(AppearanceKeys.StatusGreenText, "Grün");
YellowStatusText = _appearanceService.GetText(AppearanceKeys.StatusYellowText, "Gelb");
RedStatusText = _appearanceService.GetText(AppearanceKeys.StatusRedText, "Rot");
GrayStatusText = _appearanceService.GetText(AppearanceKeys.StatusGrayText, "Schwarz");
GreenStatusText = _appearanceService.GetText(
AppearanceKeys.StatusGreenText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusGreenText));
YellowStatusText = _appearanceService.GetText(
AppearanceKeys.StatusYellowText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusYellowText));
RedStatusText = _appearanceService.GetText(
AppearanceKeys.StatusRedText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusRedText));
GrayStatusText = _appearanceService.GetText(
AppearanceKeys.StatusGrayText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusGrayText));
GreenStateColor = _appearanceService.GetColor(AppearanceKeys.StateGreen, "#4E8B69");
YellowStateColor = _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42");
@@ -352,4 +363,4 @@ public partial class DayViewModel : ObservableObject
}
private static string BuildCounterText(string label, int count) => $"{label}\n{count}";
}
}
@@ -0,0 +1,8 @@
namespace cfs_tracker.ViewModels;
public class LanguageOptionItemViewModel
{
public string Code { get; init; } = string.Empty;
public string DisplayName { get; init; } = string.Empty;
}
+27 -2
View File
@@ -1,9 +1,34 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;
namespace cfs_tracker.ViewModels;
public class MonthSectionViewModel
public partial class MonthSectionViewModel : ObservableObject
{
public string Title { get; init; } = string.Empty;
private string _title = string.Empty;
private bool _isLoading = true;
public string Title
{
get => _title;
set => SetProperty(ref _title, value);
}
public bool IsLoading
{
get => _isLoading;
set => SetProperty(ref _isLoading, value);
}
public ObservableCollection<MonthCellViewModel> Cells { get; } = new();
public void ReplaceCells(IEnumerable<MonthCellViewModel> cells)
{
Cells.Clear();
foreach (var cell in cells)
Cells.Add(cell);
IsLoading = false;
}
}
+1 -1
View File
@@ -204,4 +204,4 @@ public partial class MonthViewModel : ObservableObject
BorderColor = Colors.Transparent
};
}
}
}
@@ -1,4 +1,5 @@
using cfs_tracker.Models;
using cfs_tracker.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -35,7 +36,9 @@ public partial class NotificationScheduleItemViewModel : ObservableObject
[ObservableProperty]
private bool sunday;
public string IsEnabledButtonText => IsEnabled ? "Aktiv" : "Inaktiv";
public string IsEnabledButtonText => IsEnabled
? LocalizationService.Translate("Common_Active")
: LocalizationService.Translate("Common_Inactive");
public IRelayCommand ToggleIsEnabledCommand { get; }
public IRelayCommand ToggleMondayCommand { get; }
@@ -90,4 +93,4 @@ public partial class NotificationScheduleItemViewModel : ObservableObject
Saturday = flags.HasFlag(NotificationWeekdays.Saturday);
Sunday = flags.HasFlag(NotificationWeekdays.Sunday);
}
}
}
+223 -83
View File
@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
namespace cfs_tracker.ViewModels;
@@ -14,6 +15,7 @@ public partial class OptionsViewModel : ObservableObject
private readonly HealthEntryRepository _healthEntryRepository;
private readonly AppearanceRepository _appearanceRepository;
private readonly AppearanceService _appearanceService;
private readonly LocalizationService _localizationService;
private readonly ActivityRepository _activityRepository;
private readonly SymptomRepository _symptomRepository;
private readonly NotificationScheduleRepository _notificationScheduleRepository;
@@ -64,8 +66,15 @@ public partial class OptionsViewModel : ObservableObject
[ObservableProperty]
private bool isExportSymptomFilterExpanded;
[ObservableProperty]
private LanguageOptionItemViewModel? selectedLanguageOption;
[ObservableProperty]
private bool requiresShellReload;
public ObservableCollection<AppearanceColorItemViewModel> AppearanceColors { get; } = new();
public ObservableCollection<AppearanceTextItemViewModel> StatusTexts { get; } = new();
public ObservableCollection<LanguageOptionItemViewModel> LanguageOptions { get; } = new();
public ObservableCollection<ActivityManageItemViewModel> Activities { get; } = new();
public ObservableCollection<SymptomManageItemViewModel> Symptoms { get; } = new();
public ObservableCollection<NotificationScheduleItemViewModel> NotificationSchedules { get; } = new();
@@ -78,7 +87,18 @@ public partial class OptionsViewModel : ObservableObject
public bool IsExportTabSelected => SelectedTab == OptionsTab.Export;
public bool IsLegalTabSelected => SelectedTab == OptionsTab.Legal;
public string NotificationVibrationButtonText => NotificationVibrationEnabled ? "Aktiv" : "Inaktiv";
public string NotificationVibrationButtonText => NotificationVibrationEnabled
? LocalizationService.Translate("Common_Active")
: LocalizationService.Translate("Common_Inactive");
public string CurrentDatabasePathText => LocalizationService.Format("Options_Database_CurrentPathFormat", CurrentDatabasePath);
public string SelectedLanguageDescription => SelectedLanguageOption?.Code == LocalizationService.SystemLanguageCode
? LocalizationService.Format("Options_Language_SystemHint", _localizationService.GetSystemLanguageDisplayName())
: LocalizationService.Format(
"Options_Language_SelectedHint",
SelectedLanguageOption?.DisplayName ?? _localizationService.GetLanguageDisplayName(_localizationService.SelectedLanguageCode));
public bool IsDayViewExportLayoutSelected => SelectedExportLayout == ExportLayout.DayView;
public bool IsWeekBlockExportLayoutSelected => SelectedExportLayout == ExportLayout.WeekBlock;
public bool IsDaySummaryExportLayoutSelected => SelectedExportLayout == ExportLayout.DaySummary;
@@ -92,16 +112,16 @@ public partial class OptionsViewModel : ObservableObject
var totalDays = (end - start).Days + 1;
return totalDays == 1
? $"1 Tag ausgewählt: {start:dd.MM.yyyy}"
: $"{totalDays} Tage ausgewählt: {start:dd.MM.yyyy} bis {end:dd.MM.yyyy}";
? LocalizationService.Format("Options_Export_RangeSingleFormat", FormatShortDate(start))
: LocalizationService.Format("Options_Export_RangeMultipleFormat", totalDays, FormatShortDate(start), FormatShortDate(end));
}
}
public string SelectedExportLayoutDescription => SelectedExportLayout switch
{
ExportLayout.DayView => "Tagesansicht: Jeder Tag wird mit allen einzelnen Einträgen, Tätigkeiten, Dauer und Symptomen exportiert.",
ExportLayout.WeekBlock => "Wochenblock: Pro Tag werden Vormittag und Nachmittag mit Status, T\u00e4tigkeiten, Gesamtdauer und Symptomen dargestellt.",
_ => "Tageszusammenfassung: Jeder Tag erscheint kompakt in einer Zeile, ähnlich wie bei Monats- und Jahresexporten."
ExportLayout.DayView => LocalizationService.Translate("Options_Export_LayoutDescription_DayView"),
ExportLayout.WeekBlock => LocalizationService.Translate("Options_Export_LayoutDescription_WeekBlock"),
_ => LocalizationService.Translate("Options_Export_LayoutDescription_DaySummary")
};
public string ExportFilterSummary
@@ -111,7 +131,7 @@ public partial class OptionsViewModel : ObservableObject
var parts = new List<string>();
if (SelectedExportActivity?.Id is int)
parts.Add($"T\u00e4tigkeit: {SelectedExportActivity.Name}");
parts.Add(LocalizationService.Format("Options_Export_Filter_ActivityFormat", SelectedExportActivity.Name));
var selectedSymptoms = ExportSymptoms
.Where(x => x.IsSelected)
@@ -120,11 +140,11 @@ public partial class OptionsViewModel : ObservableObject
.ToList();
if (selectedSymptoms.Count > 0)
parts.Add($"Symptome: {string.Join(", ", selectedSymptoms)}");
parts.Add(LocalizationService.Format("Options_Export_Filter_SymptomsFormat", string.Join(", ", selectedSymptoms)));
return parts.Count > 0
? string.Join(" | ", parts)
: "Keine Filter aktiv.";
: LocalizationService.Translate("Options_Export_Filter_None");
}
}
@@ -133,13 +153,14 @@ public partial class OptionsViewModel : ObservableObject
get
{
var selectedCount = ExportSymptoms.Count(x => x.IsSelected);
var countSuffix = selectedCount > 0
? $" ({selectedCount} ausgewählt)"
: string.Empty;
return IsExportSymptomFilterExpanded
? $"Symptome ausblenden{countSuffix}"
: $"Symptome auswählen{countSuffix}";
return (IsExportSymptomFilterExpanded, selectedCount > 0) switch
{
(true, true) => LocalizationService.Format("Options_Export_SymptomsHideWithCount", selectedCount),
(true, false) => LocalizationService.Translate("Options_Export_SymptomsHide"),
(false, true) => LocalizationService.Format("Options_Export_SymptomsSelectWithCount", selectedCount),
_ => LocalizationService.Translate("Options_Export_SymptomsSelect")
};
}
}
@@ -176,6 +197,7 @@ public partial class OptionsViewModel : ObservableObject
HealthEntryRepository healthEntryRepository,
AppearanceRepository appearanceRepository,
AppearanceService appearanceService,
LocalizationService localizationService,
ActivityRepository activityRepository,
SymptomRepository symptomRepository,
NotificationScheduleRepository notificationScheduleRepository,
@@ -187,6 +209,7 @@ public partial class OptionsViewModel : ObservableObject
_healthEntryRepository = healthEntryRepository;
_appearanceRepository = appearanceRepository;
_appearanceService = appearanceService;
_localizationService = localizationService;
_activityRepository = activityRepository;
_symptomRepository = symptomRepository;
_notificationScheduleRepository = notificationScheduleRepository;
@@ -250,6 +273,16 @@ public partial class OptionsViewModel : ObservableObject
OnPropertyChanged(nameof(NotificationVibrationButtonText));
}
partial void OnCurrentDatabasePathChanged(string value)
{
OnPropertyChanged(nameof(CurrentDatabasePathText));
}
partial void OnSelectedLanguageOptionChanged(LanguageOptionItemViewModel? value)
{
OnPropertyChanged(nameof(SelectedLanguageDescription));
}
partial void OnExportStartDateChanged(DateTime value)
{
if (ExportEndDate.Date < value.Date)
@@ -287,6 +320,7 @@ public partial class OptionsViewModel : ObservableObject
public async Task LoadAsync()
{
await LoadAppearanceAsync();
LoadLanguageOptions();
await LoadActivitiesAsync();
await LoadSymptomsAsync();
await LoadSchedulesAsync();
@@ -296,16 +330,22 @@ public partial class OptionsViewModel : ObservableObject
ExternalDatabasePath = _databaseLocationService.ExternalDatabasePath;
CurrentDatabasePath = _appDatabase.CurrentPath;
StatusText = string.Empty;
RequiresShellReload = false;
}
public void ClearShellReloadFlag()
{
RequiresShellReload = false;
}
private bool CanDeleteAllData() =>
string.Equals(DeleteConfirmationText?.Trim(), "löschen", StringComparison.OrdinalIgnoreCase);
LocalizationService.IsKnownTranslation("Options_Data_DeleteConfirmationKeyword", DeleteConfirmationText);
private async Task DeleteAllDataAsync()
{
await _healthEntryRepository.DeleteAllAsync();
DeleteConfirmationText = string.Empty;
StatusText = "Alle Einträge wurden gelöscht.";
StatusText = LocalizationService.Translate("Options_Status_AllDataDeleted");
}
private async Task LoadAppearanceAsync()
@@ -315,39 +355,39 @@ public partial class OptionsViewModel : ObservableObject
var map = await _appearanceRepository.GetMapAsync();
AddColor(AppearanceKeys.AppBackground, "App-Hintergrund");
AddColor(AppearanceKeys.SurfaceBackground, "Karten-Hintergrund");
AddColor(AppearanceKeys.SurfaceBackgroundAlt, "Sekundäre Fläche");
AddColor(AppearanceKeys.Border, "Rahmen");
AddColor(AppearanceKeys.TextPrimary, "Haupttext");
AddColor(AppearanceKeys.TextMuted, "Nebentext");
AddColor(AppearanceKeys.AppBackground);
AddColor(AppearanceKeys.SurfaceBackground);
AddColor(AppearanceKeys.SurfaceBackgroundAlt);
AddColor(AppearanceKeys.Border);
AddColor(AppearanceKeys.TextPrimary);
AddColor(AppearanceKeys.TextMuted);
AddColor(AppearanceKeys.StateGreen, "Statusfarbe Grün");
AddColor(AppearanceKeys.StateYellow, "Statusfarbe Gelb");
AddColor(AppearanceKeys.StateRed, "Statusfarbe Rot");
AddColor(AppearanceKeys.StateGray, "Statusfarbe Schwarz / Grau");
AddColor(AppearanceKeys.StateGreen);
AddColor(AppearanceKeys.StateYellow);
AddColor(AppearanceKeys.StateRed);
AddColor(AppearanceKeys.StateGray);
AddColor(AppearanceKeys.ButtonPrimaryBackground, "Button Primär Hintergrund");
AddColor(AppearanceKeys.ButtonPrimaryText, "Button Primär Text");
AddColor(AppearanceKeys.ButtonSecondaryBackground, "Button Sekundär Hintergrund");
AddColor(AppearanceKeys.ButtonSecondaryText, "Button Sekundär Text");
AddColor(AppearanceKeys.ButtonPrimaryBackground);
AddColor(AppearanceKeys.ButtonPrimaryText);
AddColor(AppearanceKeys.ButtonSecondaryBackground);
AddColor(AppearanceKeys.ButtonSecondaryText);
AddColor(AppearanceKeys.ShellBackground, "App-Leiste Hintergrund");
AddColor(AppearanceKeys.ShellForeground, "App-Leiste Vordergrund");
AddColor(AppearanceKeys.ShellTitle, "App-Leiste Titel");
AddColor(AppearanceKeys.ShellUnselected, "App-Leiste Inaktiv");
AddColor(AppearanceKeys.ShellBackground);
AddColor(AppearanceKeys.ShellForeground);
AddColor(AppearanceKeys.ShellTitle);
AddColor(AppearanceKeys.ShellUnselected);
AddColor(AppearanceKeys.TabBarBackground, "Tableiste Hintergrund");
AddColor(AppearanceKeys.TabBarForeground, "Tableiste Aktiv");
AddColor(AppearanceKeys.TabBarTitle, "Tableiste Titel");
AddColor(AppearanceKeys.TabBarUnselected, "Tableiste Inaktiv");
AddColor(AppearanceKeys.TabBarBackground);
AddColor(AppearanceKeys.TabBarForeground);
AddColor(AppearanceKeys.TabBarTitle);
AddColor(AppearanceKeys.TabBarUnselected);
AddText(AppearanceKeys.StatusGreenText, "Text für Grün");
AddText(AppearanceKeys.StatusYellowText, "Text für Gelb");
AddText(AppearanceKeys.StatusRedText, "Text für Rot");
AddText(AppearanceKeys.StatusGrayText, "Text für Schwarz / Grau");
AddText(AppearanceKeys.StatusGreenText);
AddText(AppearanceKeys.StatusYellowText);
AddText(AppearanceKeys.StatusRedText);
AddText(AppearanceKeys.StatusGrayText);
void AddColor(string key, string title)
void AddColor(string key)
{
var fallback = AppearanceDefaults.All[key];
var value = map.TryGetValue(key, out var stored) ? stored : fallback;
@@ -356,27 +396,57 @@ public partial class OptionsViewModel : ObservableObject
AppearanceColors.Add(new AppearanceColorItemViewModel
{
Key = key,
Title = title,
Title = GetAppearanceColorTitle(key),
Fallback = fallback,
Value = ToHex(preview),
PreviewColor = preview
});
}
void AddText(string key, string title)
void AddText(string key)
{
var fallback = AppearanceDefaults.All[key];
var fallback = LocalizationService.GetDefaultStatusText(key);
if (string.IsNullOrWhiteSpace(fallback))
fallback = AppearanceDefaults.All[key];
var value = map.TryGetValue(key, out var stored) ? stored : fallback;
StatusTexts.Add(new AppearanceTextItemViewModel
{
Key = key,
Title = title,
Title = GetAppearanceTextTitle(key),
Value = value
});
}
}
private void LoadLanguageOptions()
{
var currentCode = _localizationService.SelectedLanguageCode;
LanguageOptions.Clear();
LanguageOptions.Add(new LanguageOptionItemViewModel
{
Code = LocalizationService.SystemLanguageCode,
DisplayName = _localizationService.GetLanguageDisplayName(LocalizationService.SystemLanguageCode)
});
LanguageOptions.Add(new LanguageOptionItemViewModel
{
Code = LocalizationService.GermanLanguageCode,
DisplayName = _localizationService.GetLanguageDisplayName(LocalizationService.GermanLanguageCode)
});
LanguageOptions.Add(new LanguageOptionItemViewModel
{
Code = LocalizationService.EnglishLanguageCode,
DisplayName = _localizationService.GetLanguageDisplayName(LocalizationService.EnglishLanguageCode)
});
SelectedLanguageOption = LanguageOptions.FirstOrDefault(x => x.Code == currentCode)
?? LanguageOptions.FirstOrDefault();
OnPropertyChanged(nameof(SelectedLanguageDescription));
}
private async Task LoadActivitiesAsync()
{
var selectedExportActivityId = SelectedExportActivity?.Id;
@@ -447,6 +517,14 @@ public partial class OptionsViewModel : ObservableObject
private async Task SaveAppearanceAsync()
{
RequiresShellReload = false;
var targetLanguageCode = SelectedLanguageOption?.Code ?? _localizationService.SelectedLanguageCode;
var targetCulture = _localizationService.GetCultureForSelection(targetLanguageCode);
foreach (var item in StatusTexts)
item.Value = LocalizationService.NormalizeStatusTextForCulture(item.Key, item.Value, targetCulture);
foreach (var item in AppearanceColors)
{
var normalized = ToHex(ColorUtility.ParseColor(item.Value, item.Fallback));
@@ -458,23 +536,30 @@ public partial class OptionsViewModel : ObservableObject
foreach (var item in StatusTexts)
await _appearanceService.SaveTextAsync(item.Key, item.Value);
var languageChanged = _localizationService.SetSelectedLanguage(targetLanguageCode);
await _appearanceService.ApplyAsync();
await LoadAppearanceAsync();
LoadLanguageOptions();
await _notificationScheduler.SyncAsync();
StatusText = "Aussehen gespeichert.";
RequiresShellReload = languageChanged;
StatusText = LocalizationService.Translate("Options_Status_AppearanceSaved");
}
private async Task ResetAppearanceAsync()
{
await _appearanceService.ResetAsync();
await LoadAppearanceAsync();
LoadLanguageOptions();
await _notificationScheduler.SyncAsync();
StatusText = "Aussehen auf Standard zurückgesetzt.";
StatusText = LocalizationService.Translate("Options_Status_AppearanceReset");
}
private async Task AddActivityAsync()
{
if (string.IsNullOrWhiteSpace(NewActivityName))
{
StatusText = "Bitte zuerst einen Tätigkeitsnamen eingeben.";
StatusText = LocalizationService.Translate("Options_Status_ActivityNameRequired");
return;
}
@@ -483,7 +568,7 @@ public partial class OptionsViewModel : ObservableObject
await _activityRepository.AddAsync(NewActivityName);
NewActivityName = string.Empty;
await LoadActivitiesAsync();
StatusText = "Tätigkeit hinzugefügt.";
StatusText = LocalizationService.Translate("Options_Status_ActivityAdded");
}
catch (Exception ex)
{
@@ -500,7 +585,7 @@ public partial class OptionsViewModel : ObservableObject
{
await _activityRepository.RenameAsync(item.Id, item.Name);
await LoadActivitiesAsync();
StatusText = "Tätigkeit gespeichert.";
StatusText = LocalizationService.Translate("Options_Status_ActivitySaved");
}
catch (Exception ex)
{
@@ -515,7 +600,7 @@ public partial class OptionsViewModel : ObservableObject
await _activityRepository.SetActiveAsync(item.Id, !item.IsActive);
await LoadActivitiesAsync();
StatusText = "Tätigkeit aktualisiert.";
StatusText = LocalizationService.Translate("Options_Status_ActivityUpdated");
}
private async Task DeleteActivityAsync(ActivityManageItemViewModel? item)
@@ -525,14 +610,17 @@ public partial class OptionsViewModel : ObservableObject
await _activityRepository.DeleteOrDeactivateAsync(item.Id);
await LoadActivitiesAsync();
StatusText = item.IsUsed ? "Tätigkeit wurde deaktiviert." : "Tätigkeit wurde gelöscht.";
StatusText = LocalizationService.Translate(
item.IsUsed
? "Options_Status_ActivityDisabled"
: "Options_Status_ActivityDeleted");
}
private async Task AddSymptomAsync()
{
if (string.IsNullOrWhiteSpace(NewSymptomName))
{
StatusText = "Bitte zuerst einen Symptomnamen eingeben.";
StatusText = LocalizationService.Translate("Options_Status_SymptomNameRequired");
return;
}
@@ -541,7 +629,7 @@ public partial class OptionsViewModel : ObservableObject
await _symptomRepository.AddAsync(NewSymptomName);
NewSymptomName = string.Empty;
await LoadSymptomsAsync();
StatusText = "Symptom hinzugefügt.";
StatusText = LocalizationService.Translate("Options_Status_SymptomAdded");
}
catch (Exception ex)
{
@@ -558,7 +646,7 @@ public partial class OptionsViewModel : ObservableObject
{
await _symptomRepository.RenameAsync(item.Id, item.Name);
await LoadSymptomsAsync();
StatusText = "Symptom gespeichert.";
StatusText = LocalizationService.Translate("Options_Status_SymptomSaved");
}
catch (Exception ex)
{
@@ -573,7 +661,7 @@ public partial class OptionsViewModel : ObservableObject
await _symptomRepository.SetActiveAsync(item.Id, !item.IsActive);
await LoadSymptomsAsync();
StatusText = "Symptom aktualisiert.";
StatusText = LocalizationService.Translate("Options_Status_SymptomUpdated");
}
private async Task DeleteSymptomAsync(SymptomManageItemViewModel? item)
@@ -583,7 +671,10 @@ public partial class OptionsViewModel : ObservableObject
await _symptomRepository.DeleteOrDeactivateAsync(item.Id);
await LoadSymptomsAsync();
StatusText = item.IsUsed ? "Symptom wurde deaktiviert." : "Symptom wurde gelöscht.";
StatusText = LocalizationService.Translate(
item.IsUsed
? "Options_Status_SymptomDisabled"
: "Options_Status_SymptomDeleted");
}
private Task AddScheduleAsync()
@@ -599,7 +690,7 @@ public partial class OptionsViewModel : ObservableObject
Friday = true
});
StatusText = "Benachrichtigungszeit hinzugefügt.";
StatusText = LocalizationService.Translate("Options_Status_NotificationAdded");
return Task.CompletedTask;
}
@@ -610,16 +701,17 @@ public partial class OptionsViewModel : ObservableObject
var granted = await _notificationScheduler.EnsurePermissionAsync();
if (!granted)
{
StatusText = OperatingSystem.IsAndroidVersionAtLeast(31)
? "Bitte Benachrichtigungen, Push-Nachrichten und Alarme erlauben und danach erneut speichern."
: "Bitte Benachrichtigungen und Push-Nachrichten erlauben und danach erneut speichern.";
StatusText = LocalizationService.Translate(
OperatingSystem.IsAndroidVersionAtLeast(31)
? "Options_Status_NotificationPermissionAndroid31"
: "Options_Status_NotificationPermissionLegacy");
return;
}
if (NotificationSchedules.Any(x => x.ToWeekdayMask() == 0))
{
StatusText = "Bitte pro Benachrichtigungszeit mindestens einen Wochentag auswählen.";
StatusText = LocalizationService.Translate("Options_Status_NotificationWeekdayRequired");
return;
}
@@ -636,9 +728,10 @@ public partial class OptionsViewModel : ObservableObject
await _notificationScheduler.SyncAsync();
await LoadSchedulesAsync();
StatusText = NotificationVibrationEnabled
? "Benachrichtigungszeiten gespeichert. Vibration ist aktiv."
: "Benachrichtigungszeiten gespeichert. Vibration ist aus.";
StatusText = LocalizationService.Translate(
NotificationVibrationEnabled
? "Options_Status_NotificationsSavedActive"
: "Options_Status_NotificationsSavedInactive");
}
private Task DeleteScheduleAsync(NotificationScheduleItemViewModel? item)
@@ -646,7 +739,7 @@ public partial class OptionsViewModel : ObservableObject
if (item is not null)
NotificationSchedules.Remove(item);
StatusText = "Benachrichtigungszeit entfernt.";
StatusText = LocalizationService.Translate("Options_Status_NotificationRemoved");
return Task.CompletedTask;
}
@@ -655,7 +748,7 @@ public partial class OptionsViewModel : ObservableObject
_databaseLocationService.UseExternalDatabase = UseExternalDatabase;
_databaseLocationService.ExternalDatabasePath = ExternalDatabasePath?.Trim() ?? string.Empty;
CurrentDatabasePath = _databaseLocationService.ResolveDatabasePath();
StatusText = "Datenbankpfad gespeichert. Bitte App neu starten, damit der Pfad aktiv wird.";
StatusText = LocalizationService.Translate("Options_Status_DatabaseSaved");
return Task.CompletedTask;
}
@@ -670,7 +763,7 @@ public partial class OptionsViewModel : ObservableObject
SelectedExportActivity?.Id,
ExportSymptoms.Where(x => x.IsSelected).Select(x => x.Id).ToList());
StatusText = $"Export erstellt: {result.FileName}";
StatusText = LocalizationService.Format("Options_Status_ExportCreated", result.FileName);
await ExportUiHelper.ShowExportSavedActionsAsync(result);
}
catch (Exception ex)
@@ -686,15 +779,17 @@ public partial class OptionsViewModel : ObservableObject
ExportActivities.Add(new ActivityPickerItemViewModel
{
Id = null,
Name = "Alle T\u00e4tigkeiten"
Name = LocalizationService.Translate("Options_Export_AllActivities")
});
foreach (var item in activities.Where(x => !string.Equals(x.Name, "Keine T\u00e4tigkeit", StringComparison.OrdinalIgnoreCase)))
foreach (var item in activities.Where(x => !LocalizationService.IsNoActivityLabel(x.Name)))
{
ExportActivities.Add(new ActivityPickerItemViewModel
{
Id = item.Id,
Name = item.IsActive ? item.Name : $"{item.Name} (inaktiv)"
Name = item.IsActive
? item.Name
: LocalizationService.Format("Common_InactiveSuffix", item.Name)
});
}
@@ -711,7 +806,9 @@ public partial class OptionsViewModel : ObservableObject
var exportItem = new SelectableSymptomItemViewModel
{
Id = item.Id,
Name = item.IsActive ? item.Name : $"{item.Name} (inaktiv)",
Name = item.IsActive
? item.Name
: LocalizationService.Format("Common_InactiveSuffix", item.Name),
IsSelected = selectedSymptomIds.Contains(item.Id)
};
@@ -747,10 +844,10 @@ public partial class OptionsViewModel : ObservableObject
private async Task ClearExportsAsync()
{
var confirm = await Shell.Current.DisplayAlertAsync(
"Export entleeren",
"Möchtest du wirklich alle lokal gespeicherten Exporte löschen?",
"Ja",
"Nein");
LocalizationService.Translate("Options_Export_Clear"),
LocalizationService.Translate("Options_Export_Clear_Confirm"),
LocalizationService.Translate("Common_Yes"),
LocalizationService.Translate("Common_No"));
if (!confirm)
return;
@@ -758,11 +855,54 @@ public partial class OptionsViewModel : ObservableObject
var deleted = await _pdfExportService.ClearExportsAsync();
await Shell.Current.DisplayAlertAsync(
"Export entleeren",
LocalizationService.Translate("Options_Export_Clear"),
deleted > 0
? $"{deleted} Export-Datei(en) wurden gelöscht."
: "Es waren keine Export-Dateien vorhanden.",
"OK");
? LocalizationService.Format("Options_Export_Clear_ResultDeletedFormat", deleted)
: LocalizationService.Translate("Options_Export_Clear_ResultEmpty"),
LocalizationService.Translate("Common_OK"));
}
private static string GetAppearanceColorTitle(string key) => LocalizationService.Translate(key switch
{
AppearanceKeys.AppBackground => "Options_Appearance_Color_AppBackground",
AppearanceKeys.SurfaceBackground => "Options_Appearance_Color_SurfaceBackground",
AppearanceKeys.SurfaceBackgroundAlt => "Options_Appearance_Color_SurfaceBackgroundAlt",
AppearanceKeys.Border => "Options_Appearance_Color_Border",
AppearanceKeys.TextPrimary => "Options_Appearance_Color_TextPrimary",
AppearanceKeys.TextMuted => "Options_Appearance_Color_TextMuted",
AppearanceKeys.StateGreen => "Options_Appearance_Color_StateGreen",
AppearanceKeys.StateYellow => "Options_Appearance_Color_StateYellow",
AppearanceKeys.StateRed => "Options_Appearance_Color_StateRed",
AppearanceKeys.StateGray => "Options_Appearance_Color_StateGray",
AppearanceKeys.ButtonPrimaryBackground => "Options_Appearance_Color_ButtonPrimaryBackground",
AppearanceKeys.ButtonPrimaryText => "Options_Appearance_Color_ButtonPrimaryText",
AppearanceKeys.ButtonSecondaryBackground => "Options_Appearance_Color_ButtonSecondaryBackground",
AppearanceKeys.ButtonSecondaryText => "Options_Appearance_Color_ButtonSecondaryText",
AppearanceKeys.ShellBackground => "Options_Appearance_Color_ShellBackground",
AppearanceKeys.ShellForeground => "Options_Appearance_Color_ShellForeground",
AppearanceKeys.ShellTitle => "Options_Appearance_Color_ShellTitle",
AppearanceKeys.ShellUnselected => "Options_Appearance_Color_ShellUnselected",
AppearanceKeys.TabBarBackground => "Options_Appearance_Color_TabBarBackground",
AppearanceKeys.TabBarForeground => "Options_Appearance_Color_TabBarForeground",
AppearanceKeys.TabBarTitle => "Options_Appearance_Color_TabBarTitle",
AppearanceKeys.TabBarUnselected => "Options_Appearance_Color_TabBarUnselected",
_ => key
});
private static string GetAppearanceTextTitle(string key) => LocalizationService.Translate(key switch
{
AppearanceKeys.StatusGreenText => "Options_Appearance_Text_Green",
AppearanceKeys.StatusYellowText => "Options_Appearance_Text_Yellow",
AppearanceKeys.StatusRedText => "Options_Appearance_Text_Red",
AppearanceKeys.StatusGrayText => "Options_Appearance_Text_Gray",
_ => key
});
private static string FormatShortDate(DateTime date)
{
var culture = LocalizationService.GetCurrentCulture();
var format = LocalizationService.Translate("Date_ShortNumericFormat");
return date.ToString(format, culture);
}
private static string ToHex(Color color)
+25 -16
View File
@@ -41,16 +41,16 @@ public partial class QuickEntryViewModel : ObservableObject
private bool isEditing;
[ObservableProperty]
private string greenStatusText = "Grün";
private string greenStatusText = "Green";
[ObservableProperty]
private string yellowStatusText = "Gelb";
private string yellowStatusText = "Yellow";
[ObservableProperty]
private string redStatusText = "Rot";
private string redStatusText = "Red";
[ObservableProperty]
private string grayStatusText = "Schwarz";
private string grayStatusText = "Black";
[ObservableProperty]
private Color greenStateColor = Color.FromArgb("#4E8B69");
@@ -81,7 +81,7 @@ public partial class QuickEntryViewModel : ObservableObject
public ObservableCollection<DayPartOptionItemViewModel> Parts { get; } = new();
public string ModeText => IsFutureDate
? "Zukünftige Tage können nicht gespeichert werden."
? LocalizationService.Translate("QuickEntry_FutureDateMessage")
: string.Empty;
public bool CanSave => !IsFutureDate;
@@ -89,8 +89,8 @@ public partial class QuickEntryViewModel : ObservableObject
public bool CanExplicitSave => IsEditing && SelectedState.HasValue && !IsFutureDate;
public string SelectedStateSummaryText => SelectedState.HasValue
? $"Gewählter Status: {GetStateText(SelectedState.Value)}"
: "Bitte Status wählen";
? LocalizationService.Format("QuickEntry_SelectedStatusFormat", GetStateText(SelectedState.Value))
: LocalizationService.Translate("QuickEntry_SelectStatusPrompt");
public IAsyncRelayCommand SaveGreenCommand { get; }
public IAsyncRelayCommand SaveYellowCommand { get; }
@@ -214,11 +214,11 @@ public partial class QuickEntryViewModel : ObservableObject
Activities.Add(new ActivityPickerItemViewModel
{
Id = null,
Name = "Keine Tätigkeit"
Name = LocalizationService.Translate("Activity_None")
});
var items = await _activityRepository.GetActiveAsync();
foreach (var item in items.Where(x => !string.Equals(x.Name, "Keine Tätigkeit", StringComparison.OrdinalIgnoreCase)))
foreach (var item in items.Where(x => !LocalizationService.IsNoActivityLabel(x.Name)))
{
Activities.Add(new ActivityPickerItemViewModel
{
@@ -251,13 +251,13 @@ public partial class QuickEntryViewModel : ObservableObject
Parts.Add(new DayPartOptionItemViewModel
{
Value = DayPart.Morning,
Name = "Vormittag"
Name = LocalizationService.Translate("Common_Morning")
});
Parts.Add(new DayPartOptionItemViewModel
{
Value = DayPart.Afternoon,
Name = "Nachmittag"
Name = LocalizationService.Translate("Common_Afternoon")
});
}
@@ -366,10 +366,18 @@ public partial class QuickEntryViewModel : ObservableObject
private void LoadAppearance()
{
GreenStatusText = _appearanceService.GetText(AppearanceKeys.StatusGreenText, "Grün");
YellowStatusText = _appearanceService.GetText(AppearanceKeys.StatusYellowText, "Gelb");
RedStatusText = _appearanceService.GetText(AppearanceKeys.StatusRedText, "Rot");
GrayStatusText = _appearanceService.GetText(AppearanceKeys.StatusGrayText, "Schwarz");
GreenStatusText = _appearanceService.GetText(
AppearanceKeys.StatusGreenText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusGreenText));
YellowStatusText = _appearanceService.GetText(
AppearanceKeys.StatusYellowText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusYellowText));
RedStatusText = _appearanceService.GetText(
AppearanceKeys.StatusRedText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusRedText));
GrayStatusText = _appearanceService.GetText(
AppearanceKeys.StatusGrayText,
LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusGrayText));
GreenStateColor = _appearanceService.GetColor(AppearanceKeys.StateGreen, "#4E8B69");
YellowStateColor = _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42");
@@ -417,6 +425,7 @@ public partial class QuickEntryViewModel : ObservableObject
case "gray":
case "grey":
case "black":
case "grau":
case "schwarz":
state = HealthState.Gray;
@@ -441,4 +450,4 @@ public partial class QuickEntryViewModel : ObservableObject
item.IsSelected = !item.IsSelected;
}
}
}
+3 -2
View File
@@ -1,3 +1,4 @@
using cfs_tracker.Services;
using CommunityToolkit.Mvvm.ComponentModel;
namespace cfs_tracker.ViewModels;
@@ -15,6 +16,6 @@ public partial class SymptomManageItemViewModel : ObservableObject
public bool IsUsed { get; init; }
public string UsageHint => IsUsed
? "Bereits verwendet – kann nur deaktiviert werden."
: "Kann gelöscht werden, solange unbenutzt.";
? LocalizationService.Translate("Options_UsageHint_Used")
: LocalizationService.Translate("Options_UsageHint_Unused");
}
+6 -1
View File
@@ -1,3 +1,4 @@
using cfs_tracker.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -16,7 +17,11 @@ public partial class WeekDaySummaryViewModel : ObservableObject
public bool HasDetails => !string.IsNullOrWhiteSpace(ActivitiesText) || !string.IsNullOrWhiteSpace(SymptomsText);
public bool HasActivities => !string.IsNullOrWhiteSpace(ActivitiesText);
public bool HasSymptoms => !string.IsNullOrWhiteSpace(SymptomsText);
public string DetailsButtonText => IsExpanded ? "Zusammenfassung ausblenden" : "Zusammenfassung anzeigen";
public string DetailsButtonText => IsExpanded
? LocalizationService.Translate("WeekPage_SummaryHide")
: LocalizationService.Translate("WeekPage_SummaryShow");
public string ActivitiesSummaryText => LocalizationService.Format("WeekPage_ActivitiesFormat", ActivitiesText);
public string SymptomsSummaryText => LocalizationService.Format("WeekPage_SymptomsFormat", SymptomsText);
[ObservableProperty]
private bool isExpanded;
+9 -6
View File
@@ -108,7 +108,10 @@ 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}";
HeaderText = LocalizationService.Format(
"WeekPage_HeaderFormat",
WeekStart.ToString(LocalizationService.Translate("Date_ShortNumericFormat"), LocalizationService.GetCurrentCulture()),
WeekStart.AddDays(6).ToString(LocalizationService.Translate("Date_ShortNumericFormat"), LocalizationService.GetCurrentCulture()));
}
private async Task OpenDayAsync(WeekDaySummaryViewModel? item)
@@ -160,10 +163,10 @@ public partial class WeekViewModel : ObservableObject
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"),
HealthState.Green => _appearanceService.GetText(AppearanceKeys.StatusGreenText, LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusGreenText)),
HealthState.Yellow => _appearanceService.GetText(AppearanceKeys.StatusYellowText, LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusYellowText)),
HealthState.Red => _appearanceService.GetText(AppearanceKeys.StatusRedText, LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusRedText)),
HealthState.Gray => _appearanceService.GetText(AppearanceKeys.StatusGrayText, LocalizationService.GetDefaultStatusText(AppearanceKeys.StatusGrayText)),
_ => "-"
};
@@ -190,4 +193,4 @@ public partial class WeekViewModel : ObservableObject
return HealthState.Green;
}
}
}
+125 -43
View File
@@ -15,6 +15,7 @@ public partial class YearViewModel : ObservableObject
private readonly AppearanceService _appearanceService;
private readonly CalendarStateService _calendarStateService;
private readonly IPdfExportService _pdfExportService;
private CancellationTokenSource? _refreshCancellationTokenSource;
[ObservableProperty]
private DateTime selectedDate;
@@ -59,60 +60,44 @@ public partial class YearViewModel : ObservableObject
public async Task RefreshAsync()
{
var refreshCancellationTokenSource = BeginRefresh();
var cancellationToken = refreshCancellationTokenSource.Token;
SelectedDate = _calendarStateService.SelectedDate.Date;
UpdateHeader();
var yearStart = new DateTime(SelectedDate.Year, 1, 1);
var yearEnd = yearStart.AddYears(1);
var entries = await _healthEntryRepository.GetEntriesBetweenAsync(yearStart, yearEnd);
Months.Clear();
for (var monthNumber = 1; monthNumber <= 12; monthNumber++)
try
{
var monthStart = new DateTime(SelectedDate.Year, monthNumber, 1);
var daysInMonth = DateTime.DaysInMonth(monthStart.Year, monthStart.Month);
var selectedYear = SelectedDate.Year;
var sections = CreateMonthSections(selectedYear);
var section = new MonthSectionViewModel
Months.Clear();
foreach (var section in sections)
Months.Add(section);
for (var monthNumber = 1; monthNumber <= sections.Count; monthNumber++)
{
Title = monthStart.ToString("MMMM")
};
var leadingEmptyCells = GetMondayBasedColumnIndex(monthStart.DayOfWeek);
for (var i = 0; i < leadingEmptyCells; i++)
section.Cells.Add(CreatePlaceholderCell());
for (var day = 1; day <= daysInMonth; day++)
{
var date = new DateTime(monthStart.Year, monthStart.Month, day);
var dayEntries = entries.Where(x => x.EntryDate.Date == date.Date).ToList();
var worstState = CalculateWorstState(dayEntries);
section.Cells.Add(new MonthCellViewModel
{
Date = date,
DayNumberText = date.Day.ToString(),
IsCurrentMonth = true,
IsToday = date.Date == DateTime.Today,
HasEntries = dayEntries.Count > 0,
BackgroundColor = GetCellBackgroundColor(worstState),
TextColor = GetCellTextColor(worstState),
BorderColor = date.Date == DateTime.Today
? _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42")
: _appearanceService.GetColor(AppearanceKeys.Border, "#2A3E55")
});
cancellationToken.ThrowIfCancellationRequested();
await LoadMonthSectionAsync(
sections[monthNumber - 1],
selectedYear,
monthNumber,
cancellationToken);
}
while (section.Cells.Count % 7 != 0)
section.Cells.Add(CreatePlaceholderCell());
Months.Add(section);
}
catch (OperationCanceledException)
{
// Ein neueres Refresh hat diese Aktualisierung ersetzt.
}
finally
{
EndRefresh(refreshCancellationTokenSource);
}
}
private void UpdateHeader()
{
HeaderText = SelectedDate.Year.ToString();
HeaderText = DateHelper.ToGermanYear(SelectedDate);
}
private async Task OpenDayAsync(MonthCellViewModel? item)
@@ -157,11 +142,108 @@ public partial class YearViewModel : ObservableObject
{
MainThread.BeginInvokeOnMainThread(async () =>
{
if (SelectedDate.Date == date.Date)
return;
SelectedDate = date.Date;
await RefreshAsync();
});
}
private CancellationTokenSource BeginRefresh()
{
var refreshCancellationTokenSource = new CancellationTokenSource();
var previousRefresh = Interlocked.Exchange(ref _refreshCancellationTokenSource, refreshCancellationTokenSource);
previousRefresh?.Cancel();
previousRefresh?.Dispose();
return refreshCancellationTokenSource;
}
private void EndRefresh(CancellationTokenSource refreshCancellationTokenSource)
{
if (ReferenceEquals(_refreshCancellationTokenSource, refreshCancellationTokenSource))
_refreshCancellationTokenSource = null;
refreshCancellationTokenSource.Dispose();
}
private List<MonthSectionViewModel> CreateMonthSections(int year)
{
return Enumerable.Range(1, 12)
.Select(monthNumber => new MonthSectionViewModel
{
Title = new DateTime(year, monthNumber, 1).ToString("MMMM", LocalizationService.GetCurrentCulture()),
IsLoading = true
})
.ToList();
}
private async Task LoadMonthSectionAsync(
MonthSectionViewModel section,
int year,
int monthNumber,
CancellationToken cancellationToken)
{
var monthStart = new DateTime(year, monthNumber, 1);
var monthEnd = monthStart.AddMonths(1);
var entries = await _healthEntryRepository.GetEntriesBetweenAsync(monthStart, monthEnd);
cancellationToken.ThrowIfCancellationRequested();
var cells = BuildMonthCells(monthStart, entries);
await MainThread.InvokeOnMainThreadAsync(() =>
{
if (cancellationToken.IsCancellationRequested)
return;
section.ReplaceCells(cells);
});
}
private List<MonthCellViewModel> BuildMonthCells(DateTime monthStart, IReadOnlyList<HealthEntry> entries)
{
var cells = new List<MonthCellViewModel>();
var daysInMonth = DateTime.DaysInMonth(monthStart.Year, monthStart.Month);
var entriesByDay = entries
.GroupBy(x => x.EntryDate.Date)
.ToDictionary(group => group.Key, group => (IReadOnlyCollection<HealthEntry>)group.ToList());
var leadingEmptyCells = GetMondayBasedColumnIndex(monthStart.DayOfWeek);
for (var i = 0; i < leadingEmptyCells; i++)
cells.Add(CreatePlaceholderCell());
for (var day = 1; day <= daysInMonth; day++)
{
var date = new DateTime(monthStart.Year, monthStart.Month, day);
var dayEntries = entriesByDay.TryGetValue(date.Date, out var matches)
? matches
: Array.Empty<HealthEntry>();
var worstState = CalculateWorstState(dayEntries);
cells.Add(new MonthCellViewModel
{
Date = date,
DayNumberText = date.Day.ToString(),
IsCurrentMonth = true,
IsToday = date.Date == DateTime.Today,
HasEntries = dayEntries.Count > 0,
BackgroundColor = GetCellBackgroundColor(worstState),
TextColor = GetCellTextColor(worstState),
BorderColor = date.Date == DateTime.Today
? _appearanceService.GetColor(AppearanceKeys.StateYellow, "#B89A42")
: _appearanceService.GetColor(AppearanceKeys.Border, "#2A3E55")
});
}
while (cells.Count % 7 != 0)
cells.Add(CreatePlaceholderCell());
return cells;
}
private Color GetCellBackgroundColor(HealthState? state) => state switch
{
HealthState.Green => _appearanceService.GetColor(AppearanceKeys.StateGreen, "#4E8B69"),
@@ -216,4 +298,4 @@ public partial class YearViewModel : ObservableObject
BorderColor = Colors.Transparent
};
}
}
}