From 8615d1de07a631df92df2676aecb0b263fb68791 Mon Sep 17 00:00:00 2001 From: Jurij Date: Thu, 19 Mar 2026 23:11:13 +0100 Subject: [PATCH] First version --- App.xaml | 33 ++ App.xaml.cs | 17 + AppShell.xaml | 28 ++ AppShell.xaml.cs | 12 + Data/AppDatabase.cs | 26 ++ Data/HealthEntryRepository.cs | 181 ++++++++ MainPage.xaml | 36 ++ MainPage.xaml.cs | 24 + MauiProgram.cs | 44 ++ Models/CalendarDaySummary.cs | 12 + Models/DayDetailSummary.cs | 14 + Models/DayPart.cs | 7 + Models/EntrySource.cs | 8 + Models/HealthEntry.cs | 16 + Models/HealthState.cs | 10 + Models/HealthStateExtensions.cs | 28 ++ Models/WeekDaySummary.cs | 13 + Platforms/Android/AndroidManifest.xml | 6 + Platforms/Android/MainActivity.cs | 22 + Platforms/Android/MainApplication.cs | 16 + Platforms/Android/Resources/values/colors.xml | 6 + Platforms/MacCatalyst/AppDelegate.cs | 10 + Platforms/MacCatalyst/Entitlements.plist | 14 + Platforms/MacCatalyst/Info.plist | 40 ++ Platforms/MacCatalyst/Program.cs | 16 + Platforms/Windows/App.xaml | 8 + Platforms/Windows/App.xaml.cs | 25 + Platforms/Windows/Package.appxmanifest | 46 ++ Platforms/Windows/app.manifest | 17 + Platforms/iOS/AppDelegate.cs | 10 + Platforms/iOS/Info.plist | 32 ++ Platforms/iOS/Program.cs | 16 + Platforms/iOS/Resources/PrivacyInfo.xcprivacy | 51 ++ Properties/launchSettings.json | 8 + Resources/AppIcon/appicon.svg | 4 + Resources/AppIcon/appiconfg.svg | 8 + Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107280 bytes Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111204 bytes Resources/Images/dotnet_bot.png | Bin 0 -> 92532 bytes Resources/Raw/AboutAssets.txt | 15 + Resources/Splash/splash.svg | 8 + Resources/Styles/Colors.xaml | 44 ++ Resources/Styles/Styles.xaml | 434 ++++++++++++++++++ Services/AggregationService.cs | 123 +++++ Services/INotificationService.cs | 8 + Services/PdfExportService.cs | 24 + ViewModels/CalendarViewModel.cs | 36 ++ ViewModels/DayEntryItemViewModel.cs | 60 +++ ViewModels/DayViewModel.cs | 111 +++++ ViewModels/MonthCellViewModel.cs | 26 ++ ViewModels/MonthViewModel.cs | 121 +++++ ViewModels/OptionsViewModel.cs | 45 ++ ViewModels/QuickEntryViewModel.cs | 120 +++++ ViewModels/WeekCellViewModel.cs | 25 + ViewModels/WeekViewModel.cs | 140 ++++++ ViewModels/YearMonthViewModel.cs | 11 + ViewModels/YearViewModel.cs | 130 ++++++ Views/DayPage.xaml | 113 +++++ Views/DayPage.xaml.cs | 20 + Views/MonthPage.xaml | 96 ++++ Views/MonthPage.xaml.cs | 20 + Views/Options.xaml | 56 +++ Views/Options.xaml.cs | 12 + Views/QuickEntryPage.xaml | 95 ++++ Views/QuickEntryPage.xaml.cs | 21 + Views/WeekPage.xaml | 107 +++++ Views/WeekPage.xaml.cs | 20 + Views/YearPage.xaml | 127 +++++ Views/YearPage.xaml.cs | 20 + cfs-tracker.csproj | 73 +++ cfs-tracker.slnx | 3 + 71 files changed, 3128 insertions(+) create mode 100644 App.xaml create mode 100644 App.xaml.cs create mode 100644 AppShell.xaml create mode 100644 AppShell.xaml.cs create mode 100644 Data/AppDatabase.cs create mode 100644 Data/HealthEntryRepository.cs create mode 100644 MainPage.xaml create mode 100644 MainPage.xaml.cs create mode 100644 MauiProgram.cs create mode 100644 Models/CalendarDaySummary.cs create mode 100644 Models/DayDetailSummary.cs create mode 100644 Models/DayPart.cs create mode 100644 Models/EntrySource.cs create mode 100644 Models/HealthEntry.cs create mode 100644 Models/HealthState.cs create mode 100644 Models/HealthStateExtensions.cs create mode 100644 Models/WeekDaySummary.cs create mode 100644 Platforms/Android/AndroidManifest.xml create mode 100644 Platforms/Android/MainActivity.cs create mode 100644 Platforms/Android/MainApplication.cs create mode 100644 Platforms/Android/Resources/values/colors.xml create mode 100644 Platforms/MacCatalyst/AppDelegate.cs create mode 100644 Platforms/MacCatalyst/Entitlements.plist create mode 100644 Platforms/MacCatalyst/Info.plist create mode 100644 Platforms/MacCatalyst/Program.cs create mode 100644 Platforms/Windows/App.xaml create mode 100644 Platforms/Windows/App.xaml.cs create mode 100644 Platforms/Windows/Package.appxmanifest create mode 100644 Platforms/Windows/app.manifest create mode 100644 Platforms/iOS/AppDelegate.cs create mode 100644 Platforms/iOS/Info.plist create mode 100644 Platforms/iOS/Program.cs create mode 100644 Platforms/iOS/Resources/PrivacyInfo.xcprivacy create mode 100644 Properties/launchSettings.json create mode 100644 Resources/AppIcon/appicon.svg create mode 100644 Resources/AppIcon/appiconfg.svg create mode 100644 Resources/Fonts/OpenSans-Regular.ttf create mode 100644 Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 Resources/Images/dotnet_bot.png create mode 100644 Resources/Raw/AboutAssets.txt create mode 100644 Resources/Splash/splash.svg create mode 100644 Resources/Styles/Colors.xaml create mode 100644 Resources/Styles/Styles.xaml create mode 100644 Services/AggregationService.cs create mode 100644 Services/INotificationService.cs create mode 100644 Services/PdfExportService.cs create mode 100644 ViewModels/CalendarViewModel.cs create mode 100644 ViewModels/DayEntryItemViewModel.cs create mode 100644 ViewModels/DayViewModel.cs create mode 100644 ViewModels/MonthCellViewModel.cs create mode 100644 ViewModels/MonthViewModel.cs create mode 100644 ViewModels/OptionsViewModel.cs create mode 100644 ViewModels/QuickEntryViewModel.cs create mode 100644 ViewModels/WeekCellViewModel.cs create mode 100644 ViewModels/WeekViewModel.cs create mode 100644 ViewModels/YearMonthViewModel.cs create mode 100644 ViewModels/YearViewModel.cs create mode 100644 Views/DayPage.xaml create mode 100644 Views/DayPage.xaml.cs create mode 100644 Views/MonthPage.xaml create mode 100644 Views/MonthPage.xaml.cs create mode 100644 Views/Options.xaml create mode 100644 Views/Options.xaml.cs create mode 100644 Views/QuickEntryPage.xaml create mode 100644 Views/QuickEntryPage.xaml.cs create mode 100644 Views/WeekPage.xaml create mode 100644 Views/WeekPage.xaml.cs create mode 100644 Views/YearPage.xaml create mode 100644 Views/YearPage.xaml.cs create mode 100644 cfs-tracker.csproj create mode 100644 cfs-tracker.slnx diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..3ff38bc --- /dev/null +++ b/App.xaml @@ -0,0 +1,33 @@ + + + + + + + #4CAF50 + #FBC02D + #E53935 + #757575 + + #F2F2F2 + #D0D0D0 + + + + + + + + + + \ No newline at end of file diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..cb90803 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace cfs_tracker +{ + public partial class App : Application + { + public App() + { + InitializeComponent(); + } + + protected override Window CreateWindow(IActivationState? activationState) + { + return new Window(new AppShell()); + } + } +} \ No newline at end of file diff --git a/AppShell.xaml b/AppShell.xaml new file mode 100644 index 0000000..8ca276d --- /dev/null +++ b/AppShell.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AppShell.xaml.cs b/AppShell.xaml.cs new file mode 100644 index 0000000..773ea14 --- /dev/null +++ b/AppShell.xaml.cs @@ -0,0 +1,12 @@ +using cfs_tracker.Views; + +namespace cfs_tracker; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + Routing.RegisterRoute(nameof(QuickEntryPage), typeof(QuickEntryPage)); + } +} \ No newline at end of file diff --git a/Data/AppDatabase.cs b/Data/AppDatabase.cs new file mode 100644 index 0000000..2a6005b --- /dev/null +++ b/Data/AppDatabase.cs @@ -0,0 +1,26 @@ +using SQLite; +using cfs_tracker.Models; + +namespace cfs_tracker.Data; + +public class AppDatabase +{ + private SQLiteAsyncConnection? _database; + private bool _initialized; + + public async Task InitAsync() + { + if (_initialized) + return; + + var dbPath = Path.Combine(FileSystem.Current.AppDataDirectory, "mecfs_tracker.db3"); + + _database = new SQLiteAsyncConnection(dbPath); + await _database.CreateTableAsync(); + + _initialized = true; + } + + public SQLiteAsyncConnection Connection => + _database ?? throw new InvalidOperationException("Database not initialized."); +} \ No newline at end of file diff --git a/Data/HealthEntryRepository.cs b/Data/HealthEntryRepository.cs new file mode 100644 index 0000000..20a222a --- /dev/null +++ b/Data/HealthEntryRepository.cs @@ -0,0 +1,181 @@ +using cfs_tracker.Models; + +namespace cfs_tracker.Data; + +public class HealthEntryRepository +{ + private readonly AppDatabase _database; + + public HealthEntryRepository(AppDatabase database) + { + _database = database; + } + + public async Task AddEntryAsync( + HealthState state, + EntrySource source, + DateTime? timestamp = null) + { + await _database.InitAsync(); + + var entry = new HealthEntry + { + Timestamp = timestamp ?? DateTime.Now, + State = state, + Source = source, + UpdatedAt = DateTime.Now + }; + + await _database.Connection.InsertAsync(entry); + } + + public async Task UpsertBackfillAsync( + DateTime date, + DayPart part, + HealthState state, + EntrySource source) + { + await _database.InitAsync(); + + var slotTimestamp = BuildSlotTimestamp(date, part); + + var existing = await _database.Connection.Table() + .FirstOrDefaultAsync(x => x.Timestamp == slotTimestamp); + + if (existing is null) + { + var entry = new HealthEntry + { + Timestamp = slotTimestamp, + State = state, + Source = source, + UpdatedAt = DateTime.Now + }; + + await _database.Connection.InsertAsync(entry); + } + else + { + existing.State = state; + existing.Source = source; + existing.UpdatedAt = DateTime.Now; + + await _database.Connection.UpdateAsync(existing); + } + } + + public async Task GetBackfillEntryAsync(DateTime date, DayPart part) + { + await _database.InitAsync(); + + var slotTimestamp = BuildSlotTimestamp(date, part); + + return await _database.Connection.Table() + .FirstOrDefaultAsync(x => x.Timestamp == slotTimestamp); + } + + public async Task> GetEntriesForDateAsync(DateTime date) + { + await _database.InitAsync(); + + var start = date.Date; + var end = start.AddDays(1); + + var list = await _database.Connection.Table() + .Where(x => x.Timestamp >= start && x.Timestamp < end) + .ToListAsync(); + + return list + .OrderBy(x => x.Timestamp) + .ToList(); + } + + public async Task> GetEntriesBetweenAsync(DateTime startDate, DateTime endDate) + { + await _database.InitAsync(); + + var start = startDate.Date; + var end = endDate.Date; + + var list = await _database.Connection.Table() + .Where(x => x.Timestamp >= start && x.Timestamp < end) + .ToListAsync(); + + return list + .OrderBy(x => x.Timestamp) + .ToList(); + } + + public async Task> GetMonthEntriesAsync(int year, int month) + { + var start = new DateTime(year, month, 1); + var end = start.AddMonths(1); + + return await GetEntriesBetweenAsync(start, end); + } + + public async Task> GetYearEntriesAsync(int year) + { + var start = new DateTime(year, 1, 1); + var end = start.AddYears(1); + + return await GetEntriesBetweenAsync(start, end); + } + + public async Task DeleteEntryAsync(int id) + { + await _database.InitAsync(); + + var item = await _database.Connection.Table() + .FirstOrDefaultAsync(x => x.Id == id); + + if (item is not null) + await _database.Connection.DeleteAsync(item); + } + + public async Task DeleteBackfillEntryAsync(DateTime date, DayPart part) + { + await _database.InitAsync(); + + var slotTimestamp = BuildSlotTimestamp(date, part); + + var item = await _database.Connection.Table() + .FirstOrDefaultAsync(x => x.Timestamp == slotTimestamp); + + if (item is not null) + await _database.Connection.DeleteAsync(item); + } + + public async Task DeleteAllAsync() + { + await _database.InitAsync(); + await _database.Connection.DeleteAllAsync(); + } + + public async Task<(HealthEntry? Morning, HealthEntry? Afternoon)> GetBackfillSlotsAsync(DateTime date) + { + await _database.InitAsync(); + + var morningTimestamp = BuildSlotTimestamp(date, DayPart.Morning); + var afternoonTimestamp = BuildSlotTimestamp(date, DayPart.Afternoon); + + var items = await _database.Connection.Table() + .Where(x => x.Timestamp == morningTimestamp || x.Timestamp == afternoonTimestamp) + .ToListAsync(); + + var morning = items.FirstOrDefault(x => x.Timestamp == morningTimestamp); + var afternoon = items.FirstOrDefault(x => x.Timestamp == afternoonTimestamp); + + return (morning, afternoon); + } + + private static DateTime BuildSlotTimestamp(DateTime date, DayPart part) + { + return part switch + { + DayPart.Morning => date.Date.AddHours(9), + DayPart.Afternoon => date.Date.AddHours(15), + _ => date.Date.AddHours(9) + }; + } +} \ No newline at end of file diff --git a/MainPage.xaml b/MainPage.xaml new file mode 100644 index 0000000..1646f13 --- /dev/null +++ b/MainPage.xaml @@ -0,0 +1,36 @@ + + + + + + + +