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:
2026-11-29 15:06:19 +01:00
parent bb6612420d
commit 00e9990feb
22 changed files with 1086 additions and 104 deletions

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using ReminderOrganizer.Core;
namespace ReminderOrganizer.Models
@@ -88,18 +89,48 @@ namespace ReminderOrganizer.Models
BirthYear is int y && IsRecurring && RecurrenceType == RecurrenceType.Yearly && ReminderDate.Year > y
? ReminderDate.Year - y : null;
/// <summary>Set once by the app (localized "turns {0}").</summary>
public static Func<int, string>? AgeFormatter { get; set; }
/// <summary>Set once by the app: (task, years) → "turns 40" / "10th anniversary · Tin" …</summary>
public static Func<ReminderTask, int, string>? AgeFormatter { get; set; }
[System.Text.Json.Serialization.JsonIgnore]
public string? AgeText => UpcomingAge is int a ? (AgeFormatter?.Invoke(a) ?? a.ToString()) : null;
public string? AgeText => UpcomingAge is int a ? (AgeFormatter?.Invoke(this, a) ?? a.ToString()) : null;
private bool _isBirthday;
/// <summary>Birthday: yearly, date only (no time shown), reminded at <see cref="BirthdayHour"/>.</summary>
public bool IsBirthday
private bool _isAnniversary;
/// <summary>Anniversary (birthday, wedding …): yearly, date only, reminded at <see cref="BirthdayHour"/>.
/// Stored as "IsBirthday" for compatibility with older files.</summary>
[System.Text.Json.Serialization.JsonPropertyName("IsBirthday")]
public bool IsAnniversary
{
get => _isBirthday;
set { if (SetProperty(ref _isBirthday, value)) RaiseDisplay(); }
get => _isAnniversary;
set { if (SetProperty(ref _isAnniversary, value)) RaiseDisplay(); }
}
private string? _categoryId;
/// <summary>Anniversary category (see <see cref="Category"/>); null = birthday.</summary>
public string? CategoryId
{
get => _categoryId;
set { if (SetProperty(ref _categoryId, value)) RaiseDisplay(); }
}
/// <summary>Set once by the app: id → category.</summary>
public static Func<string?, Category?>? CategoryLookup { get; set; }
[System.Text.Json.Serialization.JsonIgnore]
public Category? Category => IsAnniversary ? CategoryLookup?.Invoke(CategoryId ?? Category.BirthdayId) : null;
/// <summary>Accent color: category for anniversaries, otherwise folder.</summary>
[System.Text.Json.Serialization.JsonIgnore]
public string AccentColor => Category?.Color ?? FolderColor;
[System.Text.Json.Serialization.JsonIgnore]
public string? CategoryGlyph => Category?.Glyph;
/// <summary>Call after categories were edited.</summary>
public void RefreshCategory()
{
OnPropertyChanged(nameof(Category));
RaiseDisplay();
}
public const int BirthdayHour = 9;
@@ -110,7 +141,7 @@ namespace ReminderOrganizer.Models
/// <summary>"19. März" for birthdays, otherwise "19.03.2027 09:00".</summary>
[System.Text.Json.Serialization.JsonIgnore]
public string DisplayDate => IsBirthday
public string DisplayDate => IsAnniversary
? ReminderDate.ToString(DayMonthPattern(DisplayCulture?.Invoke() ?? CultureInfo.CurrentCulture), DisplayCulture?.Invoke() ?? CultureInfo.CurrentCulture)
: ReminderDate.ToString("dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
@@ -137,6 +168,8 @@ namespace ReminderOrganizer.Models
OnPropertyChanged(nameof(DayText));
OnPropertyChanged(nameof(MonthText));
OnPropertyChanged(nameof(AgeText));
OnPropertyChanged(nameof(AccentColor));
OnPropertyChanged(nameof(CategoryGlyph));
}
/// <summary>Next birthday on/after <paramref name="today"/> at BirthdayHour (29 Feb → 28 Feb in other years).</summary>
@@ -154,7 +187,7 @@ namespace ReminderOrganizer.Models
private string _folderColor = Folder.DefaultColor;
[System.Text.Json.Serialization.JsonIgnore]
public string FolderColor { get => _folderColor; set => SetProperty(ref _folderColor, value); }
public string FolderColor { get => _folderColor; set { if (SetProperty(ref _folderColor, value)) OnPropertyChanged(nameof(AccentColor)); } }
public DateTime GetNextOccurrence() => GetNextOccurrence(DateTime.Now);
@@ -298,6 +331,24 @@ namespace ReminderOrganizer.Models
public bool HideDone { get; set; }
/// <summary>"list", "compact" or "cards".</summary>
public string ViewMode { get; set; } = "list";
/// <summary>Group the list by month (collapsible).</summary>
public bool GroupByMonth { get; set; }
/// <summary>Anniversary categories (birthday, wedding, … and own ones). Filled with defaults on first start.</summary>
public ObservableCollection<Category> Categories { get; set; } = new();
/// <summary>Adds missing default categories (keeps user edits of existing ones).</summary>
public bool EnsureDefaultCategories(Func<string, string> L)
{
bool changed = false;
int insertAt = 0;
foreach (var def in Category.Defaults(L))
{
if (Categories.Any(c => c.Id == def.Id)) { insertAt++; continue; }
Categories.Insert(Math.Min(insertAt++, Categories.Count), def);
changed = true;
}
return changed;
}
/// <summary>Folders and yearly tasks were checked for birthdays once.</summary>
public bool BirthdaysMigrated { get; set; }
@@ -308,16 +359,43 @@ namespace ReminderOrganizer.Models
/// <summary>Yearly tasks in a "Geburtstage"/"Birthdays" folder become birthday entries (one-time).</summary>
public int MigrateBirthdays()
{
if (BirthdaysMigrated) return 0;
BirthdaysMigrated = true;
int n = 0;
if (!BirthdaysMigrated)
{
BirthdaysMigrated = true;
n += MarkYearly(LooksLikeBirthdayFolder, Category.BirthdayId);
}
if (!WeddingsMigrated)
{
WeddingsMigrated = true;
n += MarkYearly(LooksLikeWeddingFolder, Category.WeddingId);
}
return n;
}
public bool WeddingsMigrated { get; set; }
public static bool LooksLikeWeddingFolder(string? name) =>
name != null && (name.Contains("hochzeit", StringComparison.OrdinalIgnoreCase) ||
name.Contains("wedding", StringComparison.OrdinalIgnoreCase) ||
name.Contains("jahrestag", StringComparison.OrdinalIgnoreCase) ||
name.Contains("anniversar", StringComparison.OrdinalIgnoreCase));
/// <summary>Category a new anniversary in this folder should get (null = no hint).</summary>
public static string? CategoryHintForFolder(string? name) =>
LooksLikeBirthdayFolder(name) ? Category.BirthdayId : LooksLikeWeddingFolder(name) ? Category.WeddingId : null;
private int MarkYearly(Func<string?, bool> folderMatches, string categoryId)
{
int n = 0;
foreach (var f in Folders)
{
if (!LooksLikeBirthdayFolder(f.Name)) continue;
if (!folderMatches(f.Name)) continue;
foreach (var t in f.Tasks)
{
if (t.IsBirthday || !t.IsRecurring || t.RecurrenceType != RecurrenceType.Yearly) continue;
t.IsBirthday = true;
if (t.IsAnniversary || !t.IsRecurring || t.RecurrenceType != RecurrenceType.Yearly) continue;
t.IsAnniversary = true;
t.CategoryId = categoryId;
n++;
}
}