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
+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
};
}
}
}