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

113
Models/Category.cs Normal file
View File

@@ -0,0 +1,113 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Globalization;
using ReminderOrganizer.Core;
namespace ReminderOrganizer.Models
{
/// <summary>Sidebar entry for a category (count = open anniversaries).</summary>
public record CategoryNavItem(string Id, string Name, string Glyph, string Color, int Count, bool IsActive);
/// <summary>
/// Kind of anniversary (birthday, wedding, jubilee …). Text uses {0} = years, {o} = ordinal ("10." / "10th").
/// </summary>
public class Category : ViewModelBase
{
public const string BirthdayId = "birthday";
public const string WeddingId = "wedding";
public const string JubileeId = "jubilee";
public const string MemorialId = "memorial";
/// <summary>Segoe MDL2 glyphs offered in the editor (theme-colored, no emojis).</summary>
public static readonly string[] Glyphs =
{
"", // balloon
"", // heart
"", // star
"", // people
"", // message
"", // home
"", // flag
"", // history
"", // calendar
"", // music
"", // pet (dog/paw-like)
"", // light bulb
};
private string _id = Guid.NewGuid().ToString("N");
private string _name = "";
private string _glyph = Glyphs[0];
private string _color = Folder.DefaultColor;
private string _format = "{0}";
private bool _isWedding;
public string Id { get => _id; set => SetProperty(ref _id, value); }
public string Name { get => _name; set => SetProperty(ref _name, value); }
public string Glyph { get => _glyph; set => SetProperty(ref _glyph, value); }
public string Color { get => _color; set => SetProperty(ref _color, value); }
/// <summary>e.g. "turns {0}", "{o} anniversary", "{0} years ago".</summary>
public string Format { get => _format; set => SetProperty(ref _format, value); }
/// <summary>Adds the traditional wedding name (Silver, Gold …).</summary>
public bool IsWedding { get => _isWedding; set => SetProperty(ref _isWedding, value); }
public bool IsPreset => Id is BirthdayId or WeddingId or JubileeId or MemorialId;
public Category Clone() => new()
{
Id = Id, Name = Name, Glyph = Glyph, Color = Color, Format = Format, IsWedding = IsWedding
};
/// <summary>Default categories in the given language.</summary>
public static List<Category> Defaults(Func<string, string> L) => new()
{
new() { Id = BirthdayId, Name = L("CatBirthday"), Glyph = "", Color = "#EC4899", Format = L("CatBirthdayFormat") },
new() { Id = WeddingId, Name = L("CatWedding"), Glyph = "", Color = "#F59E0B", Format = L("CatWeddingFormat"), IsWedding = true },
new() { Id = JubileeId, Name = L("CatJubilee"), Glyph = "", Color = "#3B82F6", Format = L("CatJubileeFormat") },
new() { Id = MemorialId, Name = L("CatMemorial"), Glyph = "", Color = "#64748B", Format = L("CatMemorialFormat") },
};
/// <summary>
/// Presets that still carry a default text of some language get the texts of the new language
/// (user-edited names/formats stay untouched).
/// </summary>
public static void RelocalizePresets(IEnumerable<Category> categories, Func<string, string> L,
IEnumerable<IReadOnlyDictionary<string, string>> allLanguages)
{
var langs = new List<IReadOnlyDictionary<string, string>>(allLanguages);
foreach (var c in categories)
{
if (!c.IsPreset) continue;
var key = c.Id switch { BirthdayId => "CatBirthday", WeddingId => "CatWedding", JubileeId => "CatJubilee", _ => "CatMemorial" };
if (langs.Exists(d => d.TryGetValue(key, out var n) && n == c.Name)) c.Name = L(key);
if (langs.Exists(d => d.TryGetValue(key + "Format", out var f) && f == c.Format)) c.Format = L(key + "Format");
}
}
/// <summary>Years for which a wedding anniversary has a traditional name (key "Wedding{n}").</summary>
public static readonly int[] WeddingYears = { 1, 5, 10, 15, 20, 25, 30, 40, 50, 60, 65, 70 };
/// <summary>"10th" (en) / "10." (de).</summary>
public static string Ordinal(int n, CultureInfo culture)
{
if (culture.TwoLetterISOLanguageName != "en") return n + ".";
var suffix = (n % 100) is 11 or 12 or 13 ? "th" : (n % 10) switch { 1 => "st", 2 => "nd", 3 => "rd", _ => "th" };
return n + suffix;
}
/// <summary>Applies the format; for weddings appends the traditional name if known.</summary>
public string FormatYears(int years, CultureInfo culture, Func<string, string> L)
{
var text = (Format ?? "{0}")
.Replace("{o}", Ordinal(years, culture))
.Replace("{0}", years.ToString(culture));
if (IsWedding && Array.IndexOf(WeddingYears, years) >= 0)
{
var name = L("Wedding" + years);
if (!string.IsNullOrEmpty(name) && name != "Wedding" + years) text += " · " + name;
}
return text;
}
}
}

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++;
}
}