- Upcoming: all folders grouped by overdue/today/tomorrow/7 days/later/done - Search (Ctrl+F) + All/Today/Overdue filters + hide done (persisted) - Lead reminder 1/2/3 days or 1 week before; birth year shows age - Several due reminders are combined into one balloon - Folder colors and reordering (drag, context menu) - iCalendar export with RRULE and VALARM - Generated reminder chime (ComfyUI / Stable Audio), can be turned off - Undo snackbar for deleted tasks/folders (Ctrl+Z), Ctrl+N, Del, Esc - 41 tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.7 KiB
C#
66 lines
2.7 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Collections;
|
|
using System.Globalization;
|
|
using ReminderOrganizer.Models;
|
|
|
|
namespace ReminderOrganizer.Core
|
|
{
|
|
public enum TaskFilterMode { All, Today, Overdue }
|
|
|
|
/// <summary>Groups in the "Upcoming" view, in display order.</summary>
|
|
public enum TaskBucket { Overdue, Today, Tomorrow, ThisWeek, Later, Done }
|
|
|
|
/// <summary>Pure filter/sort/group rules for the task list.</summary>
|
|
public static class TaskQuery
|
|
{
|
|
public static TaskBucket Bucket(ReminderTask t, DateTime now)
|
|
{
|
|
if (t.IsNotified) return TaskBucket.Done;
|
|
if (t.ReminderDate < now) return TaskBucket.Overdue;
|
|
var days = (t.ReminderDate.Date - now.Date).Days;
|
|
return days switch
|
|
{
|
|
0 => TaskBucket.Today,
|
|
1 => TaskBucket.Tomorrow,
|
|
< 7 => TaskBucket.ThisWeek,
|
|
_ => TaskBucket.Later
|
|
};
|
|
}
|
|
|
|
public static bool Matches(ReminderTask t, string? search, TaskFilterMode mode, bool hideDone, DateTime now)
|
|
{
|
|
if (hideDone && t.IsNotified) return false;
|
|
switch (mode)
|
|
{
|
|
case TaskFilterMode.Today when t.ReminderDate.Date != now.Date: return false;
|
|
case TaskFilterMode.Overdue when t.IsNotified || t.ReminderDate >= now: return false;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(search)) return true;
|
|
var s = search.Trim();
|
|
return Contains(t.Name, s) || Contains(t.Description, s) || Contains(t.FolderName, s);
|
|
}
|
|
|
|
private static bool Contains(string? text, string s) =>
|
|
text != null && CultureInfo.CurrentCulture.CompareInfo.IndexOf(text, s, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) >= 0;
|
|
|
|
/// <summary>Sort: bucket (overdue, today, … done), then date, then name.</summary>
|
|
public sealed class Comparer : IComparer
|
|
{
|
|
private readonly Func<DateTime> _now;
|
|
public Comparer(Func<DateTime>? now = null) => _now = now ?? (() => DateTime.Now);
|
|
|
|
public int Compare(object? x, object? y)
|
|
{
|
|
if (x is not ReminderTask a || y is not ReminderTask b) return 0;
|
|
var now = _now();
|
|
int c = Bucket(a, now).CompareTo(Bucket(b, now));
|
|
if (c != 0) return c;
|
|
c = a.IsNotified ? b.ReminderDate.CompareTo(a.ReminderDate) // done: newest first
|
|
: a.ReminderDate.CompareTo(b.ReminderDate);
|
|
return c != 0 ? c : string.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase);
|
|
}
|
|
}
|
|
}
|
|
}
|