Birthday entry type, relative dates, list/compact/cards views
- Task dialog: Appointment | Birthday switch. Birthday = name + "19.03." or "19.03.1986" (no time), live preview with weekday, age and days left - Birthday folders open the birthday form; yearly tasks in such folders are migrated once - Birthdays show "19. Maerz" instead of date + time; every task shows "in 15 days" / "3 days ago" (red when overdue) - View switch: list, compact (one line), cards (calendar tiles), persisted - ICS: birthdays as all-day events - 59 tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -194,6 +194,40 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- view mode ----------
|
||||
|
||||
public string ViewMode
|
||||
{
|
||||
get => _appData.ViewMode;
|
||||
set
|
||||
{
|
||||
if (_appData.ViewMode == value) return;
|
||||
_appData.ViewMode = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(IsViewList));
|
||||
OnPropertyChanged(nameof(IsViewCompact));
|
||||
OnPropertyChanged(nameof(IsViewCards));
|
||||
_ = SaveAsync();
|
||||
}
|
||||
}
|
||||
public bool IsViewList { get => ViewMode == "list"; set { if (value) ViewMode = "list"; } }
|
||||
public bool IsViewCompact { get => ViewMode == "compact"; set { if (value) ViewMode = "compact"; } }
|
||||
public bool IsViewCards { get => ViewMode == "cards"; set { if (value) ViewMode = "cards"; } }
|
||||
|
||||
/// <summary>"today", "tomorrow", "in 5 days", "yesterday", "3 days ago".</summary>
|
||||
public string RelativeText(DateTime date, DateTime now)
|
||||
{
|
||||
int days = (date.Date - now.Date).Days;
|
||||
return days switch
|
||||
{
|
||||
0 => L("RelToday"),
|
||||
1 => L("RelTomorrow"),
|
||||
-1 => L("RelYesterday"),
|
||||
> 1 => string.Format(L("RelInDays"), days),
|
||||
_ => string.Format(L("RelDaysAgo"), -days)
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- undo ----------
|
||||
|
||||
private Action? _undoAction;
|
||||
@@ -271,6 +305,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
_autostartService = autostartService;
|
||||
|
||||
ReminderTask.AgeFormatter = age => string.Format(L("TurnsAge"), age);
|
||||
ReminderTask.DisplayCulture = () => new System.Globalization.CultureInfo(_localizationService.CurrentLanguage == "de" ? "de-DE" : "en-US");
|
||||
ReminderTask.RelativeFormatter = RelativeText;
|
||||
|
||||
// Empty name = refresh every binding (all texts depend on the language).
|
||||
_localizationService.StringsChanged += (s, e) =>
|
||||
@@ -326,6 +362,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
if (firstRun)
|
||||
await SaveAsync();
|
||||
|
||||
if (_appData.MigrateBirthdays() > 0) await SaveAsync();
|
||||
_isDarkMode = _appData.IsDarkMode.Value;
|
||||
_appData.Folders.CollectionChanged += (s, e) => { HookFolders(); ReindexTasks(); };
|
||||
HookFolders();
|
||||
@@ -513,7 +550,10 @@ namespace ReminderOrganizer.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
var taskWindow = new TaskWindow(null, IsDarkMode) { Owner = Application.Current.MainWindow };
|
||||
// Birthday folders (by name or because they mostly hold birthdays) open the birthday form.
|
||||
bool birthday = AppData.LooksLikeBirthdayFolder(folder.Name) ||
|
||||
(folder.Tasks.Count > 0 && folder.Tasks.Count(t => t.IsBirthday) * 2 > folder.Tasks.Count);
|
||||
var taskWindow = new TaskWindow(null, IsDarkMode, birthday) { Owner = Application.Current.MainWindow };
|
||||
if (taskWindow.ShowDialog() == true)
|
||||
{
|
||||
folder.Tasks.Add(taskWindow.TaskResult);
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInPast => !IsRecurring && ReminderDate <= DateTime.Now;
|
||||
public bool IsInPast => !IsBirthday && !IsRecurring && ReminderDate <= DateTime.Now;
|
||||
|
||||
// lead reminder: index into LeadOptions
|
||||
public static readonly int[] LeadOptions = { 0, 1, 2, 3, 7 };
|
||||
@@ -211,9 +211,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public string WindowTitle => _isNewTask
|
||||
? _localizationService.GetString("NewTask")
|
||||
: _localizationService.GetString("EditTask");
|
||||
public string WindowTitle => _localizationService.GetString(
|
||||
IsBirthday ? (_isNewTask ? "NewBirthday" : "EditBirthday") : (_isNewTask ? "NewTask" : "EditTask"));
|
||||
|
||||
public string NameLabel => _localizationService.GetString("Name");
|
||||
public string DescriptionLabel => _localizationService.GetString("Description");
|
||||
@@ -236,15 +235,92 @@ namespace ReminderOrganizer.ViewModels
|
||||
|
||||
public event EventHandler<bool>? RequestClose;
|
||||
|
||||
public TaskViewModel(ILocalizationService localizationService, ReminderTask? existingTask = null)
|
||||
// ---------- birthday mode ----------
|
||||
|
||||
private bool _isBirthday;
|
||||
public bool IsBirthday
|
||||
{
|
||||
get => _isBirthday;
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _isBirthday, value)) return;
|
||||
OnPropertyChanged(nameof(IsAppointment));
|
||||
OnPropertyChanged(nameof(WindowTitle));
|
||||
OnPropertyChanged(nameof(IsInPast));
|
||||
OnPropertyChanged(nameof(BirthdayPreview));
|
||||
if (value && _isNewTask && SelectedLeadIndex == 0) SelectedLeadIndex = 1; // birthdays: 1 day before by default
|
||||
}
|
||||
}
|
||||
public bool IsAppointment { get => !IsBirthday; set => IsBirthday = !value; }
|
||||
|
||||
private string _birthdayText = "";
|
||||
public string BirthdayText
|
||||
{
|
||||
get => _birthdayText;
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _birthdayText, value ?? "")) return;
|
||||
OnPropertyChanged(nameof(BirthdayPreview));
|
||||
OnPropertyChanged(nameof(BirthdayInvalid));
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryBirthday(out DateTime next, out int? year)
|
||||
{
|
||||
next = default;
|
||||
if (!BirthdayInput.TryParse(BirthdayText, DateTime.Today, out var d, out var m, out year)) return false;
|
||||
next = ReminderTask.NextBirthday(d, m, DateTime.Today);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Red only once the input could be complete ("1.1" = 3 chars) – no error after the first digit.</summary>
|
||||
public bool BirthdayInvalid => BirthdayText.Trim().Length >= 3 && !TryBirthday(out _, out _);
|
||||
|
||||
/// <summary>"Next: Thu, 19 March 2027 · turns 41 · in 110 days"</summary>
|
||||
public string BirthdayPreview
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!TryBirthday(out var next, out var year))
|
||||
return _localizationService.GetString(BirthdayInvalid ? "BirthdayInvalid" : "BirthdayHint");
|
||||
var culture = ReminderTask.DisplayCulture?.Invoke() ?? System.Globalization.CultureInfo.CurrentCulture;
|
||||
var text = next.ToString("ddd, " + ReminderTask.DayMonthPattern(culture) + " yyyy", culture);
|
||||
if (year is int y) text += " · " + string.Format(_localizationService.GetString("TurnsAge"), next.Year - y);
|
||||
var rel = ReminderTask.RelativeFormatter?.Invoke(next, DateTime.Now);
|
||||
if (!string.IsNullOrEmpty(rel)) text += " · " + rel;
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public string AppointmentText => _localizationService.GetString("TypeAppointment");
|
||||
public string BirthdayTypeText => _localizationService.GetString("TypeBirthday");
|
||||
public string BirthdayLabel => _localizationService.GetString("BirthdayDate");
|
||||
public string NoteLabel => _localizationService.GetString("Note");
|
||||
|
||||
public TaskViewModel(ILocalizationService localizationService, ReminderTask? existingTask = null, bool defaultBirthday = false)
|
||||
{
|
||||
_localizationService = localizationService;
|
||||
_isNewTask = existingTask == null;
|
||||
|
||||
|
||||
if (_isNewTask)
|
||||
{
|
||||
_originalTask = new ReminderTask();
|
||||
_reminderDate = DateTime.Now.AddHours(1);
|
||||
_isBirthday = defaultBirthday;
|
||||
if (defaultBirthday) _selectedLeadIndex = 1;
|
||||
}
|
||||
else if (existingTask!.IsBirthday)
|
||||
{
|
||||
_originalTask = existingTask;
|
||||
_isBirthday = true;
|
||||
_name = existingTask.Name;
|
||||
_description = existingTask.Description;
|
||||
_reminderDate = existingTask.ReminderDate;
|
||||
_isRecurring = true;
|
||||
_selectedRecurrenceIndex = (int)RecurrenceType.Yearly;
|
||||
_selectedLeadIndex = Math.Max(0, Array.IndexOf(LeadOptions, existingTask.LeadDays));
|
||||
_birthdayText = existingTask.ReminderDate.ToString("dd.MM.", System.Globalization.CultureInfo.InvariantCulture)
|
||||
+ (existingTask.BirthYear?.ToString() ?? "");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -271,7 +347,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
OnPropertyChanged(nameof(SelectedMinuteIndex));
|
||||
}
|
||||
|
||||
private bool CanSave() => !string.IsNullOrWhiteSpace(Name) && !BirthYearError;
|
||||
private bool CanSave() => !string.IsNullOrWhiteSpace(Name) &&
|
||||
(IsBirthday ? TryBirthday(out _, out _) : !BirthYearError);
|
||||
|
||||
private void ValidateInput()
|
||||
{
|
||||
@@ -311,6 +388,28 @@ namespace ReminderOrganizer.ViewModels
|
||||
{
|
||||
if (!CanSave()) return;
|
||||
|
||||
if (IsBirthday && TryBirthday(out var nextBirthday, out var birthYear))
|
||||
{
|
||||
var lead = LeadOptions[SelectedLeadIndex];
|
||||
// Editing on the birthday itself after it was already reminded: keep next year's date.
|
||||
if (!_isNewTask && nextBirthday <= DateTime.Now && _originalTask.ReminderDate > DateTime.Now)
|
||||
nextBirthday = nextBirthday.AddYears(1);
|
||||
if (_isNewTask || _originalTask.ReminderDate != nextBirthday || _originalTask.LeadDays != lead)
|
||||
_originalTask.IsPreNotified = false;
|
||||
_originalTask.IsBirthday = true;
|
||||
_originalTask.Name = Name.Trim();
|
||||
_originalTask.Description = Description?.Trim() ?? "";
|
||||
_originalTask.IsRecurring = true;
|
||||
_originalTask.RecurrenceType = RecurrenceType.Yearly;
|
||||
_originalTask.BirthYear = birthYear;
|
||||
_originalTask.LeadDays = lead;
|
||||
_originalTask.ReminderDate = nextBirthday;
|
||||
_originalTask.IsNotified = false;
|
||||
RequestClose?.Invoke(this, true);
|
||||
return;
|
||||
}
|
||||
_originalTask.IsBirthday = false;
|
||||
|
||||
var leadDays = LeadOptions[SelectedLeadIndex];
|
||||
bool timingChanged = _originalTask.ReminderDate != ReminderDate || _originalTask.LeadDays != leadDays;
|
||||
_originalTask.LeadDays = leadDays;
|
||||
|
||||
Reference in New Issue
Block a user