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);
|
||||
|
||||
Reference in New Issue
Block a user