diff --git a/Models/TrackingEnums.cs b/Models/TrackingEnums.cs index cb0e011..8f7ff99 100644 --- a/Models/TrackingEnums.cs +++ b/Models/TrackingEnums.cs @@ -21,3 +21,10 @@ public enum EntrySource : byte Notification = 2, Import = 3 } + +public enum ExportLayout : byte +{ + DayView = 0, + WeekBlock = 1, + DaySummary = 2 +} diff --git a/Platforms/Android/AndroidNotificationScheduler.cs b/Platforms/Android/AndroidNotificationScheduler.cs index 213ea54..50e5675 100644 --- a/Platforms/Android/AndroidNotificationScheduler.cs +++ b/Platforms/Android/AndroidNotificationScheduler.cs @@ -158,10 +158,12 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler requestCode, intent, BuildPendingIntentFlags()); + if (pendingIntent is null) + return; var when = triggerAt.ToUnixTimeMilliseconds(); - if (CanUseExactAlarms(context, alarmManager)) + if (OperatingSystem.IsAndroidVersionAtLeast(23) && CanUseExactAlarms(alarmManager)) { alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, when, pendingIntent); return; @@ -203,28 +205,50 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler var smallIcon = context.ApplicationInfo?.Icon ?? global::Android.Resource.Drawable.IcDialogInfo; - var builder = new NotificationCompat.Builder(context, channelId) - .SetSmallIcon(smallIcon) - .SetContentTitle(title) - .SetContentText(message) - .SetPriority((int)NotificationPriority.High) - .SetAutoCancel(true) - .SetContentIntent(openPendingIntent) - .SetOnlyAlertOnce(true) - .AddAction(0, yellowLabel, yellowPendingIntent) - .AddAction(0, redLabel, redPendingIntent) - .AddAction(0, grayLabel, grayPendingIntent); + var builder = new NotificationCompat.Builder(context, channelId); + builder.SetSmallIcon(smallIcon); + builder.SetContentTitle(title); + builder.SetContentText(message); + builder.SetPriority((int)NotificationPriority.High); + builder.SetAutoCancel(true); + builder.SetOnlyAlertOnce(true); + + if (openPendingIntent is not null) + builder.SetContentIntent(openPendingIntent); + + if (yellowPendingIntent is not null) + builder.AddAction(0, yellowLabel, yellowPendingIntent); + + if (redPendingIntent is not null) + builder.AddAction(0, redLabel, redPendingIntent); + + if (grayPendingIntent is not null) + builder.AddAction(0, grayLabel, grayPendingIntent); if (vibrationEnabled && !OperatingSystem.IsAndroidVersionAtLeast(26)) builder.SetVibrate(NotificationVibrationPattern); - NotificationManagerCompat.From(context).Notify(notificationId, builder.Build()); + var notification = builder.Build(); + if (notification is null) + return; + + var notificationManager = NotificationManagerCompat.From(context); + notificationManager?.Notify(notificationId, notification); } - private static PendingIntent CreateOpenQuickEntryPendingIntent(Context context, int notificationId, string date) + private static PendingIntent? CreateOpenQuickEntryPendingIntent(Context context, int notificationId, string date) { - var launchIntent = context.PackageManager?.GetLaunchIntentForPackage(context.PackageName) - ?? new Intent(context, typeof(MainActivity)); + Intent launchIntent; + var packageName = context.PackageName; + if (!string.IsNullOrWhiteSpace(packageName)) + { + launchIntent = context.PackageManager?.GetLaunchIntentForPackage(packageName) + ?? new Intent(context, typeof(MainActivity)); + } + else + { + launchIntent = new Intent(context, typeof(MainActivity)); + } launchIntent.SetAction(ActionOpenQuickEntry); launchIntent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop | ActivityFlags.NewTask); @@ -239,7 +263,7 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler BuildPendingIntentFlags()); } - private static PendingIntent CreateSaveStatusPendingIntent(Context context, int notificationId, string status, string date) + private static PendingIntent? CreateSaveStatusPendingIntent(Context context, int notificationId, string status, string date) { var intent = new Intent(context, typeof(CfsNotificationReceiver)); intent.SetAction(ActionSaveStatus); @@ -313,14 +337,17 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler intent, BuildPendingIntentFlags()); - alarmManager.Cancel(pendingIntent); - NotificationManagerCompat.From(context).Cancel(BuildNotificationId(scheduleId, day)); + if (pendingIntent is not null) + alarmManager.Cancel(pendingIntent); + + var notificationManager = NotificationManagerCompat.From(context); + notificationManager?.Cancel(BuildNotificationId(scheduleId, day)); } Preferences.Default.Remove(PrefScheduledIds); } - private static bool CanUseExactAlarms(Context context, AlarmManager alarmManager) + private static bool CanUseExactAlarms(AlarmManager alarmManager) { if (!OperatingSystem.IsAndroidVersionAtLeast(31)) return true; @@ -387,4 +414,4 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler if (flags.HasFlag(NotificationWeekdays.Saturday)) yield return DayOfWeek.Saturday; if (flags.HasFlag(NotificationWeekdays.Sunday)) yield return DayOfWeek.Sunday; } -} \ No newline at end of file +} diff --git a/Platforms/Android/CfsNotificationReceiver.cs b/Platforms/Android/CfsNotificationReceiver.cs index ccae4ef..a12530a 100644 --- a/Platforms/Android/CfsNotificationReceiver.cs +++ b/Platforms/Android/CfsNotificationReceiver.cs @@ -51,6 +51,8 @@ public sealed class CfsNotificationReceiver : BroadcastReceiver private void HandleSaveStatus(Context context, Intent intent) { var pendingResult = GoAsync(); + if (pendingResult is null) + return; _ = Task.Run(async () => { @@ -76,7 +78,8 @@ public sealed class CfsNotificationReceiver : BroadcastReceiver timestamp: DateTime.Now, source: EntrySource.App); - NotificationManagerCompat.From(context).Cancel(notificationId); + var notificationManager = NotificationManagerCompat.From(context); + notificationManager?.Cancel(notificationId); } finally { @@ -117,4 +120,4 @@ public sealed class CfsNotificationReceiver : BroadcastReceiver return false; } } -} \ No newline at end of file +} diff --git a/Services/IPdfExportService.cs b/Services/IPdfExportService.cs index 2d4c008..97c9a64 100644 --- a/Services/IPdfExportService.cs +++ b/Services/IPdfExportService.cs @@ -1,3 +1,5 @@ +using cfs_tracker.Models; + namespace cfs_tracker.Services; public interface IPdfExportService @@ -8,6 +10,7 @@ public interface IPdfExportService Task ExportMonthAsync(int year, int month); Task ExportYearAsync(DateTime date); Task ExportYearAsync(int year); + Task ExportRangeAsync(DateTime startDate, DateTime endDate, ExportLayout layout); Task ClearExportsAsync(); -} \ No newline at end of file +} diff --git a/Services/PdfExportService.cs b/Services/PdfExportService.cs index 95f3bee..3287f3b 100644 --- a/Services/PdfExportService.cs +++ b/Services/PdfExportService.cs @@ -40,6 +40,209 @@ public sealed class PdfExportService : IPdfExportService public Task ExportYearAsync(int year) => ExportYearHtmlAsync(year); + public Task ExportRangeAsync(DateTime startDate, DateTime endDate, ExportLayout layout) + { + var (rangeStart, rangeEnd) = NormalizeDateRange(startDate, endDate); + + return layout switch + { + ExportLayout.DayView => ExportDayRangeHtmlAsync(rangeStart, rangeEnd), + ExportLayout.WeekBlock => ExportWeekBlockRangeHtmlAsync(rangeStart, rangeEnd), + _ => ExportDaySummaryRangeHtmlAsync(rangeStart, rangeEnd) + }; + } + + private async Task ExportDayRangeHtmlAsync(DateTime startDate, DateTime endDate) + { + var entries = await _healthEntryRepository.GetEntriesBetweenAsync(startDate, endDate.AddDays(1)); + var activityNames = await GetActivityNamesAsync(); + var symptomNamesByEntry = await GetSymptomNamesByEntryAsync(entries.Select(x => x.Id)); + + var sb = new StringBuilder(); + sb.AppendLine("

Export - Tagesansicht

"); + sb.AppendLine($"

Zeitraum: {Encode(FormatDateRange(startDate, endDate))}

"); + + var currentDay = startDate.Date; + var isFirstSection = true; + + while (currentDay <= endDate.Date) + { + var dayEntries = entries + .Where(x => x.EntryDate.Date == currentDay) + .OrderBy(x => x.Timestamp) + .ThenBy(x => x.Id) + .ToList(); + + if (dayEntries.Count == 0) + { + currentDay = currentDay.AddDays(1); + continue; + } + + if (!isFirstSection) + sb.AppendLine("
"); + + sb.AppendLine("
"); + sb.AppendLine($"

{Encode(currentDay.ToString("dddd, dd.MM.yyyy", DateHelper.GermanCulture))}

"); + AppendDayDetailTable(sb, dayEntries, activityNames, symptomNamesByEntry); + sb.AppendLine("
"); + + currentDay = currentDay.AddDays(1); + isFirstSection = false; + } + + if (isFirstSection) + sb.AppendLine("

Keine Einträge im gewählten Zeitraum vorhanden.

"); + + return await SaveHtmlAsync( + fileName: $"export-tagesansicht-{startDate:yyyy-MM-dd}-bis-{endDate:yyyy-MM-dd}.html", + title: $"Export Tagesansicht {FormatDateRange(startDate, endDate)}", + bodyHtml: sb.ToString()); + } + + private async Task ExportWeekBlockRangeHtmlAsync(DateTime startDate, DateTime endDate) + { + var entries = await _healthEntryRepository.GetEntriesBetweenAsync(startDate, endDate.AddDays(1)); + var activityNames = await GetActivityNamesAsync(); + var symptomNamesByEntry = await GetSymptomNamesByEntryAsync(entries.Select(x => x.Id)); + + var sb = new StringBuilder(); + sb.AppendLine("

Export - Wochenblock

"); + sb.AppendLine($"

Zeitraum: {Encode(FormatDateRange(startDate, endDate))}

"); + + var weekStart = StartOfWeekMonday(startDate); + var isFirstSection = true; + + while (weekStart <= endDate.Date) + { + var daysInBlock = Enumerable.Range(0, 7) + .Select(offset => weekStart.AddDays(offset)) + .Where(day => day.Date >= startDate.Date && day.Date <= endDate.Date) + .ToList(); + + if (daysInBlock.Count == 0) + { + weekStart = weekStart.AddDays(7); + continue; + } + + var weekEntries = entries + .Where(x => x.EntryDate.Date >= daysInBlock[0].Date && x.EntryDate.Date <= daysInBlock[^1].Date) + .ToList(); + + if (weekEntries.Count == 0) + { + weekStart = weekStart.AddDays(7); + continue; + } + + if (!isFirstSection) + sb.AppendLine("
"); + + sb.AppendLine("
"); + sb.AppendLine($"

Woche {Encode(weekStart.ToString("dd.MM.yyyy"))} bis {Encode(weekStart.AddDays(6).ToString("dd.MM.yyyy"))}

"); + sb.AppendLine(""); + sb.AppendLine(""); + sb.AppendLine(""); + + foreach (var currentDay in daysInBlock) + { + var dayEntries = entries + .Where(x => x.EntryDate.Date == currentDay.Date) + .OrderBy(x => x.Timestamp) + .ThenBy(x => x.Id) + .ToList(); + + var morningState = CalculateWorstState(FilterEntriesForDayPart(dayEntries, DayPart.Morning).ToList()); + var afternoonState = CalculateWorstState(FilterEntriesForDayPart(dayEntries, DayPart.Afternoon).ToList()); + + sb.AppendLine(""); + sb.AppendLine($""); + sb.AppendLine(morningState.HasValue + ? StateCell(morningState.Value, GetStateText(morningState.Value)) + : ""); + sb.AppendLine(afternoonState.HasValue + ? StateCell(afternoonState.Value, GetStateText(afternoonState.Value)) + : ""); + sb.AppendLine($""); + sb.AppendLine($""); + sb.AppendLine($""); + sb.AppendLine(""); + } + + sb.AppendLine("
TagVormittagNachmittagAnzahlTätigkeitenSymptome
{Encode(currentDay.ToString("ddd, dd.MM.yyyy", DateHelper.GermanCulture))}——{dayEntries.Count}{Encode(BuildDistinctActivityList(dayEntries, activityNames))}{Encode(BuildDistinctSymptomList(dayEntries, symptomNamesByEntry))}
"); + sb.AppendLine("
"); + + weekStart = weekStart.AddDays(7); + isFirstSection = false; + } + + if (isFirstSection) + sb.AppendLine("

Keine Einträge im gewählten Zeitraum vorhanden.

"); + + return await SaveHtmlAsync( + fileName: $"export-wochenblock-{startDate:yyyy-MM-dd}-bis-{endDate:yyyy-MM-dd}.html", + title: $"Export Wochenblock {FormatDateRange(startDate, endDate)}", + bodyHtml: sb.ToString(), + compactA4: true); + } + + private async Task ExportDaySummaryRangeHtmlAsync(DateTime startDate, DateTime endDate) + { + var entries = await _healthEntryRepository.GetEntriesBetweenAsync(startDate, endDate.AddDays(1)); + var activityNames = await GetActivityNamesAsync(); + var symptomNamesByEntry = await GetSymptomNamesByEntryAsync(entries.Select(x => x.Id)); + + var sb = new StringBuilder(); + sb.AppendLine("

Export - Tageszusammenfassung

"); + sb.AppendLine($"

Zeitraum: {Encode(FormatDateRange(startDate, endDate))}

"); + sb.AppendLine(""); + sb.AppendLine(""" + + + + + + + + + + +"""); + + var currentDay = startDate.Date; + while (currentDay <= endDate.Date) + { + var dayEntries = entries + .Where(x => x.EntryDate.Date == currentDay.Date) + .OrderBy(x => x.Timestamp) + .ThenBy(x => x.Id) + .ToList(); + + var worstState = CalculateWorstState(dayEntries); + + sb.AppendLine(""); + sb.AppendLine($""); + sb.AppendLine($""); + sb.AppendLine(worstState.HasValue + ? StateCellCompact(worstState.Value, GetStateText(worstState.Value)) + : ""); + sb.AppendLine($""); + sb.AppendLine($""); + sb.AppendLine(""); + + currentDay = currentDay.AddDays(1); + } + + sb.AppendLine("
TagAnzahlStatusTätigkeitenSymptome
{Encode(currentDay.ToString("ddd, dd.MM.yyyy", DateHelper.GermanCulture))}{dayEntries.Count}—{Encode(BuildDistinctActivityList(dayEntries, activityNames))}{Encode(BuildDistinctSymptomList(dayEntries, symptomNamesByEntry))}
"); + + return await SaveHtmlAsync( + fileName: $"export-tageszusammenfassung-{startDate:yyyy-MM-dd}-bis-{endDate:yyyy-MM-dd}.html", + title: $"Export Tageszusammenfassung {FormatDateRange(startDate, endDate)}", + bodyHtml: sb.ToString(), + compactA4: true); + } + private async Task ExportDayHtmlAsync(DateTime date) { var entries = await _healthEntryRepository.GetEntriesForDateAsync(date); @@ -315,6 +518,88 @@ public sealed class PdfExportService : IPdfExportService .ToList()); } + private void AppendDayDetailTable( + StringBuilder sb, + IReadOnlyList entries, + IReadOnlyDictionary activityNames, + IReadOnlyDictionary> symptomNamesByEntry) + { + var conflicts = DetectDayExportConflicts(entries); + if (conflicts.Count > 0) + sb.AppendLine(BuildConflictHtml(conflicts)); + + sb.AppendLine(""); + sb.AppendLine(""); + sb.AppendLine(""); + + foreach (var entry in entries) + { + var symptoms = symptomNamesByEntry.TryGetValue(entry.Id, out var symptomList) && symptomList.Count > 0 + ? string.Join(", ", symptomList) + : "—"; + + var activity = entry.ActivityId.HasValue && activityNames.TryGetValue(entry.ActivityId.Value, out var activityName) + ? activityName + : "—"; + + sb.AppendLine(""); + sb.AppendLine($""); + sb.AppendLine(StateCell(entry.State, GetStateText(entry.State))); + sb.AppendLine($""); + sb.AppendLine($""); + sb.AppendLine($""); + sb.AppendLine(""); + } + + if (entries.Count == 0) + sb.AppendLine(""); + + sb.AppendLine("
ZeitStatusTätigkeitDauerSymptome
{Encode(GetDayTimeLabel(entry))}{Encode(activity)}{Encode(FormatDuration(entry.ActivityDurationMinutes))}{Encode(symptoms)}
Keine Einträge vorhanden.
"); + } + + private string BuildDistinctActivityList(IEnumerable entries, IReadOnlyDictionary activityNames) + { + var activities = entries + .Where(x => x.ActivityId.HasValue && activityNames.ContainsKey(x.ActivityId.Value)) + .Select(x => activityNames[x.ActivityId!.Value]) + .Where(x => !string.IsNullOrWhiteSpace(x)) + .Where(x => !string.Equals(x, "Keine Tätigkeit", StringComparison.OrdinalIgnoreCase)) + .Distinct() + .OrderBy(x => x) + .ToList(); + + return activities.Count > 0 + ? string.Join(", ", activities) + : "—"; + } + + private static string BuildDistinctSymptomList(IEnumerable entries, IReadOnlyDictionary> symptomNamesByEntry) + { + var symptoms = entries + .Where(x => symptomNamesByEntry.ContainsKey(x.Id)) + .SelectMany(x => symptomNamesByEntry[x.Id]) + .Distinct() + .OrderBy(x => x) + .ToList(); + + return symptoms.Count > 0 + ? string.Join(", ", symptoms) + : "—"; + } + + private static IEnumerable FilterEntriesForDayPart(IEnumerable entries, DayPart part) + { + return entries.Where(x => + { + if (x.DayPart.HasValue) + return x.DayPart == part; + + return part == DayPart.Morning + ? x.Timestamp.Hour < 12 + : x.Timestamp.Hour >= 12; + }); + } + private async Task SaveHtmlAsync( string fileName, string title, @@ -378,6 +663,23 @@ public sealed class PdfExportService : IPdfExportService _ => string.Empty }; + private static (DateTime StartDate, DateTime EndDate) NormalizeDateRange(DateTime startDate, DateTime endDate) + { + var rangeStart = startDate.Date; + var rangeEnd = endDate.Date; + + return rangeEnd < rangeStart + ? (rangeEnd, rangeStart) + : (rangeStart, rangeEnd); + } + + private static string FormatDateRange(DateTime startDate, DateTime endDate) + { + return startDate.Date == endDate.Date + ? startDate.ToString("dd.MM.yyyy", DateHelper.GermanCulture) + : $"{startDate:dd.MM.yyyy} bis {endDate:dd.MM.yyyy}"; + } + private static DateTime StartOfWeekMonday(DateTime date) { var diff = ((int)date.DayOfWeek + 6) % 7; @@ -467,6 +769,24 @@ public sealed class PdfExportService : IPdfExportService font-size: {{(compactA4 ? "18px" : "28px")}}; } + h2 { + margin: {{(compactA4 ? "8px" : "16px")}} 0 {{(compactA4 ? "6px" : "10px")}} 0; + font-size: {{(compactA4 ? "15px" : "22px")}}; + } + + .summary-note { + margin: 0 0 {{(compactA4 ? "8px" : "14px")}} 0; + } + + .export-section + .export-section { + margin-top: {{(compactA4 ? "8px" : "14px")}}; + } + + .page-break { + break-before: page; + page-break-before: always; + } + table { width: 100%; border-collapse: collapse; @@ -512,6 +832,11 @@ public sealed class PdfExportService : IPdfExportService width: 32%; } + .summary-day { + width: 18%; + white-space: nowrap; + } + .conflict-box { border: 1px solid #000000; background: #fff8e1; @@ -609,4 +934,4 @@ public sealed class PdfExportService : IPdfExportService return sb.ToString(); } -} \ No newline at end of file +} diff --git a/ViewModels/OptionsViewModel.cs b/ViewModels/OptionsViewModel.cs index 062d40c..95470c1 100644 --- a/ViewModels/OptionsViewModel.cs +++ b/ViewModels/OptionsViewModel.cs @@ -48,6 +48,15 @@ public partial class OptionsViewModel : ObservableObject [ObservableProperty] private OptionsTab selectedTab = OptionsTab.Notifications; + [ObservableProperty] + private DateTime exportStartDate = DateTime.Today; + + [ObservableProperty] + private DateTime exportEndDate = DateTime.Today; + + [ObservableProperty] + private ExportLayout selectedExportLayout = ExportLayout.DaySummary; + public ObservableCollection AppearanceColors { get; } = new(); public ObservableCollection StatusTexts { get; } = new(); public ObservableCollection Activities { get; } = new(); @@ -57,8 +66,33 @@ public partial class OptionsViewModel : ObservableObject public bool IsAppearanceTabSelected => SelectedTab == OptionsTab.Appearance; public bool IsNotificationsTabSelected => SelectedTab == OptionsTab.Notifications; public bool IsDataManagementTabSelected => SelectedTab == OptionsTab.DataManagement; + public bool IsExportTabSelected => SelectedTab == OptionsTab.Export; public string NotificationVibrationButtonText => NotificationVibrationEnabled ? "Aktiv" : "Inaktiv"; + public bool IsDayViewExportLayoutSelected => SelectedExportLayout == ExportLayout.DayView; + public bool IsWeekBlockExportLayoutSelected => SelectedExportLayout == ExportLayout.WeekBlock; + public bool IsDaySummaryExportLayoutSelected => SelectedExportLayout == ExportLayout.DaySummary; + + public string ExportRangeSummary + { + get + { + var start = ExportStartDate.Date; + var end = ExportEndDate.Date; + 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}"; + } + } + + 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: Der Zeitraum wird in Wochen gruppiert. Pro Tag siehst du Vormittag, Nachmittag und die wichtigsten Details.", + _ => "Tageszusammenfassung: Jeder Tag erscheint kompakt in einer Zeile, ähnlich wie bei Monats- und Jahresexporten." + }; public IAsyncRelayCommand DeleteAllDataCommand { get; } public IAsyncRelayCommand SaveAppearanceCommand { get; } @@ -76,10 +110,15 @@ public partial class OptionsViewModel : ObservableObject public IAsyncRelayCommand DeleteScheduleCommand { get; } public IAsyncRelayCommand SaveDatabaseLocationCommand { get; } public IAsyncRelayCommand ClearExportsCommand { get; } + public IAsyncRelayCommand ExportSelectedRangeCommand { get; } public IRelayCommand ToggleNotificationVibrationCommand { get; } public IRelayCommand ShowAppearanceTabCommand { get; } public IRelayCommand ShowNotificationsTabCommand { get; } public IRelayCommand ShowDataManagementTabCommand { get; } + public IRelayCommand ShowExportTabCommand { get; } + public IRelayCommand SelectDayViewExportLayoutCommand { get; } + public IRelayCommand SelectWeekBlockExportLayoutCommand { get; } + public IRelayCommand SelectDaySummaryExportLayoutCommand { get; } public OptionsViewModel( HealthEntryRepository healthEntryRepository, @@ -120,6 +159,7 @@ public partial class OptionsViewModel : ObservableObject DeleteScheduleCommand = new AsyncRelayCommand(DeleteScheduleAsync); SaveDatabaseLocationCommand = new AsyncRelayCommand(SaveDatabaseLocationAsync); ClearExportsCommand = new AsyncRelayCommand(ClearExportsAsync); + ExportSelectedRangeCommand = new AsyncRelayCommand(ExportSelectedRangeAsync); ToggleNotificationVibrationCommand = new RelayCommand(() => { @@ -129,6 +169,11 @@ public partial class OptionsViewModel : ObservableObject ShowAppearanceTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Appearance); ShowNotificationsTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Notifications); ShowDataManagementTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.DataManagement); + ShowExportTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Export); + + SelectDayViewExportLayoutCommand = new RelayCommand(() => SelectedExportLayout = ExportLayout.DayView); + SelectWeekBlockExportLayoutCommand = new RelayCommand(() => SelectedExportLayout = ExportLayout.WeekBlock); + SelectDaySummaryExportLayoutCommand = new RelayCommand(() => SelectedExportLayout = ExportLayout.DaySummary); } partial void OnDeleteConfirmationTextChanged(string value) @@ -141,6 +186,7 @@ public partial class OptionsViewModel : ObservableObject OnPropertyChanged(nameof(IsAppearanceTabSelected)); OnPropertyChanged(nameof(IsNotificationsTabSelected)); OnPropertyChanged(nameof(IsDataManagementTabSelected)); + OnPropertyChanged(nameof(IsExportTabSelected)); } partial void OnNotificationVibrationEnabledChanged(bool value) @@ -148,6 +194,30 @@ public partial class OptionsViewModel : ObservableObject OnPropertyChanged(nameof(NotificationVibrationButtonText)); } + partial void OnExportStartDateChanged(DateTime value) + { + if (ExportEndDate.Date < value.Date) + ExportEndDate = value.Date; + + OnPropertyChanged(nameof(ExportRangeSummary)); + } + + partial void OnExportEndDateChanged(DateTime value) + { + if (ExportStartDate.Date > value.Date) + ExportStartDate = value.Date; + + OnPropertyChanged(nameof(ExportRangeSummary)); + } + + partial void OnSelectedExportLayoutChanged(ExportLayout value) + { + OnPropertyChanged(nameof(IsDayViewExportLayoutSelected)); + OnPropertyChanged(nameof(IsWeekBlockExportLayoutSelected)); + OnPropertyChanged(nameof(IsDaySummaryExportLayoutSelected)); + OnPropertyChanged(nameof(SelectedExportLayoutDescription)); + } + public async Task LoadAsync() { await LoadAppearanceAsync(); @@ -509,6 +579,24 @@ public partial class OptionsViewModel : ObservableObject return Task.CompletedTask; } + private async Task ExportSelectedRangeAsync() + { + try + { + var result = await _pdfExportService.ExportRangeAsync( + ExportStartDate.Date, + ExportEndDate.Date, + SelectedExportLayout); + + StatusText = $"Export erstellt: {result.FileName}"; + await ExportUiHelper.ShowExportSavedActionsAsync(result); + } + catch (Exception ex) + { + StatusText = ex.Message; + } + } + private async Task ClearExportsAsync() { var confirm = await Shell.Current.DisplayAlertAsync( @@ -544,6 +632,7 @@ public partial class OptionsViewModel : ObservableObject { Appearance, Notifications, - DataManagement + DataManagement, + Export } -} \ No newline at end of file +} diff --git a/Views/MonthPage.xaml b/Views/MonthPage.xaml index ec1243f..fc41c37 100644 --- a/Views/MonthPage.xaml +++ b/Views/MonthPage.xaml @@ -3,6 +3,7 @@ x:Name="RootPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:views="clr-namespace:cfs_tracker.Views" xmlns:viewModels="clr-namespace:cfs_tracker.ViewModels" x:DataType="viewModels:MonthViewModel" Title="Monat" @@ -76,7 +77,7 @@ Padding="6" MinimumHeightRequest="58"> - @@ -94,4 +95,4 @@ - \ No newline at end of file + diff --git a/Views/MonthPage.xaml.cs b/Views/MonthPage.xaml.cs index 7dc6f27..1dcdd57 100644 --- a/Views/MonthPage.xaml.cs +++ b/Views/MonthPage.xaml.cs @@ -5,6 +5,7 @@ namespace cfs_tracker.Views; public partial class MonthPage : ContentPage { private readonly MonthViewModel _viewModel; + public MonthViewModel ViewModel => _viewModel; public MonthPage(MonthViewModel viewModel) { diff --git a/Views/OptionsPage.xaml b/Views/OptionsPage.xaml index d06fee2..9371657 100644 --- a/Views/OptionsPage.xaml +++ b/Views/OptionsPage.xaml @@ -3,6 +3,7 @@ x:Name="RootPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:views="clr-namespace:cfs_tracker.Views" xmlns:viewModels="clr-namespace:cfs_tracker.ViewModels" x:DataType="viewModels:OptionsViewModel" Title="Optionen" @@ -91,6 +92,21 @@ + + @@ -332,7 +348,7 @@ + + + + + + +