Layout and Push Fix

This commit is contained in:
2026-03-28 23:44:56 +01:00
parent 74722b5e81
commit cf3d7557aa
13 changed files with 429 additions and 282 deletions
+1
View File
@@ -4,4 +4,5 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
</manifest>
@@ -1,5 +1,6 @@
using Android.App;
using Android.Content;
using Android.Provider;
using AndroidX.Core.App;
using cfs_tracker.Data;
using cfs_tracker.Helpers;
@@ -54,12 +55,29 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
public async Task<bool> EnsurePermissionAsync()
{
var status = await Permissions.CheckStatusAsync<NotificationPermission>();
if (status == PermissionStatus.Granted)
var notificationStatus = await Permissions.CheckStatusAsync<NotificationPermission>();
if (notificationStatus != PermissionStatus.Granted)
{
notificationStatus = await Permissions.RequestAsync<NotificationPermission>();
if (notificationStatus != PermissionStatus.Granted)
return false;
}
if (!OperatingSystem.IsAndroidVersionAtLeast(31))
return true;
status = await Permissions.RequestAsync<NotificationPermission>();
return status == PermissionStatus.Granted;
var context = Platform.AppContext;
var alarmManager = (AlarmManager?)context.GetSystemService(Context.AlarmService);
if (alarmManager is null || alarmManager.CanScheduleExactAlarms())
return true;
var intent = new Intent(Settings.ActionRequestScheduleExactAlarm);
intent.SetData(global::Android.Net.Uri.Parse($"package:{context.PackageName}"));
intent.AddFlags(ActivityFlags.NewTask);
context.StartActivity(intent);
return false;
}
public Task<bool> GetVibrationEnabledAsync() =>
@@ -78,8 +96,8 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
CancelAllScheduled(context);
var granted = await EnsurePermissionAsync();
if (!granted)
var notificationStatus = await Permissions.CheckStatusAsync<NotificationPermission>();
if (notificationStatus != PermissionStatus.Granted)
return;
SaveActionLabelsToPreferences();
@@ -143,10 +161,19 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
var when = triggerAt.ToUnixTimeMilliseconds();
if (CanUseExactAlarms(context, alarmManager))
{
alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, when, pendingIntent);
return;
}
if (OperatingSystem.IsAndroidVersionAtLeast(23))
{
alarmManager.SetAndAllowWhileIdle(AlarmType.RtcWakeup, when, pendingIntent);
else
alarmManager.Set(AlarmType.RtcWakeup, when, pendingIntent);
return;
}
alarmManager.Set(AlarmType.RtcWakeup, when, pendingIntent);
}
internal static void ShowNotification(
@@ -293,6 +320,14 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
Preferences.Default.Remove(PrefScheduledIds);
}
private static bool CanUseExactAlarms(Context context, AlarmManager alarmManager)
{
if (!OperatingSystem.IsAndroidVersionAtLeast(31))
return true;
return alarmManager.CanScheduleExactAlarms();
}
private static PendingIntentFlags BuildPendingIntentFlags()
{
var flags = PendingIntentFlags.UpdateCurrent;
@@ -352,4 +387,4 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
if (flags.HasFlag(NotificationWeekdays.Saturday)) yield return DayOfWeek.Saturday;
if (flags.HasFlag(NotificationWeekdays.Sunday)) yield return DayOfWeek.Sunday;
}
}
}
+1 -1
View File
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256"><rect width="256" height="256" fill="#0B1620"/><text x="50%" y="55%" dominant-baseline="middle" text-anchor="middle" font-size="96" fill="#D9E6F2">C</text></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256"><rect width="256" height="256" fill="#0B1620"/><text x="50%" y="55%" dominant-baseline="middle" text-anchor="middle" font-size="100" fill="#D9E6F2">Cfs</text></svg>

Before

Width:  |  Height:  |  Size: 226 B

After

Width:  |  Height:  |  Size: 229 B

+22 -31
View File
@@ -107,10 +107,10 @@ public sealed class PdfExportService : IPdfExportService
var currentDay = weekStart.AddDays(i).Date;
var dayEntries = entries.Where(x => x.EntryDate.Date == currentDay).OrderBy(x => x.Timestamp).ToList();
var averageState = CalculateAverageState(dayEntries);
var worstState = CalculateWorstState(dayEntries);
var statusText = dayEntries.Count == 0
? "—"
: $"{GetStateText(averageState!.Value)} ({dayEntries.Count})";
: $"{GetStateText(worstState!.Value)} ({dayEntries.Count})";
var activities = dayEntries
.Where(x => x.ActivityId.HasValue)
@@ -128,8 +128,8 @@ public sealed class PdfExportService : IPdfExportService
sb.AppendLine("<tr>");
sb.AppendLine($"<td>{Encode(currentDay.ToString("ddd, dd.MM.yyyy"))}</td>");
sb.AppendLine($"<td>{dayEntries.Count}</td>");
sb.AppendLine(averageState.HasValue
? StateCell(averageState.Value, statusText)
sb.AppendLine(worstState.HasValue
? StateCell(worstState.Value, statusText)
: "<td>—</td>");
sb.AppendLine($"<td>{Encode(activities.Count > 0 ? string.Join(", ", activities) : "—")}</td>");
sb.AppendLine($"<td>{Encode(symptoms.Count > 0 ? string.Join(", ", symptoms) : "—")}</td>");
@@ -175,10 +175,10 @@ public sealed class PdfExportService : IPdfExportService
var currentDay = new DateTime(year, month, day);
var dayEntries = entries.Where(x => x.EntryDate.Date == currentDay.Date).OrderBy(x => x.Timestamp).ToList();
var averageState = CalculateAverageState(dayEntries);
var worstState = CalculateWorstState(dayEntries);
var statusText = dayEntries.Count == 0
? "—"
: GetStateText(averageState!.Value);
: GetStateText(worstState!.Value);
var activities = dayEntries
.Where(x => x.ActivityId.HasValue)
@@ -196,8 +196,8 @@ public sealed class PdfExportService : IPdfExportService
sb.AppendLine("<tr>");
sb.AppendLine($"<td class=\"compact-day\">{Encode(currentDay.ToString("dd.MM."))}</td>");
sb.AppendLine($"<td class=\"compact-count\">{dayEntries.Count}</td>");
sb.AppendLine(averageState.HasValue
? StateCellCompact(averageState.Value, statusText)
sb.AppendLine(worstState.HasValue
? StateCellCompact(worstState.Value, statusText)
: "<td>—</td>");
sb.AppendLine($"<td class=\"compact-activity\">{Encode(activities.Count > 0 ? string.Join(", ", activities) : "—")}</td>");
sb.AppendLine($"<td class=\"compact-symptoms\">{Encode(symptoms.Count > 0 ? string.Join(", ", symptoms) : "—")}</td>");
@@ -236,11 +236,11 @@ public sealed class PdfExportService : IPdfExportService
.ToList();
var monthDate = new DateTime(year, month, 1);
var averageState = CalculateAverageState(monthEntries);
var worstState = CalculateWorstState(monthEntries);
var statusText = monthEntries.Count == 0
? "—"
: $"{GetStateText(averageState!.Value)} ({monthEntries.Count})";
: $"{GetStateText(worstState!.Value)} ({monthEntries.Count})";
var activities = monthEntries
.Where(x => x.ActivityId.HasValue)
@@ -258,8 +258,8 @@ public sealed class PdfExportService : IPdfExportService
sb.AppendLine("<tr>");
sb.AppendLine($"<td>{Encode(monthDate.ToString("MMMM"))}</td>");
sb.AppendLine($"<td>{monthEntries.Count}</td>");
sb.AppendLine(averageState.HasValue
? StateCell(averageState.Value, statusText)
sb.AppendLine(worstState.HasValue
? StateCell(worstState.Value, statusText)
: "<td>—</td>");
sb.AppendLine($"<td>{Encode(activities.Count > 0 ? string.Join(", ", activities) : "—")}</td>");
sb.AppendLine($"<td>{Encode(symptoms.Count > 0 ? string.Join(", ", symptoms) : "—")}</td>");
@@ -384,32 +384,23 @@ public sealed class PdfExportService : IPdfExportService
return date.Date.AddDays(-diff);
}
private static HealthState? CalculateAverageState(IReadOnlyCollection<HealthEntry> entries)
private static HealthState? CalculateWorstState(IReadOnlyCollection<HealthEntry> entries)
{
if (entries.Count == 0)
return null;
var average = entries.Average(x => StateToNumber(x.State));
var rounded = (int)Math.Round(average, MidpointRounding.AwayFromZero);
if (entries.Any(x => x.State == HealthState.Gray))
return HealthState.Gray;
return rounded switch
{
<= 0 => HealthState.Green,
1 => HealthState.Yellow,
2 => HealthState.Red,
_ => 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 int StateToNumber(HealthState state) => state switch
{
HealthState.Green => 0,
HealthState.Yellow => 1,
HealthState.Red => 2,
HealthState.Gray => 3,
_ => 0
};
private static string ToCssHex(Color color)
{
var r = (int)Math.Round(color.Red * 255);
+3 -4
View File
@@ -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;
}
}
+41 -11
View File
@@ -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;
+18 -2
View File
@@ -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
}
}
}
+43 -6
View File
@@ -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
View File
@@ -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
};
}
}
}
+82 -88
View File
@@ -8,96 +8,90 @@
Title="Monat"
BackgroundColor="{DynamicResource AppBackground}">
<ScrollView>
<VerticalStackLayout Padding="16" Spacing="16">
<Grid ColumnDefinitions="Auto,*,Auto"
VerticalOptions="Center">
<Button Text="←"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding PreviousMonthCommand}" />
<Label Grid.Column="1"
Text="{Binding HeaderText}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="20"
FontAttributes="Bold"
TextColor="{DynamicResource TextPrimary}" />
<Button Grid.Column="2"
Text="→"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding NextMonthCommand}" />
</Grid>
<Grid RowDefinitions="Auto,Auto,Auto,*"
Padding="16"
RowSpacing="12">
<Grid ColumnDefinitions="*,*"
ColumnSpacing="12">
<Button Text="Heute"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding TodayCommand}" />
<Button Grid.Column="1"
Text="Export"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding ExportPdfCommand}" />
</Grid>
<Grid Grid.Row="0"
ColumnDefinitions="Auto,*,Auto"
ColumnSpacing="12">
<Button Text="◀"
Command="{Binding PreviousMonthCommand}"
Style="{StaticResource SecondaryButtonStyle}" />
<Grid ColumnDefinitions="*,*,*,*,*,*,*"
ColumnSpacing="4">
<Label Text="Mo" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="1" Text="Di" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="2" Text="Mi" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="3" Text="Do" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="4" Text="Fr" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="5" Text="Sa" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="6" Text="So" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
</Grid>
<Label Grid.Column="1"
Text="{Binding HeaderText}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="22"
FontAttributes="Bold"
TextColor="{DynamicResource TextPrimary}" />
<CollectionView ItemsSource="{Binding Cells}"
SelectionMode="None">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="7" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModels:MonthCellViewModel">
<Border Margin="2"
Padding="6"
Stroke="{Binding BorderColor}"
BackgroundColor="{DynamicResource SurfaceBackground}"
StrokeShape="RoundRectangle 10">
<Border.Triggers>
<DataTrigger TargetType="Border"
Binding="{Binding IsPlaceholder}"
Value="True">
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="StrokeThickness" Value="0" />
</DataTrigger>
</Border.Triggers>
<Button Grid.Column="2"
Text="▶"
Command="{Binding NextMonthCommand}"
Style="{StaticResource SecondaryButtonStyle}" />
</Grid>
<Border.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type viewModels:MonthViewModel}}, Path=OpenDayCommand, x:DataType='viewModels:MonthViewModel'}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Grid Grid.Row="1"
ColumnDefinitions="*,*"
ColumnSpacing="12">
<Button Text="Heute"
Command="{Binding TodayCommand}"
Style="{StaticResource SecondaryButtonStyle}" />
<Button Grid.Column="1"
Text="Export"
Command="{Binding ExportPdfCommand}"
Style="{StaticResource PrimaryButtonStyle}" />
</Grid>
<VerticalStackLayout Spacing="4">
<Label Text="{Binding DayNumberText}"
IsVisible="{Binding ShowDayNumber}"
FontAttributes="Bold"
TextColor="{Binding TextColor}" />
<Border Padding="4"
IsVisible="{Binding ShowAverage}"
StrokeThickness="0"
StrokeShape="RoundRectangle 8"
BackgroundColor="{Binding StateColor}">
<Label Text="{Binding AverageStateText}"
FontSize="11"
HorizontalTextAlignment="Center"
TextColor="White" />
</Border>
</VerticalStackLayout>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
<Grid Grid.Row="2"
ColumnDefinitions="*,*,*,*,*,*,*"
ColumnSpacing="6"
Padding="2,0">
<Label Text="Mo" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="1" Text="Di" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="2" Text="Mi" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="3" Text="Do" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="4" Text="Fr" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="5" Text="Sa" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="6" Text="So" HorizontalTextAlignment="Center" TextColor="{DynamicResource TextMuted}" />
</Grid>
<CollectionView Grid.Row="3"
ItemsSource="{Binding Cells}"
SelectionMode="None">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="7"
VerticalItemSpacing="6"
HorizontalItemSpacing="6" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModels:MonthCellViewModel">
<Border Stroke="{Binding BorderColor}"
BackgroundColor="{Binding BackgroundColor}"
StrokeShape="RoundRectangle 10"
Padding="6"
MinimumHeightRequest="58">
<Border.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference RootPage}, Path=BindingContext.OpenDayCommand}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Grid>
<Label Text="{Binding DayNumberText}"
IsVisible="{Binding ShowDayNumber}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontAttributes="Bold"
FontSize="15"
TextColor="{Binding TextColor}" />
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</ContentPage>
+42 -11
View File
@@ -154,8 +154,23 @@
TextColor="{DynamicResource TextMuted}" />
<Grid ColumnDefinitions="Auto,*"
ColumnSpacing="8">
<CheckBox IsChecked="{Binding NotificationVibrationEnabled}" />
ColumnSpacing="12">
<Button Text="{Binding NotificationVibrationButtonText}"
Style="{StaticResource DayToggleButtonStyle}"
Command="{Binding ToggleNotificationVibrationCommand}"
VerticalOptions="Center">
<Button.Triggers>
<DataTrigger TargetType="Button"
Binding="{Binding NotificationVibrationEnabled}"
Value="True">
<Setter Property="BackgroundColor"
Value="{DynamicResource ButtonSecondaryBackground}" />
<Setter Property="TextColor"
Value="{DynamicResource ButtonSecondaryText}" />
</DataTrigger>
</Button.Triggers>
</Button>
<VerticalStackLayout Grid.Column="1"
Spacing="2">
<Label Text="Vibration für Push-Nachrichten"
@@ -179,16 +194,26 @@
Stroke="{DynamicResource Border}"
BackgroundColor="{DynamicResource SurfaceBackgroundAlt}">
<VerticalStackLayout Spacing="10">
<Grid ColumnDefinitions="*,Auto,Auto"
<Grid ColumnDefinitions="*,Auto"
ColumnSpacing="8">
<TimePicker Time="{Binding SelectedTime}" />
<CheckBox Grid.Column="1"
IsChecked="{Binding IsEnabled}"
VerticalOptions="Center" />
<Label Grid.Column="2"
Text="Aktiv"
VerticalOptions="Center"
TextColor="{DynamicResource TextPrimary}" />
<Button Grid.Column="1"
Text="{Binding IsEnabledButtonText}"
Style="{StaticResource DayToggleButtonStyle}"
Command="{Binding ToggleIsEnabledCommand}"
VerticalOptions="Center">
<Button.Triggers>
<DataTrigger TargetType="Button"
Binding="{Binding IsEnabled}"
Value="True">
<Setter Property="BackgroundColor"
Value="{DynamicResource ButtonSecondaryBackground}" />
<Setter Property="TextColor"
Value="{DynamicResource ButtonSecondaryText}" />
</DataTrigger>
</Button.Triggers>
</Button>
</Grid>
<Grid ColumnDefinitions="*,*,*,*,*,*,*"
@@ -207,6 +232,7 @@
</DataTrigger>
</Button.Triggers>
</Button>
<Button Grid.Column="1"
Text="Di"
Style="{StaticResource DayToggleButtonStyle}"
@@ -222,6 +248,7 @@
</DataTrigger>
</Button.Triggers>
</Button>
<Button Grid.Column="2"
Text="Mi"
Style="{StaticResource DayToggleButtonStyle}"
@@ -237,6 +264,7 @@
</DataTrigger>
</Button.Triggers>
</Button>
<Button Grid.Column="3"
Text="Do"
Style="{StaticResource DayToggleButtonStyle}"
@@ -252,6 +280,7 @@
</DataTrigger>
</Button.Triggers>
</Button>
<Button Grid.Column="4"
Text="Fr"
Style="{StaticResource DayToggleButtonStyle}"
@@ -267,6 +296,7 @@
</DataTrigger>
</Button.Triggers>
</Button>
<Button Grid.Column="5"
Text="Sa"
Style="{StaticResource DayToggleButtonStyle}"
@@ -282,6 +312,7 @@
</DataTrigger>
</Button.Triggers>
</Button>
<Button Grid.Column="6"
Text="So"
Style="{StaticResource DayToggleButtonStyle}"
@@ -633,4 +664,4 @@
</Border>
</Grid>
</Grid>
</ContentPage>
</ContentPage>
+80 -106
View File
@@ -8,132 +8,106 @@
Title="Jahr"
BackgroundColor="{DynamicResource AppBackground}">
<Grid Padding="16"
RowSpacing="16"
RowDefinitions="Auto,Auto,*">
<Grid RowDefinitions="Auto,Auto,*"
Padding="16"
RowSpacing="12">
<Grid Grid.Row="0"
ColumnDefinitions="Auto,*,Auto"
ColumnSpacing="12">
<Button Text="◀"
Command="{Binding PreviousYearCommand}"
Style="{StaticResource SecondaryButtonStyle}" />
<Grid ColumnDefinitions="Auto,*,Auto"
VerticalOptions="Center">
<Button Text="←"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding PreviousYearCommand}" />
<Label Grid.Column="1"
Text="{Binding HeaderText}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="20"
FontAttributes="Bold"
TextColor="{DynamicResource TextPrimary}" />
Text="{Binding HeaderText}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="22"
FontAttributes="Bold"
TextColor="{DynamicResource TextPrimary}" />
<Button Grid.Column="2"
Text="→"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding NextYearCommand}" />
Text="▶"
Command="{Binding NextYearCommand}"
Style="{StaticResource SecondaryButtonStyle}" />
</Grid>
<Grid Grid.Row="1"
ColumnDefinitions="*,*"
ColumnSpacing="12">
<Button Text="Heute"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding TodayCommand}" />
Command="{Binding TodayCommand}"
Style="{StaticResource SecondaryButtonStyle}" />
<Button Grid.Column="1"
Text="Export"
Style="{StaticResource PrimaryButtonStyle}"
Command="{Binding ExportPdfCommand}" />
Command="{Binding ExportPdfCommand}"
Style="{StaticResource PrimaryButtonStyle}" />
</Grid>
<CollectionView Grid.Row="2"
ItemsSource="{Binding Months}"
SelectionMode="None"
VerticalOptions="Fill"
HorizontalOptions="Fill"
ItemSizingStrategy="MeasureAllItems">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModels:MonthSectionViewModel">
<Border Padding="12"
Margin="0,0,0,12"
Stroke="{DynamicResource Border}"
BackgroundColor="{DynamicResource SurfaceBackground}"
StrokeShape="RoundRectangle 14">
<VerticalStackLayout Spacing="10">
<Label Text="{Binding Title}"
FontSize="18"
FontAttributes="Bold"
TextColor="{DynamicResource TextPrimary}" />
<ScrollView Grid.Row="2">
<VerticalStackLayout BindableLayout.ItemsSource="{Binding Months}"
Spacing="14">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="viewModels:MonthSectionViewModel">
<Border Stroke="{DynamicResource Border}"
BackgroundColor="{DynamicResource SurfaceBackground}"
StrokeShape="RoundRectangle 12"
Padding="10">
<VerticalStackLayout Spacing="8">
<Label Text="{Binding Title}"
FontSize="18"
FontAttributes="Bold"
TextColor="{DynamicResource TextPrimary}" />
<Grid ColumnDefinitions="*,*,*,*,*,*,*"
ColumnSpacing="4">
<Label Text="Mo" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="1" Text="Di" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="2" Text="Mi" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="3" Text="Do" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="4" Text="Fr" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="5" Text="Sa" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="6" Text="So" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
</Grid>
<Grid ColumnDefinitions="*,*,*,*,*,*,*"
ColumnSpacing="4">
<Label Text="Mo" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="1" Text="Di" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="2" Text="Mi" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="3" Text="Do" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="4" Text="Fr" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="5" Text="Sa" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
<Label Grid.Column="6" Text="So" HorizontalTextAlignment="Center" FontSize="11" TextColor="{DynamicResource TextMuted}" />
</Grid>
<CollectionView ItemsSource="{Binding Cells}"
SelectionMode="None"
ItemSizingStrategy="MeasureFirstItem">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="7" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModels:MonthCellViewModel">
<Border Margin="2"
Padding="4"
WidthRequest="46"
HeightRequest="46"
Stroke="{Binding BorderColor}"
BackgroundColor="{DynamicResource SurfaceBackgroundAlt}"
StrokeShape="RoundRectangle 8">
<Border.Triggers>
<DataTrigger TargetType="Border"
Binding="{Binding IsPlaceholder}"
Value="True">
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="StrokeThickness" Value="0" />
</DataTrigger>
</Border.Triggers>
<CollectionView ItemsSource="{Binding Cells}"
SelectionMode="None">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="7"
VerticalItemSpacing="4"
HorizontalItemSpacing="4" />
</CollectionView.ItemsLayout>
<Border.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type viewModels:YearViewModel}}, Path=OpenDayCommand, x:DataType='viewModels:YearViewModel'}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModels:MonthCellViewModel">
<Border Stroke="{Binding BorderColor}"
BackgroundColor="{Binding BackgroundColor}"
StrokeShape="RoundRectangle 8"
Padding="3"
MinimumHeightRequest="30">
<Border.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference RootPage}, Path=BindingContext.OpenDayCommand}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Grid RowDefinitions="Auto,*">
<Label Text="{Binding DayNumberText}"
IsVisible="{Binding ShowDayNumber}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="11"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
TextColor="{Binding TextColor}" />
<Border Grid.Row="1"
IsVisible="{Binding ShowAverage}"
Margin="0,4,0,0"
Padding="2"
StrokeThickness="0"
StrokeShape="RoundRectangle 5"
BackgroundColor="{Binding StateColor}">
<Label Text="{Binding AverageStateText}"
FontSize="9"
LineBreakMode="TailTruncation"
MaxLines="1"
HorizontalTextAlignment="Center"
TextColor="White" />
</Border>
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</Border>
</DataTemplate>
</BindableLayout.ItemTemplate>
</VerticalStackLayout>
</ScrollView>
</Grid>
</ContentPage>
</ContentPage>