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:
113
Models/Category.cs
Normal file
113
Models/Category.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user