Anniversary categories (wedding, jubilee, own) and month grouping
- Birthday becomes "anniversary" with a category: birthday, wedding
anniversary (with Silver/Gold/... names), jubilee, memorial day
- Own categories: Settings > Categories (icon, color, text with {0}/{o})
- Sidebar "Categories" lists anniversaries across folders with counts
- Group by month (any view), groups fold with a click
- Folders named Hochzeit/Wedding migrate yearly tasks once
- Old files keep working (JSON "IsBirthday" maps to IsAnniversary)
- 74 tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using ReminderOrganizer.Core;
|
||||
using ReminderOrganizer.Models;
|
||||
@@ -69,7 +71,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInPast => !IsBirthday && !IsRecurring && ReminderDate <= DateTime.Now;
|
||||
public bool IsInPast => !IsAnniversary && !IsRecurring && ReminderDate <= DateTime.Now;
|
||||
|
||||
// lead reminder: index into LeadOptions
|
||||
public static readonly int[] LeadOptions = { 0, 1, 2, 3, 7 };
|
||||
@@ -211,8 +213,10 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public string WindowTitle => _localizationService.GetString(
|
||||
IsBirthday ? (_isNewTask ? "NewBirthday" : "EditBirthday") : (_isNewTask ? "NewTask" : "EditTask"));
|
||||
/// <summary>"New birthday", "Edit wedding anniversary", "New task" …</summary>
|
||||
public string WindowTitle => IsAnniversary && SelectedCategory != null
|
||||
? string.Format(_localizationService.GetString(_isNewTask ? "NewAnniversaryOf" : "EditAnniversaryOf"), SelectedCategory.Name)
|
||||
: _localizationService.GetString(_isNewTask ? "NewTask" : "EditTask");
|
||||
|
||||
public string NameLabel => _localizationService.GetString("Name");
|
||||
public string DescriptionLabel => _localizationService.GetString("Description");
|
||||
@@ -238,7 +242,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
// ---------- birthday mode ----------
|
||||
|
||||
private bool _isBirthday;
|
||||
public bool IsBirthday
|
||||
public bool IsAnniversary
|
||||
{
|
||||
get => _isBirthday;
|
||||
set
|
||||
@@ -251,7 +255,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
if (value && _isNewTask && SelectedLeadIndex == 0) SelectedLeadIndex = 1; // birthdays: 1 day before by default
|
||||
}
|
||||
}
|
||||
public bool IsAppointment { get => !IsBirthday; set => IsBirthday = !value; }
|
||||
public bool IsAppointment { get => !IsAnniversary; set => IsAnniversary = !value; }
|
||||
|
||||
private string _birthdayText = "";
|
||||
public string BirthdayText
|
||||
@@ -285,7 +289,9 @@ namespace ReminderOrganizer.ViewModels
|
||||
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);
|
||||
if (year is int y && next.Year > y)
|
||||
text += " · " + (SelectedCategory?.FormatYears(next.Year - y, culture, _localizationService.GetString)
|
||||
?? string.Format(_localizationService.GetString("TurnsAge"), next.Year - y));
|
||||
var rel = ReminderTask.RelativeFormatter?.Invoke(next, DateTime.Now);
|
||||
if (!string.IsNullOrEmpty(rel)) text += " · " + rel;
|
||||
return text;
|
||||
@@ -293,23 +299,44 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
|
||||
public string AppointmentText => _localizationService.GetString("TypeAppointment");
|
||||
public string BirthdayTypeText => _localizationService.GetString("TypeBirthday");
|
||||
public string BirthdayLabel => _localizationService.GetString("BirthdayDate");
|
||||
public string BirthdayTypeText => _localizationService.GetString("TypeAnniversary");
|
||||
public string BirthdayLabel => _localizationService.GetString("AnniversaryDate");
|
||||
public string CategoryLabel => _localizationService.GetString("Category");
|
||||
public string NoteLabel => _localizationService.GetString("Note");
|
||||
|
||||
public TaskViewModel(ILocalizationService localizationService, ReminderTask? existingTask = null, bool defaultBirthday = false)
|
||||
// ---------- category ----------
|
||||
|
||||
public IReadOnlyList<Category> Categories { get; }
|
||||
|
||||
private Category? _selectedCategory;
|
||||
public Category? SelectedCategory
|
||||
{
|
||||
get => _selectedCategory;
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _selectedCategory, value)) return;
|
||||
OnPropertyChanged(nameof(BirthdayPreview));
|
||||
OnPropertyChanged(nameof(WindowTitle));
|
||||
}
|
||||
}
|
||||
|
||||
public TaskViewModel(ILocalizationService localizationService, ReminderTask? existingTask = null,
|
||||
string? defaultCategory = null, IEnumerable<Category>? categories = null)
|
||||
{
|
||||
_localizationService = localizationService;
|
||||
_isNewTask = existingTask == null;
|
||||
Categories = (categories ?? Category.Defaults(localizationService.GetString)).ToList();
|
||||
var wantedCategory = existingTask?.IsAnniversary == true ? existingTask.CategoryId ?? Category.BirthdayId : defaultCategory;
|
||||
_selectedCategory = Categories.FirstOrDefault(c => c.Id == wantedCategory) ?? Categories.FirstOrDefault();
|
||||
|
||||
if (_isNewTask)
|
||||
{
|
||||
_originalTask = new ReminderTask();
|
||||
_reminderDate = DateTime.Now.AddHours(1);
|
||||
_isBirthday = defaultBirthday;
|
||||
if (defaultBirthday) _selectedLeadIndex = 1;
|
||||
_isBirthday = defaultCategory != null;
|
||||
if (_isBirthday) _selectedLeadIndex = 1;
|
||||
}
|
||||
else if (existingTask!.IsBirthday)
|
||||
else if (existingTask!.IsAnniversary)
|
||||
{
|
||||
_originalTask = existingTask;
|
||||
_isBirthday = true;
|
||||
@@ -348,7 +375,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
|
||||
private bool CanSave() => !string.IsNullOrWhiteSpace(Name) &&
|
||||
(IsBirthday ? TryBirthday(out _, out _) : !BirthYearError);
|
||||
(IsAnniversary ? TryBirthday(out _, out _) : !BirthYearError);
|
||||
|
||||
private void ValidateInput()
|
||||
{
|
||||
@@ -388,7 +415,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
{
|
||||
if (!CanSave()) return;
|
||||
|
||||
if (IsBirthday && TryBirthday(out var nextBirthday, out var birthYear))
|
||||
if (IsAnniversary && 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.
|
||||
@@ -396,7 +423,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
nextBirthday = nextBirthday.AddYears(1);
|
||||
if (_isNewTask || _originalTask.ReminderDate != nextBirthday || _originalTask.LeadDays != lead)
|
||||
_originalTask.IsPreNotified = false;
|
||||
_originalTask.IsBirthday = true;
|
||||
_originalTask.IsAnniversary = true;
|
||||
_originalTask.CategoryId = SelectedCategory?.Id ?? Category.BirthdayId;
|
||||
_originalTask.Name = Name.Trim();
|
||||
_originalTask.Description = Description?.Trim() ?? "";
|
||||
_originalTask.IsRecurring = true;
|
||||
@@ -408,7 +436,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
RequestClose?.Invoke(this, true);
|
||||
return;
|
||||
}
|
||||
_originalTask.IsBirthday = false;
|
||||
_originalTask.IsAnniversary = false;
|
||||
|
||||
var leadDays = LeadOptions[SelectedLeadIndex];
|
||||
bool timingChanged = _originalTask.ReminderDate != ReminderDate || _originalTask.LeadDays != leadDays;
|
||||
|
||||
Reference in New Issue
Block a user