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:
@@ -65,9 +65,12 @@ namespace ReminderOrganizer.ViewModels
|
||||
bool changed = !ReferenceEquals(_selectedFolder, folder) || _isUpcomingMode;
|
||||
_selectedFolder = folder;
|
||||
_isUpcomingMode = false;
|
||||
_categoryFilter = null;
|
||||
if (!changed) return;
|
||||
OnPropertyChanged(nameof(SelectedFolder));
|
||||
OnPropertyChanged(nameof(IsUpcomingMode));
|
||||
OnPropertyChanged(nameof(CategoryFilter));
|
||||
OnPropertyChanged(nameof(IsAllUpcoming));
|
||||
RebuildView();
|
||||
}
|
||||
|
||||
@@ -79,6 +82,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
if (_isUpcomingMode == value) return;
|
||||
_isUpcomingMode = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(IsAllUpcoming));
|
||||
RebuildView();
|
||||
}
|
||||
}
|
||||
@@ -92,8 +96,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
public bool HasVisibleTasks => VisibleCount > 0;
|
||||
public bool HasSelectedFolder => SelectedFolder != null;
|
||||
|
||||
public string HeaderTitle => IsUpcomingMode ? L("Upcoming") : SelectedFolder?.Name ?? L("Welcome");
|
||||
public string HeaderColor => IsUpcomingMode ? Folder.DefaultColor : SelectedFolder?.Color ?? Folder.DefaultColor;
|
||||
public string HeaderTitle => ActiveCategory?.Name ?? (IsUpcomingMode ? L("Upcoming") : SelectedFolder?.Name ?? L("Welcome"));
|
||||
public string HeaderColor => ActiveCategory?.Color ?? (IsUpcomingMode ? Folder.DefaultColor : SelectedFolder?.Color ?? Folder.DefaultColor);
|
||||
|
||||
public string TaskCountText
|
||||
{
|
||||
@@ -159,7 +163,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsFiltering => !string.IsNullOrWhiteSpace(SearchText) || FilterMode != TaskFilterMode.All || HideDone;
|
||||
private bool IsFiltering => !string.IsNullOrWhiteSpace(SearchText) || FilterMode != TaskFilterMode.All || HideDone || CategoryFilter != null;
|
||||
|
||||
// ---------- settings ----------
|
||||
|
||||
@@ -194,6 +198,92 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- categories ----------
|
||||
|
||||
public ObservableCollection<Category> Categories => _appData.Categories;
|
||||
|
||||
/// <summary>Sidebar entries: every category that has entries, with count; active one highlighted.</summary>
|
||||
public IReadOnlyList<CategoryNavItem> CategoryNav =>
|
||||
_appData.Categories
|
||||
.Select(c => new CategoryNavItem(c.Id, c.Name, c.Glyph, c.Color,
|
||||
_allTasks.Count(t => t.IsAnniversary && !t.IsNotified && (t.CategoryId ?? Category.BirthdayId) == c.Id),
|
||||
IsUpcomingMode && CategoryFilter == c.Id))
|
||||
.Where(n => n.Count > 0)
|
||||
.ToList();
|
||||
|
||||
public bool HasCategoryNav => CategoryNav.Count > 0;
|
||||
|
||||
private string? _categoryFilter;
|
||||
/// <summary>Category shown in the "Upcoming" view (null = all).</summary>
|
||||
public string? CategoryFilter
|
||||
{
|
||||
get => _categoryFilter;
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _categoryFilter, value)) return;
|
||||
OnPropertyChanged(nameof(HeaderTitle));
|
||||
OnPropertyChanged(nameof(HeaderColor));
|
||||
OnPropertyChanged(nameof(HeaderGlyph));
|
||||
OnPropertyChanged(nameof(IsAllUpcoming));
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
|
||||
private Category? ActiveCategory => IsUpcomingMode && CategoryFilter != null
|
||||
? _appData.Categories.FirstOrDefault(c => c.Id == CategoryFilter) : null;
|
||||
|
||||
/// <summary>"Upcoming" without a category filter (for the sidebar highlight).</summary>
|
||||
public bool IsAllUpcoming => IsUpcomingMode && CategoryFilter == null;
|
||||
|
||||
/// <summary>Icon in the header: category glyph, calendar for "Upcoming", null = folder outline.</summary>
|
||||
public string? HeaderGlyph => ActiveCategory?.Glyph ?? (IsUpcomingMode ? "" : null);
|
||||
|
||||
private void ShowCategory(string? id)
|
||||
{
|
||||
_categoryFilter = id;
|
||||
OnPropertyChanged(nameof(CategoryFilter));
|
||||
OnPropertyChanged(nameof(IsAllUpcoming));
|
||||
if (!IsUpcomingMode) IsUpcomingMode = true; // rebuilds the view
|
||||
else RebuildView();
|
||||
}
|
||||
|
||||
private void EditCategories()
|
||||
{
|
||||
var dialog = new CategoryWindow(_appData.Categories, IsDarkMode,
|
||||
id => _allTasks.Count(t => t.IsAnniversary && (t.CategoryId ?? Category.BirthdayId) == id))
|
||||
{ Owner = Application.Current.MainWindow };
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
|
||||
var result = dialog.Result;
|
||||
var removed = _appData.Categories.Where(c => result.All(r => r.Id != c.Id)).Select(c => c.Id).ToHashSet();
|
||||
_appData.Categories.Clear();
|
||||
foreach (var c in result) _appData.Categories.Add(c);
|
||||
foreach (var t in _allTasks)
|
||||
{
|
||||
if (t.CategoryId != null && removed.Contains(t.CategoryId)) t.CategoryId = null; // back to birthday
|
||||
t.RefreshCategory();
|
||||
}
|
||||
if (CategoryFilter != null && removed.Contains(CategoryFilter)) CategoryFilter = null;
|
||||
UpdateCounts();
|
||||
OnPropertyChanged(nameof(HeaderTitle));
|
||||
_ = SaveAsync();
|
||||
}
|
||||
|
||||
// ---------- month grouping ----------
|
||||
|
||||
public bool GroupByMonth
|
||||
{
|
||||
get => _appData.GroupByMonth;
|
||||
set
|
||||
{
|
||||
if (_appData.GroupByMonth == value) return;
|
||||
_appData.GroupByMonth = value;
|
||||
OnPropertyChanged();
|
||||
RebuildView();
|
||||
_ = SaveAsync();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- view mode ----------
|
||||
|
||||
public string ViewMode
|
||||
@@ -292,6 +382,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
public ICommand ShowUpcomingCommand { get; }
|
||||
public ICommand UndoCommand { get; }
|
||||
public ICommand ClearSearchCommand { get; }
|
||||
public ICommand EditCategoriesCommand { get; }
|
||||
public ICommand ShowCategoryCommand { get; }
|
||||
|
||||
public MainViewModel(
|
||||
IDataService dataService,
|
||||
@@ -304,13 +396,19 @@ namespace ReminderOrganizer.ViewModels
|
||||
_localizationService = localizationService;
|
||||
_autostartService = autostartService;
|
||||
|
||||
ReminderTask.AgeFormatter = age => string.Format(L("TurnsAge"), age);
|
||||
ReminderTask.AgeFormatter = (task, years) =>
|
||||
task.Category?.FormatYears(years, ReminderTask.DisplayCulture!(), L) ?? string.Format(L("TurnsAge"), years);
|
||||
ReminderTask.CategoryLookup = id =>
|
||||
_appData.Categories.FirstOrDefault(c => c.Id == id) ?? _appData.Categories.FirstOrDefault();
|
||||
ReminderTask.DisplayCulture = () => new System.Globalization.CultureInfo(_localizationService.CurrentLanguage == "de" ? "de-DE" : "en-US");
|
||||
ReminderTask.RelativeFormatter = RelativeText;
|
||||
|
||||
// Empty name = refresh every binding (all texts depend on the language).
|
||||
_localizationService.StringsChanged += (s, e) =>
|
||||
{
|
||||
Category.RelocalizePresets(_appData.Categories, L,
|
||||
new[] { LocalizationService.LoadStrings("en"), LocalizationService.LoadStrings("de") });
|
||||
foreach (var t in _allTasks) t.RefreshCategory();
|
||||
OnPropertyChanged(string.Empty);
|
||||
_tasksView?.Refresh(); // group headers + age texts
|
||||
};
|
||||
@@ -339,9 +437,11 @@ namespace ReminderOrganizer.ViewModels
|
||||
ExportCsvCommand = new RelayCommand(ExportCsv);
|
||||
ExportIcsCommand = new RelayCommand(ExportIcs);
|
||||
OpenDiscordCommand = new RelayCommand(OpenDiscord);
|
||||
ShowUpcomingCommand = new RelayCommand(() => IsUpcomingMode = true);
|
||||
ShowUpcomingCommand = new RelayCommand(() => ShowCategory(null));
|
||||
ShowCategoryCommand = new RelayCommand<string>(ShowCategory);
|
||||
UndoCommand = new RelayCommand(Undo);
|
||||
ClearSearchCommand = new RelayCommand(() => { SearchText = ""; FilterMode = TaskFilterMode.All; });
|
||||
ClearSearchCommand = new RelayCommand(() => { SearchText = ""; FilterMode = TaskFilterMode.All; CategoryFilter = null; });
|
||||
EditCategoriesCommand = new RelayCommand(EditCategories);
|
||||
|
||||
_reminderTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(30) };
|
||||
_reminderTimer.Tick += (s, e) => CheckReminders();
|
||||
@@ -362,7 +462,9 @@ namespace ReminderOrganizer.ViewModels
|
||||
if (firstRun)
|
||||
await SaveAsync();
|
||||
|
||||
if (_appData.MigrateBirthdays() > 0) await SaveAsync();
|
||||
bool changed = _appData.EnsureDefaultCategories(L);
|
||||
changed |= _appData.MigrateBirthdays() > 0;
|
||||
if (changed) await SaveAsync();
|
||||
_isDarkMode = _appData.IsDarkMode.Value;
|
||||
_appData.Folders.CollectionChanged += (s, e) => { HookFolders(); ReindexTasks(); };
|
||||
HookFolders();
|
||||
@@ -430,16 +532,19 @@ namespace ReminderOrganizer.ViewModels
|
||||
{
|
||||
var view = new ListCollectionView((System.Collections.IList)source)
|
||||
{
|
||||
CustomSort = new TaskQuery.Comparer(),
|
||||
Filter = o => o is ReminderTask t && TaskQuery.Matches(t, SearchText, FilterMode, HideDone, DateTime.Now)
|
||||
CustomSort = new TaskQuery.Comparer(chronological: GroupByMonth),
|
||||
Filter = o => o is ReminderTask t && TaskQuery.Matches(t, SearchText, FilterMode, HideDone, DateTime.Now, CategoryFilter)
|
||||
};
|
||||
if (IsUpcomingMode)
|
||||
if (GroupByMonth)
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription(null, new Converters.MonthKeyConverter()));
|
||||
else if (IsUpcomingMode)
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription(null, new Converters.TaskBucketConverter()));
|
||||
_tasksView = view;
|
||||
}
|
||||
OnPropertyChanged(nameof(TasksView));
|
||||
OnPropertyChanged(nameof(HeaderTitle));
|
||||
OnPropertyChanged(nameof(HeaderColor));
|
||||
OnPropertyChanged(nameof(HeaderGlyph));
|
||||
OnPropertyChanged(nameof(HasSelectedFolder));
|
||||
UpdateCounts();
|
||||
}
|
||||
@@ -461,6 +566,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
OnPropertyChanged(nameof(UpcomingCount));
|
||||
OnPropertyChanged(nameof(EmptyTitle));
|
||||
OnPropertyChanged(nameof(EmptyHint));
|
||||
OnPropertyChanged(nameof(CategoryNav));
|
||||
OnPropertyChanged(nameof(HasCategoryNav));
|
||||
}
|
||||
|
||||
// ---------- dialogs ----------
|
||||
@@ -551,9 +658,15 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
|
||||
// Birthday folders (by name or because they mostly hold birthdays) open the birthday form.
|
||||
bool birthday = AppData.LooksLikeBirthdayFolder(folder.Name) ||
|
||||
(folder.Tasks.Count > 0 && folder.Tasks.Count(t => t.IsBirthday) * 2 > folder.Tasks.Count);
|
||||
var taskWindow = new TaskWindow(null, IsDarkMode, birthday) { Owner = Application.Current.MainWindow };
|
||||
// Anniversary folders (by name or because they mostly hold anniversaries) open the anniversary form
|
||||
// with the folder's usual category preselected.
|
||||
string? category = AppData.CategoryHintForFolder(folder.Name);
|
||||
var anniversaries = folder.Tasks.Where(t => t.IsAnniversary).ToList();
|
||||
if (category == null && anniversaries.Count * 2 > folder.Tasks.Count && anniversaries.Count > 0)
|
||||
category = anniversaries.GroupBy(t => t.CategoryId ?? Category.BirthdayId).OrderByDescending(g => g.Count()).First().Key;
|
||||
if (category == null && CategoryFilter is { } cf && cf != TaskQuery.AppointmentsFilter)
|
||||
category = cf;
|
||||
var taskWindow = new TaskWindow(null, IsDarkMode, Categories, category) { Owner = Application.Current.MainWindow };
|
||||
if (taskWindow.ShowDialog() == true)
|
||||
{
|
||||
folder.Tasks.Add(taskWindow.TaskResult);
|
||||
|
||||
@@ -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