Modern Apps git

← Modern-Apps.git

todo: bulk/wear reschedule now shifts the reminder with the due date

Commit
4694277ab807be5a9194ec5dbbf9b4d92bdc929c
Author
Vayun Mathur <[email protected]>
When
2026-11-30 19:50 UTC (5 days ago)
Parents
77e3fbb
Two due-changing paths moved dueAt but left reminderAt at its
old absolute instant: bulk reschedule (Today/Tomorrow/Next Week/
Pick date) and the Wear EDIT op. A 30-minutes-before reminder
stayed pinned to the old date — if that instant had passed, the
reminder silently never fired while the UI showed one set; if
not, it fired detached from the new due date. The editor's due
sheet and completion roll-forward already shift by the due delta;
these two paths simply missed it.

The shift now lives in one place, Reminders.shifted (clearing the
due date or setting the first one leaves the reminder alone,
matching editor semantics), and both paths use it. Regression
tests cover the helper, bulk reschedule (+12d and clear-due) and
the Wear EDIT op, all failing pre-fix. Calendar mirror, envelopes
(no keys renamed), quick-add, snooze/digest and format round-trips
were audited and cleared. Verified: :todo:testDevUnitTest 408
tests pass; lint errors are pre-existing on untouched files.

Diff

todo/src/main/java/com/vayunmathur/todo/domain/Reminders.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/domain/Reminders.kt b/todo/src/main/java/com/vayunmathur/todo/domain/Reminders.ktindex 81827275fe..3e9bfb41e9 100644--- a/todo/src/main/java/com/vayunmathur/todo/domain/Reminders.kt+++ b/todo/src/main/java/com/vayunmathur/todo/domain/Reminders.kt@@ -30,6 +30,15 @@ object Reminders {         return if (offset == Offset.DAY_1) base else base - offset.minutes * MINUTE_MS     } +    /**+     * [reminderAt] moved along with a due-date change from [oldDueAt] to [newDueAt], so the+     * reminder keeps the same lead before the due moment. Clearing the due date, or setting+     * the first one, leaves the reminder alone — the editor's due-date sheet behaves the same.+     */+    fun shifted(reminderAt: Long?, oldDueAt: Long?, newDueAt: Long?): Long? =+        if (reminderAt == null || oldDueAt == null || newDueAt == null) reminderAt+        else reminderAt + (newDueAt - oldDueAt)+     /**      * When [todo]'s reminder should next go off, or null for never. A one-time reminder fires      * once at its `reminderAt`. A repeating task keeps the same lead before every later
todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt b/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.ktindex 7135ea1639..43aff14133 100644--- a/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt+++ b/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt@@ -17,6 +17,7 @@ import com.vayunmathur.todo.data.TodoList import com.vayunmathur.todo.data.TodoRepository import com.vayunmathur.todo.data.TodoSettings import com.vayunmathur.todo.domain.QuickAddParser+import com.vayunmathur.todo.domain.Reminders import com.vayunmathur.todo.domain.SortMode import com.vayunmathur.todo.domain.TodoListModel import com.vayunmathur.todo.domain.TodoQuery@@ -226,7 +227,13 @@ class TodoViewModel(         upsertAll(todos.map { it.copy(listSyncId = listSyncId, section = null) })      fun reschedule(todos: List<Todo>, dueAt: Long?) =-        upsertAll(todos.map { it.copy(dueAt = dueAt, dueAllDay = true) })+        upsertAll(todos.map {+            it.copy(+                dueAt = dueAt,+                dueAllDay = true,+                reminderAt = Reminders.shifted(it.reminderAt, it.dueAt, dueAt),+            )+        })      fun setPriority(todos: List<Todo>, priority: Int) = upsertAll(todos.map { it.copy(priority = priority) }) 
todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt b/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.ktindex 539156ca11..fb64fe1232 100644--- a/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt+++ b/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt@@ -348,14 +348,16 @@ class WearTodoSync private constructor(context: Context) {         WearTodoOpKind.QUICK_ADD -> applyQuickAdd(op, now, zone)         WearTodoOpKind.EDIT -> {             val todo = repository.getBySyncId(op.syncId)?.takeIf { !it.deleted } ?: return false+            val newDueAt = when {+                op.clearDue -> null+                op.dueAt != null -> op.dueAt+                else -> todo.dueAt+            }             val edited = todo.copy(                 title = op.title?.trim()?.take(WearTodoProtocol.MAX_TITLE_CHARS)                     ?.takeIf { it.isNotEmpty() } ?: todo.title,-                dueAt = when {-                    op.clearDue -> null-                    op.dueAt != null -> op.dueAt-                    else -> todo.dueAt-                },+                dueAt = newDueAt,+                reminderAt = Reminders.shifted(todo.reminderAt, todo.dueAt, newDueAt),                 dueAllDay = if (op.dueAt != null && !op.clearDue) true else todo.dueAllDay,                 priority = op.priority?.coerceIn(Todo.PRIORITY_NONE, Todo.PRIORITY_MAX)                     ?: todo.priority,
todo/src/test/java/com/vayunmathur/todo/domain/RemindersTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/domain/RemindersTest.kt b/todo/src/test/java/com/vayunmathur/todo/domain/RemindersTest.ktindex c4870445a5..ae1a998eac 100644--- a/todo/src/test/java/com/vayunmathur/todo/domain/RemindersTest.kt+++ b/todo/src/test/java/com/vayunmathur/todo/domain/RemindersTest.kt@@ -34,6 +34,17 @@ class RemindersTest {         assertEquals(Reminders.Offset.entries, Reminders.offsetsFor(allDay = false))     } +    @Test+    fun `shifting a reminder follows its due date`() {+        val due = at(10, 15)+        val reminder = at(10, 14)+        assertEquals(at(12, 14), Reminders.shifted(reminder, due, at(12, 15)))+        // Clearing the due date, or setting the first one, leaves the reminder alone.+        assertEquals(reminder, Reminders.shifted(reminder, due, null))+        assertEquals(reminder, Reminders.shifted(reminder, null, at(12, 15)))+        assertNull(Reminders.shifted(null, due, at(12, 15)))+    }+     @Test     fun `a future reminder fires as set`() {         val todo = Todo(dueAt = at(10, 15), dueAllDay = false, reminderAt = at(10, 14))
todo/src/test/java/com/vayunmathur/todo/platform/TodoViewModelTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/platform/TodoViewModelTest.kt b/todo/src/test/java/com/vayunmathur/todo/platform/TodoViewModelTest.ktindex 2bf25520ab..1de1b34402 100644--- a/todo/src/test/java/com/vayunmathur/todo/platform/TodoViewModelTest.kt+++ b/todo/src/test/java/com/vayunmathur/todo/platform/TodoViewModelTest.kt@@ -179,6 +179,25 @@ class TodoViewModelTest {         await("upsertAll") { repo.getBySyncId("a")!!.title == "Renamed" }     } +    @Test fun rescheduleShiftsReminderAlongWithDueDate() = runBlocking {+        // Fixed instants: a due time and a reminder 30 min before it.+        val due = 1_772_942_400_000L+        val reminder = due - 30 * 60_000L+        repo.upsert(Todo(syncId = "a", title = "A", dueAt = due, dueAllDay = false, reminderAt = reminder))+        val vm = viewModel()++        val newDue = due + 12 * 86_400_000L+        vm.reschedule(listOf(repo.getBySyncId("a")!!), newDue)+        await("reschedule shifts reminder") { repo.getBySyncId("a")!!.dueAt == newDue }+        assertEquals(newDue, repo.getBySyncId("a")!!.dueAt)+        assertEquals(reminder + 12 * 86_400_000L, repo.getBySyncId("a")!!.reminderAt)++        // Clearing the due date keeps the reminder, as the editor does.+        vm.reschedule(listOf(repo.getBySyncId("a")!!), null)+        await("clear due") { repo.getBySyncId("a")!!.dueAt == null }+        assertEquals(reminder + 12 * 86_400_000L, repo.getBySyncId("a")!!.reminderAt)+    }+     @Test fun upsertAllWithEmptyListIsNoOp() = runBlocking {         val vm = viewModel()         vm.upsertAll(emptyList())
todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt b/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.ktindex 5215a5ad4f..893a5482f3 100644--- a/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt+++ b/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt@@ -159,6 +159,21 @@ class WearTodoApplyTest {         )     } +    @Test fun editDueShiftsReminderAlongWithDueDate() = runTest {+        val due = DueDates.startOfDay(LocalDate(2026, 1, 20), zone)+        val reminder = due - 30 * 60_000L+        repo.upsert(Todo(syncId = "a", title = "A", dueAt = due, dueAllDay = false, reminderAt = reminder))+        val newDue = DueDates.startOfDay(LocalDate(2026, 1, 27), zone)+        assertTrue(+            sync.applyWearOp(+                WearTodoOp(WearTodoOpKind.EDIT, syncId = "a", dueAt = newDue), now, zone,+            ),+        )+        val edited = repo.getBySyncId("a")!!+        assertEquals(newDue, edited.dueAt)+        assertEquals(reminder + (newDue - due), edited.reminderAt)+    }+     @Test fun pageSnapshotPagesThroughView() = runTest {         repeat(25) { repo.upsert(Todo(syncId = "t$it", title = "Task $it", position = it.toDouble())) }         val first = sync.buildPage(