Modern Apps git

← Modern-Apps.git

todo: the daily digest counts Today the way the Today view does

Commit
8de225b64ff3296b8ea4b35371ea4db71e9ddb2e
Author
Vayun Mathur <[email protected]>
When
2026-12-01 11:33 UTC (5 days ago)
Parents
c496349
ReminderReceiver.digest hand-rolled its count over all open
top-level tasks (due-by-today minus overdue), bypassing
TodoQuery's blocked/deferred rules: a blocked task and a
not-yet-started (deferred) task due today counted as
'today' (3 today / 1 overdue where the Today view and
widget show 1 today / 1 overdue), and the digest posted
those wrong numbers.

TodoQuery now owns digestCounts (open top-level rows through
the exact Today inView path, split by overdue) and the
receiver calls it. Regression tests pin blocked/deferred/
done/subtask/future cases at 1/1 and a timed task due earlier
today as overdue, not today (the old formula yields 3/1 on
the fixture). No envelope keys touched. Subtasks, quick-add,
mirroring and formats were audited and cleared. Verified:
:todo:testDevUnitTest 418 tests pass; lint errors are
pre-existing on untouched files.

Diff

todo/src/main/java/com/vayunmathur/todo/domain/TodoQuery.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/domain/TodoQuery.kt b/todo/src/main/java/com/vayunmathur/todo/domain/TodoQuery.ktindex 10b69b5d67..bead46d6a9 100644--- a/todo/src/main/java/com/vayunmathur/todo/domain/TodoQuery.kt+++ b/todo/src/main/java/com/vayunmathur/todo/domain/TodoQuery.kt@@ -181,6 +181,22 @@ object TodoQuery {         }     } +    /** Open tasks counted as due today (excluding overdue) and as overdue, for the daily digest. */+    data class DigestCounts(val today: Int, val overdue: Int)++    /**+     * Digest split of the Today view: the same open top-level tasks the Today view and the+     * Today widget show, so blocked tasks and tasks deferred by a future start date are+     * excluded, partitioned by [DueBuckets.isOverdue].+     */+    fun digestCounts(todos: List<Todo>, lists: List<TodoList>, now: Long, zone: TimeZone): DigestCounts {+        val listsById = lists.associateBy { it.syncId }+        val input = Input(todos, lists, TodoView.Today, now = now, zone = zone)+        val visible = toRows(todos, listsById, now, zone).filter { !it.todo.done && inView(it, input) }+        val overdue = visible.count { it.overdue }+        return DigestCounts(today = visible.size - overdue, overdue = overdue)+    }+     fun allTags(todos: List<Todo>): List<String> =         todos.flatMap { it.tags }.distinctBy { it.lowercase() }.sortedBy { it.lowercase() } }
todo/src/main/java/com/vayunmathur/todo/notifications/ReminderReceiver.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderReceiver.kt b/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderReceiver.ktindex 592354e9ac..fa444b54ef 100644--- a/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderReceiver.kt+++ b/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderReceiver.kt@@ -6,7 +6,8 @@ import android.content.Context import android.content.Intent import com.vayunmathur.todo.data.TodoRepository import com.vayunmathur.todo.data.TodoSettings-import com.vayunmathur.todo.domain.DueBuckets+import com.vayunmathur.todo.data.getLists+import com.vayunmathur.todo.domain.TodoQuery import kotlinx.coroutines.launch import kotlinx.datetime.TimeZone @@ -46,10 +47,10 @@ class ReminderReceiver : BroadcastReceiver() {         val settings = TodoSettings(context)         val now = System.currentTimeMillis()         val zone = TimeZone.currentSystemDefault()-        val open = repo.getAll().filter { !it.done && it.parentSyncId == null }-        val overdue = open.count { DueBuckets.isOverdue(it, now, zone) }-        val today = open.count { DueBuckets.isDueByToday(it, now, zone) } - overdue-        if (today + overdue > 0) ReminderNotifications.postDigest(context, today, overdue)+        val counts = TodoQuery.digestCounts(repo.getAll(), repo.getLists(), now, zone)+        if (counts.today + counts.overdue > 0) {+            ReminderNotifications.postDigest(context, counts.today, counts.overdue)+        }         DigestScheduler.schedule(context, settings.digestEnabledNow(), settings.digestMinutesNow(), now + 1)     } 
todo/src/test/java/com/vayunmathur/todo/domain/TodoDigestCountsTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/domain/TodoDigestCountsTest.kt b/todo/src/test/java/com/vayunmathur/todo/domain/TodoDigestCountsTest.ktnew file mode 100644index 0000000000..e9187ceda7--- /dev/null+++ b/todo/src/test/java/com/vayunmathur/todo/domain/TodoDigestCountsTest.kt@@ -0,0 +1,48 @@+package com.vayunmathur.todo.domain++import com.vayunmathur.todo.data.Todo+import kotlinx.datetime.LocalDate+import kotlinx.datetime.LocalTime+import kotlinx.datetime.TimeZone+import kotlin.test.Test+import kotlin.test.assertEquals++class TodoDigestCountsTest {+    private val zone = TimeZone.of("America/Los_Angeles")+    private val now = DueDates.at(LocalDate(2026, 3, 4), LocalTime(10, 0), zone)+    private fun day(offset: Int) = DueDates.startOfDay(LocalDate(2026, 3, 4 + offset), zone)++    @Test+    fun `digest counts match the today view for blocked and deferred tasks`() {+        val todos = listOf(+            Todo(syncId = "blocker", title = "Blocker"),+            Todo(syncId = "blocked", title = "Blocked", blockedBy = listOf("blocker"), dueAt = day(0)),+            Todo(syncId = "overdue", title = "Overdue", dueAt = day(-1)),+            Todo(syncId = "deferred", title = "Deferred", dueAt = day(0), startAt = day(2)),+            Todo(syncId = "genuine", title = "Genuine today", dueAt = day(0)),+            Todo(syncId = "sub", title = "Subtask due today", parentSyncId = "genuine", dueAt = day(0)),+            Todo(syncId = "done", title = "Done today", dueAt = day(0), done = true, completedAt = now),+            Todo(syncId = "future", title = "Future", dueAt = day(3)),+            Todo(syncId = "nodate", title = "No date"),+        )+        val counts = TodoQuery.digestCounts(todos, emptyList(), now, zone)+        assertEquals(1, counts.today)+        assertEquals(1, counts.overdue)+    }++    @Test+    fun `timed task due earlier today is overdue not today`() {+        val todos = listOf(+            Todo(+                syncId = "timed",+                title = "Timed earlier",+                dueAt = DueDates.at(LocalDate(2026, 3, 4), LocalTime(9, 0), zone),+                dueAllDay = false,+            ),+            Todo(syncId = "later", title = "Later today", dueAt = day(0)),+        )+        val counts = TodoQuery.digestCounts(todos, emptyList(), now, zone)+        assertEquals(1, counts.today)+        assertEquals(1, counts.overdue)+    }+}