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:
@@ -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