Modern Apps git

← Modern-Apps.git

todo: markdown notes editor, one-time/repeating editor, repeating reminders

Commit
47d96c529c4978d396cc720d09ccc6709ab4c651
Author
Vayun Mathur <[email protected]>
When
2026-11-01 19:06 UTC (1 month ago)
Parents
5c12d70
The task editor's notes field and property chips were hard to use: notes
were a plain text box that only rendered a markdown subset when not
focused, and the nine property chips sat in one undifferentiated row with
labels like "Start date" and "Blocked by" that didn't say what they did.
Repeating tasks also had two real gaps: a repeat set without a due date
never rolled forward, and a repeating task left unchecked stopped
reminding because its single reminderAt was already in the past.

Notes
- Replace MarkdownNotes with the shared ODF markdown editor
  (rememberOdfMarkdownEditorController + OdfMarkdownEditorField), the
  same setup the contacts note uses. The formatting toolbar shows in the
  DetailScaffold bottom bar while the field is focused. Storage stays
  markdown, so existing notes carry over. MarkdownNotes.kt is deleted.

Editor layout
- New One-time / Repeating segmented toggle at the top. Choosing
  Repeating sets a daily repeat in one tap; One-time clears the repeat
  (replacing the "Doesn't repeat" option in the repeat sheet).
- Chips are grouped under Schedule (repeat, due / "Next: ...", remind
  me), Organize (list, priority, tags) and Details (hide until, time
  estimate, waiting on).
- Renames: Start date -> Hide until (it hides the task from
  Today/Upcoming), Estimate -> Time estimate, Blocked by -> Waiting on,
  Reminder -> Remind me. Repeat, due and reminder sheets gain titles.
- Setting a repeat on a task with no due date seeds the due date with
  Recurrence.firstOnOrAfter(today), so the task actually rolls forward.
- The due sheet hides "No date" for repeating tasks.

Reminders
- The reminder sheet adapts to the task: repeating tasks get "Remind me
  each time" and a time-only picker, and the chip reads "Remind at
  8:00 AM". All-day tasks only offer "On the day at 9:00" and "The day
  before at 9:00", since minute offsets are meaningless for them.
- New Reminders.nextFire computes when a reminder should next go off.
  One-time reminders fire once. Repeating tasks keep the same lead
  before every later occurrence, so an unchecked daily task still
  reminds tomorrow. ReminderScheduler.reconcile uses it,
  ReminderReceiver re-arms the next occurrence after posting (no data
  changes in that case, so the background observer would not), and the
  TodoBackground reminder key now includes dueAt and recurrence.
- Known, unchanged: snoozing a repeating task's reminder permanently
  shifts its time for later occurrences.

Verification
- ./gradlew :todo:compileDevKotlin :todo:testDevUnitTest :todo:lint
  :todo:detekt all pass. checkMetadata passes.
- New unit tests: RemindersTest (offsetsFor, nextFire for one-time,
  overdue daily, weekly day-before lead, done/after-completion) and
  RecurrenceTest (firstOnOrAfter for daily/weekly/monthly/last day).
- TodoAddTest now looks for the "Repeating" toggle instead of the old
  "Repeat" chip. Listing screenshots regenerated with :todo:metadata;
  the phone editor shot was reviewed. Not yet exercised on a device.

Diff

metadata_data/photos/todo/phone/2.png
diff --git a/metadata_data/photos/todo/phone/2.png b/metadata_data/photos/todo/phone/2.pngindex bf47af23f8..a03f86564f 100644Binary files a/metadata_data/photos/todo/phone/2.png and b/metadata_data/photos/todo/phone/2.png differ
metadata_data/photos/todo/tablet/1.png
diff --git a/metadata_data/photos/todo/tablet/1.png b/metadata_data/photos/todo/tablet/1.pngindex 528b1962db..5e840b7df9 100644Binary files a/metadata_data/photos/todo/tablet/1.png and b/metadata_data/photos/todo/tablet/1.png differ
todo/src/androidTest/java/com/vayunmathur/todo/ui/TodoAddTest.kt
diff --git a/todo/src/androidTest/java/com/vayunmathur/todo/ui/TodoAddTest.kt b/todo/src/androidTest/java/com/vayunmathur/todo/ui/TodoAddTest.ktindex 7a557252e1..5bd9808076 100644--- a/todo/src/androidTest/java/com/vayunmathur/todo/ui/TodoAddTest.kt+++ b/todo/src/androidTest/java/com/vayunmathur/todo/ui/TodoAddTest.kt@@ -125,8 +125,8 @@ class TodoAddTest {         private const val SAVE_SETTLE_MS = 1_000L         private const val SEARCH_PLACEHOLDER = "Search Today"         private const val EDITOR_NOTES_LABEL = "Notes"-        // Tasks created from Today are due today, so check a chip that is always unset.-        private const val NO_DUE_DATE = "Repeat"+        // Tasks created from Today are due today, so check the always-present task-type toggle.+        private const val NO_DUE_DATE = "Repeating"         private const val ADD_DESCRIPTION = "Add"         private const val EDIT_TEXT_CLASS = "android.widget.EditText"         private const val TASK_TITLE = "Journey Todo Alpha"
todo/src/main/java/com/vayunmathur/todo/domain/Recurrence.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/domain/Recurrence.kt b/todo/src/main/java/com/vayunmathur/todo/domain/Recurrence.ktindex 23f476b4e3..9770365428 100644--- a/todo/src/main/java/com/vayunmathur/todo/domain/Recurrence.kt+++ b/todo/src/main/java/com/vayunmathur/todo/domain/Recurrence.kt@@ -47,6 +47,20 @@ sealed interface Recurrence {         }     } +    /** The first day on or after [today] this schedule lands on; seeds a repeating task's due date. */+    fun firstOnOrAfter(today: LocalDate): LocalDate {+        val matches = when (this) {+            is Weekly -> days.isEmpty() || today.dayOfWeek in days+            is Monthly -> when (dayOfMonth) {+                null -> true+                LAST_DAY -> today.day == lengthOfMonth(LocalDate(today.year, today.month.number, 1))+                else -> today.day == dayOfMonth+            }+            else -> true+        }+        return if (matches) today else nextDate(today, today)+    }+     fun serialize(): String {         val parts = mutableListOf<String>()         parts += "FREQ=" + when (this) {
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 951cc16114..e168665b95 100644--- a/todo/src/main/java/com/vayunmathur/todo/domain/Reminders.kt+++ b/todo/src/main/java/com/vayunmathur/todo/domain/Reminders.kt@@ -1,5 +1,6 @@ package com.vayunmathur.todo.domain +import com.vayunmathur.todo.data.Todo import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalTime import kotlinx.datetime.TimeZone@@ -9,11 +10,17 @@ import kotlinx.datetime.minus object Reminders {     val ALL_DAY_TIME = LocalTime(9, 0)     private const val MINUTE_MS = 60_000L+    private const val DAY_MS = 86_400_000L+    private const val MAX_OCCURRENCES = 400      enum class Offset(val minutes: Long) {         AT_DUE(0), MINUTES_10(10), HOUR_1(60), DAY_1(24 * 60)     } +    /** Offsets that make sense for the due kind: minutes-before an all-day task is meaningless. */+    fun offsetsFor(allDay: Boolean): List<Offset> =+        if (allDay) listOf(Offset.AT_DUE, Offset.DAY_1) else Offset.entries+     fun at(dueAt: Long, allDay: Boolean, offset: Offset, zone: TimeZone): Long {         if (!allDay) return dueAt - offset.minutes * MINUTE_MS         val date = DueDates.localDate(dueAt, zone)@@ -21,4 +28,31 @@ object Reminders {         val base = DueDates.at(day, ALL_DAY_TIME, zone)         return if (offset == Offset.DAY_1) base else base - offset.minutes * MINUTE_MS     }++    /**+     * 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+     * occurrence, so a daily task left unchecked still reminds tomorrow instead of going quiet.+     */+    fun nextFire(todo: Todo, now: Long, zone: TimeZone): Long? {+        val reminderAt = todo.reminderAt ?: return null+        if (todo.done || todo.deleted) return null+        if (reminderAt > now) return reminderAt+        val dueAt = todo.dueAt+        val recurrence = Recurrence.parse(todo.recurrence)+        if (dueAt == null || recurrence == null || recurrence is Recurrence.AfterCompletion) return null+        val lead = dueAt - reminderAt+        val dueDate = DueDates.localDate(dueAt, zone)+        val time = DueDates.localTime(dueAt, zone)+        // Jump close to now first so a long-overdue task doesn't walk every missed occurrence.+        val leadDays = (lead / DAY_MS).coerceAtLeast(0).toInt()+        val floor = DueDates.localDate(now, zone).minus(leadDays + 2, DateTimeUnit.DAY)+        var date = recurrence.nextDate(dueDate, floor)+        repeat(MAX_OCCURRENCES) {+            val due = if (todo.dueAllDay) DueDates.startOfDay(date, zone) else DueDates.at(date, time, zone)+            if (due - lead > now) return due - lead+            date = recurrence.nextDate(dueDate, date)+        }+        return null+    } }
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 3223505a79..592354e9ac 100644--- a/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderReceiver.kt+++ b/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderReceiver.kt@@ -33,10 +33,13 @@ class ReminderReceiver : BroadcastReceiver() {         val todo = syncId?.let { repo.getBySyncId(it) } ?: return         val at = todo.reminderAt ?: return         // A reminder that moved later since this alarm was set is re-armed by reconcile.-        if (todo.done || todo.deleted || at > System.currentTimeMillis() + EARLY_SLACK_MS) return+        val now = System.currentTimeMillis()+        if (todo.done || todo.deleted || at > now + EARLY_SLACK_MS) return         val channelName = todo.listSyncId?.let { repo.getListBySyncId(it)?.name }             ?: context.getString(com.vayunmathur.todo.R.string.view_inbox)         ReminderNotifications.postReminder(context, todo, channelName)+        // Nothing in the data changed, so arm a repeating task's next occurrence here.+        if (todo.recurrence != null) ReminderScheduler.reconcile(context, repo.getAll(), maxOf(now, at) + 1)     }      private suspend fun digest(context: Context, repo: TodoRepository) {
todo/src/main/java/com/vayunmathur/todo/notifications/ReminderScheduler.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderScheduler.kt b/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderScheduler.ktindex 38de609ea8..a2dda01f41 100644--- a/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderScheduler.kt+++ b/todo/src/main/java/com/vayunmathur/todo/notifications/ReminderScheduler.kt@@ -7,6 +7,8 @@ import android.content.Intent import androidx.core.content.edit import androidx.core.net.toUri import com.vayunmathur.todo.data.Todo+import com.vayunmathur.todo.domain.Reminders+import kotlinx.datetime.TimeZone  /**  * Keeps one exact alarm per pending task reminder.@@ -26,10 +28,11 @@ object ReminderScheduler {         val alarms = context.getSystemService(AlarmManager::class.java) ?: return         val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)         val previous = prefs.getStringSet(KEY_SCHEDULED, emptySet()).orEmpty()-        val pending = todos.filter { !it.done && !it.deleted && (it.reminderAt ?: 0L) > now }-        val wanted = pending.map { it.syncId }.toSet()+        val zone = TimeZone.currentSystemDefault()+        val pending = todos.mapNotNull { todo -> Reminders.nextFire(todo, now, zone)?.let { todo.syncId to it } }+        val wanted = pending.map { it.first }.toSet()         (previous - wanted).forEach { alarms.cancel(intent(context, it)) }-        pending.forEach { schedule(context, alarms, it.syncId, it.reminderAt!!) }+        pending.forEach { (syncId, at) -> schedule(context, alarms, syncId, at) }         prefs.edit { putStringSet(KEY_SCHEDULED, wanted) }     } 
todo/src/main/java/com/vayunmathur/todo/platform/TodoBackground.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/platform/TodoBackground.kt b/todo/src/main/java/com/vayunmathur/todo/platform/TodoBackground.ktindex c9549c6d9f..148e223e6f 100644--- a/todo/src/main/java/com/vayunmathur/todo/platform/TodoBackground.kt+++ b/todo/src/main/java/com/vayunmathur/todo/platform/TodoBackground.kt@@ -27,7 +27,13 @@ object TodoBackground {     private const val SETTLE_MS = 500L     private const val MIRROR_SETTLE_MS = 2_000L -    private data class ReminderKey(val syncId: String, val reminderAt: Long?, val done: Boolean)+    private data class ReminderKey(+        val syncId: String,+        val reminderAt: Long?,+        val done: Boolean,+        val dueAt: Long?,+        val recurrence: String?,+    )      @OptIn(FlowPreview::class)     fun start(context: Context) {@@ -38,7 +44,8 @@ object TodoBackground {         repo.appScope.launch {             repo.todos                 .map { todos ->-                    todos.filter { it.reminderAt != null }.map { ReminderKey(it.syncId, it.reminderAt, it.done) }+                    todos.filter { it.reminderAt != null }+                        .map { ReminderKey(it.syncId, it.reminderAt, it.done, it.dueAt, it.recurrence) }                 }                 .distinctUntilChanged()                 .debounce(SETTLE_MS)
todo/src/main/java/com/vayunmathur/todo/ui/DueDateSheet.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/DueDateSheet.kt b/todo/src/main/java/com/vayunmathur/todo/ui/DueDateSheet.ktindex 4d86a3d765..d8486a6c2a 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/DueDateSheet.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/DueDateSheet.kt@@ -19,6 +19,7 @@ import com.vayunmathur.library.ui.IconAccessTime import com.vayunmathur.library.ui.IconCalendar import com.vayunmathur.library.ui.IconToday import com.vayunmathur.library.ui.ListItem+import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.ModalBottomSheet import com.vayunmathur.library.ui.Text import com.vayunmathur.todo.R@@ -28,10 +29,19 @@ import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalTime import kotlinx.datetime.TimeZone -/** Due date and optional time: one-tap shortcuts, a date picker and a time picker. */+/**+ * Due date and optional time: one-tap shortcuts, a date picker and a time picker. For a+ * [repeating] task this is the next occurrence, which can't be cleared.+ */ @OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable-fun DueDateSheet(dueAt: Long?, allDay: Boolean, onSet: (dueAt: Long?, allDay: Boolean) -> Unit, onDismiss: () -> Unit) {+fun DueDateSheet(+    dueAt: Long?,+    allDay: Boolean,+    repeating: Boolean,+    onSet: (dueAt: Long?, allDay: Boolean) -> Unit,+    onDismiss: () -> Unit,+) {     val zone = TimeZone.currentSystemDefault()     var pickDate by remember { mutableStateOf(false) }     var pickTime by remember { mutableStateOf(false) }@@ -43,11 +53,16 @@ fun DueDateSheet(dueAt: Long?, allDay: Boolean, onSet: (dueAt: Long?, allDay: Bo     }      ModalBottomSheet(onDismissRequest = onDismiss) {+        Text(+            stringResource(if (repeating) R.string.next_occurrence else R.string.add_due_date),+            style = MaterialTheme.typography.titleMedium,+            modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp),+        )         FlowRow(             modifier = Modifier.padding(horizontal = 16.dp),             horizontalArrangement = Arrangement.spacedBy(8.dp),         ) {-            DueShortcuts.entries.forEach { shortcut ->+            DueShortcuts.entries.filter { !repeating || it != DueShortcuts.NONE }.forEach { shortcut ->                 val target = shortcut.dueAt()                 val selected = target?.let { t -> dueAt?.let { DueDates.localDate(it, zone) == DueDates.localDate(t, zone) } }                     ?: (dueAt == null)
todo/src/main/java/com/vayunmathur/todo/ui/EditorChips.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/EditorChips.kt b/todo/src/main/java/com/vayunmathur/todo/ui/EditorChips.ktindex daeda74256..abfd8343fb 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/EditorChips.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/EditorChips.kt@@ -2,8 +2,11 @@ package com.vayunmathur.todo.ui  import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.FlowRow+import androidx.compose.foundation.layout.FlowRowScope+import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue@@ -28,7 +31,12 @@ import com.vayunmathur.library.ui.IconLocalOffer import com.vayunmathur.library.ui.IconLock import com.vayunmathur.library.ui.IconRepeat import com.vayunmathur.library.ui.IconSchedule+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.SegmentedButton+import com.vayunmathur.library.ui.SegmentedButtonDefaults+import com.vayunmathur.library.ui.SingleChoiceSegmentedButtonRow import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.rememberIs24Hour import com.vayunmathur.todo.R import com.vayunmathur.todo.data.Todo import com.vayunmathur.todo.domain.DueDates@@ -36,10 +44,14 @@ import com.vayunmathur.todo.domain.Recurrence import com.vayunmathur.todo.platform.TodoActions import com.vayunmathur.todo.platform.TodoUiState import kotlinx.datetime.TimeZone+import kotlinx.datetime.daysUntil  internal enum class EditorSheet { DUE, REPEAT, REMINDER, LIST, TAGS, START, BLOCKED } -/** Every property of a task as a tappable chip; set ones are shown selected. */+/**+ * A task's properties, grouped: whether it's one-time or repeating, then its schedule, how it's+ * organized, and rarer details. Set properties show as selected chips.+ */ @OptIn(ExperimentalLayoutApi::class) @Composable fun EditorChips(state: TodoUiState, actions: TodoActions, modifier: Modifier = Modifier) {@@ -49,51 +61,111 @@ fun EditorChips(state: TodoUiState, actions: TodoActions, modifier: Modifier = M     val chip: @Composable (Boolean, String, @Composable () -> Unit, () -> Unit) -> Unit = { on, label, lead, click ->         FilterChip(selected = on, onClick = click, label = { Text(label) }, leadingIcon = lead)     }-    FlowRow(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(8.dp)) {-        chip(-            todo.dueAt != null,-            todo.dueAt?.let { dueLabel(it, todo.dueAllDay, state.now) } ?: stringResource(R.string.add_due_date),-            { IconEvent(icon) },-        ) { sheet = EditorSheet.DUE }-        val recurrence = Recurrence.parse(todo.recurrence)-        chip(recurrence != null, recurrence?.let { recurrenceLabel(it) } ?: stringResource(R.string.repeat), { IconRepeat(icon) }) {-            sheet = EditorSheet.REPEAT-        }-        chip(-            todo.reminderAt != null,-            todo.reminderAt?.let { dueLabel(it, false, state.now) } ?: stringResource(R.string.reminder),-            { IconAlarm(icon) },-        ) { sheet = EditorSheet.REMINDER }-        PriorityChip(todo.priority) { p -> actions.update { it.copy(priority = p) } }-        val list = state.lists.firstOrNull { it.syncId == todo.listSyncId }-        val listLabel = list?.let { l -> listOfNotNull(l.name, todo.section).joinToString(" / ") } ?: stringResource(R.string.view_inbox)-        chip(list != null, listLabel, { IconList(icon) }) { sheet = EditorSheet.LIST }-        chip(-            todo.tags.isNotEmpty(),-            todo.tags.joinToString(" ") { "#$it" }.ifEmpty { stringResource(R.string.tags) },-            { IconLocalOffer(icon) },-        ) { sheet = EditorSheet.TAGS }-        EstimateChip(todo.estimateMinutes) { m -> actions.update { it.copy(estimateMinutes = m) } }-        chip(-            todo.startAt != null,-            todo.startAt?.let {-                stringResource(R.string.starts_on, DateString.dateShort(DueDates.localDate(it, TimeZone.currentSystemDefault())))-            } ?: stringResource(R.string.start_date),-            { IconSchedule(icon) },-        ) { sheet = EditorSheet.START }-        chip(-            todo.blockedBy.isNotEmpty(),-            if (todo.blockedBy.isEmpty()) {-                stringResource(R.string.blocked_by)+    val recurrence = Recurrence.parse(todo.recurrence)+    Column(modifier, verticalArrangement = Arrangement.spacedBy(12.dp)) {+        TaskKindToggle(+            repeating = recurrence != null,+            onOnce = { actions.update { it.copy(recurrence = null) } },+            onRepeating = { actions.update { it.withRecurrence(Recurrence.Daily(), state.now) } },+        )+        ChipSection(stringResource(R.string.section_schedule)) {+            if (recurrence != null) {+                chip(true, recurrenceLabel(recurrence), { IconRepeat(icon) }) { sheet = EditorSheet.REPEAT }+                chip(+                    todo.dueAt != null,+                    todo.dueAt?.let { stringResource(R.string.next_due, dueLabel(it, todo.dueAllDay, state.now)) }+                        ?: stringResource(R.string.next_occurrence),+                    { IconEvent(icon) },+                ) { sheet = EditorSheet.DUE }             } else {-                pluralStringResource(R.plurals.waiting_on, todo.blockedBy.size, todo.blockedBy.size)-            },-            { IconLock(icon) },-        ) { sheet = EditorSheet.BLOCKED }+                chip(+                    todo.dueAt != null,+                    todo.dueAt?.let { dueLabel(it, todo.dueAllDay, state.now) } ?: stringResource(R.string.add_due_date),+                    { IconEvent(icon) },+                ) { sheet = EditorSheet.DUE }+            }+            chip(todo.reminderAt != null, reminderLabel(todo, recurrence != null, state.now), { IconAlarm(icon) }) {+                sheet = EditorSheet.REMINDER+            }+        }+        ChipSection(stringResource(R.string.section_organize)) {+            val list = state.lists.firstOrNull { it.syncId == todo.listSyncId }+            val listLabel = list?.let { l -> listOfNotNull(l.name, todo.section).joinToString(" / ") } ?: stringResource(R.string.view_inbox)+            chip(list != null, listLabel, { IconList(icon) }) { sheet = EditorSheet.LIST }+            PriorityChip(todo.priority) { p -> actions.update { it.copy(priority = p) } }+            chip(+                todo.tags.isNotEmpty(),+                todo.tags.joinToString(" ") { "#$it" }.ifEmpty { stringResource(R.string.tags) },+                { IconLocalOffer(icon) },+            ) { sheet = EditorSheet.TAGS }+        }+        ChipSection(stringResource(R.string.section_details)) {+            chip(+                todo.startAt != null,+                todo.startAt?.let {+                    stringResource(R.string.starts_on, DateString.dateShort(DueDates.localDate(it, TimeZone.currentSystemDefault())))+                } ?: stringResource(R.string.start_date),+                { IconSchedule(icon) },+            ) { sheet = EditorSheet.START }+            EstimateChip(todo.estimateMinutes) { m -> actions.update { it.copy(estimateMinutes = m) } }+            chip(+                todo.blockedBy.isNotEmpty(),+                if (todo.blockedBy.isEmpty()) {+                    stringResource(R.string.blocked_by)+                } else {+                    pluralStringResource(R.plurals.waiting_on, todo.blockedBy.size, todo.blockedBy.size)+                },+                { IconLock(icon) },+            ) { sheet = EditorSheet.BLOCKED }+        }     }     sheet?.let { EditorSheetHost(it, state, actions) { sheet = null } } } +@Composable+private fun TaskKindToggle(repeating: Boolean, onOnce: () -> Unit, onRepeating: () -> Unit) {+    SingleChoiceSegmentedButtonRow(Modifier.fillMaxWidth()) {+        SegmentedButton(+            selected = !repeating,+            onClick = { if (repeating) onOnce() },+            shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2),+            label = { Text(stringResource(R.string.kind_once)) },+        )+        SegmentedButton(+            selected = repeating,+            onClick = { if (!repeating) onRepeating() },+            shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2),+            label = { Text(stringResource(R.string.kind_repeating)) },+        )+    }+}++@OptIn(ExperimentalLayoutApi::class)+@Composable+private fun ChipSection(title: String, content: @Composable FlowRowScope.() -> Unit) {+    Column {+        Text(title, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+        FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), content = content)+    }+}++/** A repeating task's reminder reads as a time of day, since it fires for every occurrence. */+@Composable+private fun reminderLabel(todo: Todo, repeating: Boolean, now: Long): String {+    val is24 = rememberIs24Hour()+    val at = todo.reminderAt ?: return stringResource(R.string.reminder)+    val due = todo.dueAt+    if (!repeating || due == null) return dueLabel(at, false, now)+    val zone = TimeZone.currentSystemDefault()+    val time = DateString.time(DueDates.localTime(at, zone), is24)+    val daysBefore = DueDates.localDate(at, zone).daysUntil(DueDates.localDate(due, zone))+    return if (daysBefore <= 0) {+        stringResource(R.string.remind_at, time)+    } else {+        pluralStringResource(R.plurals.remind_days_before_at, daysBefore, daysBefore, time)+    }+}+ @Composable private fun PriorityChip(priority: Int, onSet: (Int) -> Unit) {     var open by remember { mutableStateOf(false) }
todo/src/main/java/com/vayunmathur/todo/ui/EditorSheetHost.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/EditorSheetHost.kt b/todo/src/main/java/com/vayunmathur/todo/ui/EditorSheetHost.ktindex c89c49b3a3..e1b4c15ba4 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/EditorSheetHost.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/EditorSheetHost.kt@@ -13,30 +13,34 @@ import com.vayunmathur.library.ui.ListItem import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.todo.R+import com.vayunmathur.todo.data.Todo+import com.vayunmathur.todo.domain.DueDates import com.vayunmathur.todo.domain.Recurrence import com.vayunmathur.todo.platform.TodoActions import com.vayunmathur.todo.platform.TodoUiState+import kotlinx.datetime.TimeZone import com.vayunmathur.library.ui.R as UiR  /** Shows the sheet or dialog for one [EditorSheet]; every choice dismisses it. */ @Composable internal fun EditorSheetHost(sheet: EditorSheet, state: TodoUiState, actions: TodoActions, onDismiss: () -> Unit) {     val todo = state.todo-    val set: ((com.vayunmathur.todo.data.Todo) -> com.vayunmathur.todo.data.Todo) -> Unit = { transform ->+    val set: ((Todo) -> Todo) -> Unit = { transform ->         actions.update(transform)         onDismiss()     }+    val repeating = todo.recurrence != null     when (sheet) {-        EditorSheet.DUE -> DueDateSheet(todo.dueAt, todo.dueAllDay, onSet = { due, allDay ->+        EditorSheet.DUE -> DueDateSheet(todo.dueAt, todo.dueAllDay, repeating, onSet = { due, allDay ->             set { t ->                 val shift = if (t.dueAt != null && due != null) due - t.dueAt else null                 t.copy(dueAt = due, dueAllDay = allDay, reminderAt = shift?.let { s -> t.reminderAt?.plus(s) } ?: t.reminderAt)             }         }, onDismiss = onDismiss)         EditorSheet.REPEAT -> RecurrenceSheet(Recurrence.parse(todo.recurrence), onSet = { r ->-            set { it.copy(recurrence = r?.serialize()) }+            set { it.withRecurrence(r, state.now) }         }, onDismiss = onDismiss)-        EditorSheet.REMINDER -> ReminderSheet(todo.dueAt, todo.dueAllDay, todo.reminderAt, onSet = { at ->+        EditorSheet.REMINDER -> ReminderSheet(todo, onSet = { at ->             set { it.copy(reminderAt = at) }         }, onDismiss = onDismiss)         EditorSheet.LIST -> ListSectionPickerDialog(state.lists, todo.listSyncId, todo.section, onPick = { list, section ->@@ -52,6 +56,17 @@ internal fun EditorSheetHost(sheet: EditorSheet, state: TodoUiState, actions: To     } } +/**+ * Makes the task repeat on [recurrence]. A repeating task only rolls forward from a due date,+ * so one without gets the schedule's first day from today.+ */+internal fun Todo.withRecurrence(recurrence: Recurrence, now: Long): Todo {+    if (dueAt != null) return copy(recurrence = recurrence.serialize())+    val zone = TimeZone.currentSystemDefault()+    val first = recurrence.firstOnOrAfter(DueDates.localDate(now, zone))+    return copy(recurrence = recurrence.serialize(), dueAt = DueDates.startOfDay(first, zone), dueAllDay = true)+}+ /** A set start date offers clearing first; otherwise go straight to the picker. */ @Composable private fun StartDateDialog(startAt: Long?, onSet: (Long?) -> Unit, onDismiss: () -> Unit) {
todo/src/main/java/com/vayunmathur/todo/ui/MarkdownNotes.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/MarkdownNotes.kt b/todo/src/main/java/com/vayunmathur/todo/ui/MarkdownNotes.ktdeleted file mode 100644index 83a5d4a71d..0000000000--- a/todo/src/main/java/com/vayunmathur/todo/ui/MarkdownNotes.kt+++ /dev/null@@ -1,106 +0,0 @@-package com.vayunmathur.todo.ui--import androidx.compose.foundation.clickable-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.runtime.Composable-import androidx.compose.runtime.LaunchedEffect-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue-import androidx.compose.ui.Modifier-import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester-import androidx.compose.ui.focus.onFocusChanged-import androidx.compose.ui.graphics.Color-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.AnnotatedString-import androidx.compose.ui.text.LinkAnnotation-import androidx.compose.ui.text.SpanStyle-import androidx.compose.ui.text.TextLinkStyles-import androidx.compose.ui.text.buildAnnotatedString-import androidx.compose.ui.text.font.FontWeight-import androidx.compose.ui.text.style.TextDecoration-import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.OutlinedTextField-import com.vayunmathur.library.ui.Text-import com.vayunmathur.todo.R--/**- * Notes field that grows with its text. While not being edited it renders light markdown:- * `- ` / `* ` bullets, `[ ]` / `[x]` checkboxes, `**bold**`, and tappable links. The stored- * text stays plain.- */-@Composable-fun MarkdownNotes(notes: String, onChange: (String) -> Unit, modifier: Modifier = Modifier) {-    var editing by remember { mutableStateOf(notes.isEmpty()) }-    val focus = remember { FocusRequester() }-    if (editing || notes.isBlank()) {-        var hadFocus by remember { mutableStateOf(false) }-        OutlinedTextField(-            value = notes,-            onValueChange = onChange,-            modifier = modifier.fillMaxWidth().focusRequester(focus).onFocusChanged {-                if (hadFocus && !it.isFocused && notes.isNotBlank()) editing = false-                hadFocus = it.isFocused-            },-            label = { Text(stringResource(R.string.todo_notes)) },-            minLines = 3,-        )-        LaunchedEffect(editing) { if (editing && notes.isNotEmpty()) focus.requestFocus() }-    } else {-        val link = MaterialTheme.colorScheme.primary-        val rendered = remember(notes, link) { renderMarkdown(notes, link) }-        Text(-            rendered,-            modifier = modifier.fillMaxWidth().clickable { editing = true }.padding(vertical = 8.dp),-            style = MaterialTheme.typography.bodyLarge,-        )-    }-}--private val URL = Regex("https?://[^\\s)]+")-private val BOLD = Regex("\\*\\*(.+?)\\*\\*")--internal fun renderMarkdown(text: String, linkColor: Color): AnnotatedString = buildAnnotatedString {-    text.lines().forEachIndexed { i, raw ->-        if (i > 0) append('\n')-        val line = when {-            raw.startsWith("- [ ] ") -> "☐ " + raw.removePrefix("- [ ] ")-            raw.startsWith("- [x] ", ignoreCase = true) -> "☑ " + raw.substring(6)-            raw.startsWith("- ") || raw.startsWith("* ") -> "•  " + raw.substring(2)-            else -> raw-        }-        appendInline(line, linkColor)-    }-}--private fun AnnotatedString.Builder.appendInline(line: String, linkColor: Color) {-    var cursor = 0-    val bolds = BOLD.findAll(line).toList()-    val plain = StringBuilder()-    val boldRanges = mutableListOf<IntRange>()-    for (m in bolds) {-        plain.append(line, cursor, m.range.first)-        val start = plain.length-        plain.append(m.groupValues[1])-        boldRanges += start until plain.length-        cursor = m.range.last + 1-    }-    plain.append(line.substring(cursor))-    val offset = length-    append(plain.toString())-    boldRanges.forEach { addStyle(SpanStyle(fontWeight = FontWeight.Bold), offset + it.first, offset + it.last + 1) }-    URL.findAll(plain).forEach { m ->-        addLink(-            LinkAnnotation.Url(-                m.value,-                TextLinkStyles(SpanStyle(color = linkColor, textDecoration = TextDecoration.Underline)),-            ),-            offset + m.range.first,-            offset + m.range.last + 1,-        )-    }-}
todo/src/main/java/com/vayunmathur/todo/ui/RecurrenceSheet.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/RecurrenceSheet.kt b/todo/src/main/java/com/vayunmathur/todo/ui/RecurrenceSheet.ktindex f400209028..e1e0afd5fa 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/RecurrenceSheet.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/RecurrenceSheet.kt@@ -24,6 +24,7 @@ import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.ListItem+import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.ModalBottomSheet import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Switch@@ -40,14 +41,19 @@ private enum class Unit4 { DAYS, WEEKS, MONTHS, YEARS } /** Preset repeats plus a custom editor (interval, unit, weekdays, last day, from completion). */ @OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable-fun RecurrenceSheet(current: Recurrence?, onSet: (Recurrence?) -> Unit, onDismiss: () -> Unit) {+fun RecurrenceSheet(current: Recurrence?, onSet: (Recurrence) -> Unit, onDismiss: () -> Unit) {     var custom by remember { mutableStateOf(false) }     ModalBottomSheet(onDismissRequest = onDismiss) {         if (!custom) {+            Text(+                stringResource(R.string.repeat_how_often),+                style = MaterialTheme.typography.titleMedium,+                modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp),+            )+            val weekdays = Recurrence.Weekly(1, DayOfWeek.entries.take(WORKDAYS).toSet())             val presets = listOf(-                null,                 Recurrence.Daily(),-                Recurrence.Weekly(1, DayOfWeek.entries.take(WORKDAYS).toSet()),+                weekdays,                 Recurrence.Weekly(),                 Recurrence.Monthly(),                 Recurrence.Yearly(),@@ -55,13 +61,7 @@ fun RecurrenceSheet(current: Recurrence?, onSet: (Recurrence?) -> Unit, onDismis             presets.forEach { preset ->                 ListItem(                     headlineContent = {-                        Text(-                            when {-                                preset == null -> stringResource(R.string.no_repeat)-                                preset == presets[2] -> stringResource(R.string.weekdays)-                                else -> recurrenceLabel(preset)-                            },-                        )+                        Text(if (preset == weekdays) stringResource(R.string.weekdays) else recurrenceLabel(preset))                     },                     trailingContent = if (preset == current) ({ IconCheck() }) else null,                     modifier = Modifier.clickable { onSet(preset) },@@ -80,7 +80,7 @@ fun RecurrenceSheet(current: Recurrence?, onSet: (Recurrence?) -> Unit, onDismis  @OptIn(ExperimentalLayoutApi::class) @Composable-private fun CustomRecurrence(current: Recurrence?, onSet: (Recurrence?) -> Unit) {+private fun CustomRecurrence(current: Recurrence?, onSet: (Recurrence) -> Unit) {     var interval by remember { mutableStateOf((current?.interval ?: 1).toString()) }     var unit by remember {         mutableStateOf(
todo/src/main/java/com/vayunmathur/todo/ui/ReminderSheet.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/ReminderSheet.kt b/todo/src/main/java/com/vayunmathur/todo/ui/ReminderSheet.ktindex 3912bcc45c..b106297f8d 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/ReminderSheet.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/ReminderSheet.kt@@ -1,6 +1,7 @@ package com.vayunmathur.todo.ui  import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue@@ -10,27 +11,34 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.DateString import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.ListItem+import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.ModalBottomSheet import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.rememberIs24Hour import com.vayunmathur.todo.R+import com.vayunmathur.todo.data.Todo import com.vayunmathur.todo.domain.DueDates import com.vayunmathur.todo.domain.Reminders import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone -/** Reminder relative to the due time, or at an exact date and time. */+/**+ * Reminder relative to the due time, or at a chosen moment. A repeating task's reminder keeps+ * its lead for every occurrence, so it only offers a time of day; a one-time task gets a full+ * date and time.+ */ @OptIn(ExperimentalMaterial3Api::class) @Composable-fun ReminderSheet(-    dueAt: Long?,-    allDay: Boolean,-    reminderAt: Long?,-    onSet: (Long?) -> Unit,-    onDismiss: () -> Unit,-) {+fun ReminderSheet(todo: Todo, onSet: (Long?) -> Unit, onDismiss: () -> Unit) {+    val dueAt = todo.dueAt+    val allDay = todo.dueAllDay+    val reminderAt = todo.reminderAt+    val repeating = todo.recurrence != null     val zone = TimeZone.currentSystemDefault()     val requestPermission = rememberNotificationPermissionRequest()     LaunchedEffect(Unit) { requestPermission() }@@ -38,6 +46,11 @@ fun ReminderSheet(     var pickedDate by remember { mutableStateOf<LocalDate?>(null) }      ModalBottomSheet(onDismissRequest = onDismiss) {+        Text(+            stringResource(if (repeating) R.string.remind_each_time else R.string.reminder),+            style = MaterialTheme.typography.titleMedium,+            modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp),+        )         val option: @Composable (String, Long?) -> Unit = { label, value ->             ListItem(                 headlineContent = { Text(label) },@@ -47,14 +60,27 @@ fun ReminderSheet(         }         option(stringResource(R.string.no_reminder), null)         if (dueAt != null) {-            Reminders.Offset.entries.forEach { offset ->-                option(offsetLabel(offset), Reminders.at(dueAt, allDay, offset, zone))+            Reminders.offsetsFor(allDay).forEach { offset ->+                option(offsetLabel(offset, allDay), Reminders.at(dueAt, allDay, offset, zone))             }         }+        val is24 = rememberIs24Hour()         ListItem(-            headlineContent = { Text(stringResource(R.string.pick_date_time)) },-            supportingContent = reminderAt?.let { { Text(dueLabel(it, false, System.currentTimeMillis())) } },-            modifier = Modifier.clickable { pickDate = true },+            headlineContent = { Text(stringResource(if (repeating) R.string.pick_time else R.string.pick_date_time)) },+            supportingContent = reminderAt?.let { at ->+                {+                    Text(+                        if (repeating) DateString.time(DueDates.localTime(at, zone), is24) else dueLabel(at, false, System.currentTimeMillis()),+                    )+                }+            },+            modifier = Modifier.clickable {+                if (repeating) {+                    pickedDate = DueDates.localDate(dueAt ?: System.currentTimeMillis(), zone)+                } else {+                    pickDate = true+                }+            },         )     } @@ -73,9 +99,19 @@ fun ReminderSheet( }  @Composable-private fun offsetLabel(offset: Reminders.Offset): String = when (offset) {-    Reminders.Offset.AT_DUE -> stringResource(R.string.reminder_at_due)-    Reminders.Offset.MINUTES_10 -> pluralStringResource(R.plurals.reminder_minutes_before, 10, 10)-    Reminders.Offset.HOUR_1 -> pluralStringResource(R.plurals.reminder_hours_before, 1, 1)-    Reminders.Offset.DAY_1 -> pluralStringResource(R.plurals.reminder_days_before, 1, 1)+private fun offsetLabel(offset: Reminders.Offset, allDay: Boolean): String {+    if (allDay) {+        val time = DateString.time(Reminders.ALL_DAY_TIME, rememberIs24Hour())+        return if (offset == Reminders.Offset.DAY_1) {+            stringResource(R.string.reminder_day_before_at, time)+        } else {+            stringResource(R.string.reminder_on_the_day, time)+        }+    }+    return when (offset) {+        Reminders.Offset.AT_DUE -> stringResource(R.string.reminder_at_due)+        Reminders.Offset.MINUTES_10 -> pluralStringResource(R.plurals.reminder_minutes_before, 10, 10)+        Reminders.Offset.HOUR_1 -> pluralStringResource(R.plurals.reminder_hours_before, 1, 1)+        Reminders.Offset.DAY_1 -> pluralStringResource(R.plurals.reminder_days_before, 1, 1)+    } }
todo/src/main/java/com/vayunmathur/todo/ui/TodoDetailScreen.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/TodoDetailScreen.kt b/todo/src/main/java/com/vayunmathur/todo/ui/TodoDetailScreen.ktindex 3450b5383f..2d8797f4b1 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/TodoDetailScreen.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/TodoDetailScreen.kt@@ -1,12 +1,15 @@ package com.vayunmathur.todo.ui +import androidx.compose.foundation.border import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue+import androidx.compose.runtime.key import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue@@ -32,10 +35,13 @@ import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconMoreVert import com.vayunmathur.library.ui.IconMove import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OdfMarkdownEditorField+import com.vayunmathur.library.ui.OdfMarkdownEditorToolbar import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextField import com.vayunmathur.library.ui.TextFieldDefaults import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.rememberOdfMarkdownEditorController import com.vayunmathur.library.util.sharedContainer import com.vayunmathur.todo.R import com.vayunmathur.todo.platform.TodoActions@@ -56,11 +62,18 @@ fun TodoDetailScreen(state: TodoUiState, actions: TodoActions) {     var pickList by remember { mutableStateOf(false) }     val titleFocus = remember { FocusRequester() }     LaunchedEffect(state.isNew) { if (state.isNew) titleFocus.requestFocus() }+    val notes = key(todo.syncId) {+        rememberOdfMarkdownEditorController(initialMarkdown = todo.notes) { md -> actions.update { it.copy(notes = md) } }+    }      DetailScaffold(         title = stringResource(R.string.todo_details),         onNavigateBack = { actions.back() },         scrollBehavior = appBarScrollBehavior(),+        bottomBar = {+            // EditorBottomBar claims navigationBars ∪ ime itself; no extra imePadding.+            if (notes.focused) OdfMarkdownEditorToolbar(notes)+        },         actions = {             IconButton(onClick = { showDeleteConfirm = true }) { IconDelete() }             IconButton(onClick = { menu = true }) { IconMoreVert() }@@ -111,10 +124,18 @@ fun TodoDetailScreen(state: TodoUiState, actions: TodoActions) {             )         }         EditorChips(state, actions, Modifier.fillMaxWidth().padding(vertical = 8.dp))-        MarkdownNotes(-            notes = todo.notes,-            onChange = { notes -> actions.update { it.copy(notes = notes) } },-            modifier = Modifier.padding(vertical = 8.dp),+        Text(+            stringResource(R.string.todo_notes),+            style = MaterialTheme.typography.labelMedium,+            color = MaterialTheme.colorScheme.onSurfaceVariant,+            modifier = Modifier.fillMaxWidth().padding(top = 8.dp, bottom = 4.dp),+        )+        OdfMarkdownEditorField(+            controller = notes,+            modifier = Modifier+                .fillMaxWidth()+                .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(8.dp))+                .padding(12.dp),         )         if (!todo.isSubtask) {             SubtaskList(
todo/src/main/res/values/strings.xml
diff --git a/todo/src/main/res/values/strings.xml b/todo/src/main/res/values/strings.xmlindex 4a2aec8e4a..eada2532f7 100644--- a/todo/src/main/res/values/strings.xml+++ b/todo/src/main/res/values/strings.xml@@ -184,18 +184,30 @@         <item quantity="other"><xliff:g id="count" example="7">%d</xliff:g> days after completion</item>     </plurals> +    <!-- Editor toggle: a task done a single time. Adjective. -->+    <string name="kind_once">One-time</string>+    <!-- Editor toggle: a task that comes back on a schedule (daily, weekly, …). Adjective. -->+    <string name="kind_repeating">Repeating</string>+    <!-- Editor section header: due date, repeat and reminder. Noun. -->+    <string name="section_schedule">Schedule</string>+    <!-- Editor section header: list, priority and tags. Verb. -->+    <string name="section_organize">Organize</string>+    <!-- Editor section header: hide-until, estimate and dependencies. Noun, plural. -->+    <string name="section_details">Details</string>     <!-- Editor chip with no due date set. Verb phrase. -->     <string name="add_due_date">Due date</string>+    <!-- Repeating task chip: when it is next due; argument is e.g. "Tomorrow 8:00 AM". -->+    <string name="next_due">Next: <xliff:g id="when" example="Tomorrow">%s</xliff:g></string>+    <!-- Repeating task chip / due sheet title with no next date set. Noun phrase. -->+    <string name="next_occurrence">Next occurrence</string>     <!-- Due sheet: adds a time of day. Verb phrase. -->     <string name="add_time">Add time</string>     <!-- Due sheet: changes the time of day. Verb phrase. -->     <string name="change_time">Change time</string>     <!-- Due sheet: removes the time, making the task all-day. Adjective phrase. -->     <string name="all_day">All day</string>-    <!-- Editor chip with no repeat set. Verb. -->-    <string name="repeat">Repeat</string>-    <!-- Repeat option: one-off task. Verb phrase. -->-    <string name="no_repeat">Doesn\'t repeat</string>+    <!-- Repeat sheet title. Noun phrase. -->+    <string name="repeat_how_often">How often?</string>     <!-- Repeat option: Monday to Friday. Noun. -->     <string name="weekdays">Every weekday</string>     <!-- Repeat option: open the custom repeat editor. Adjective. -->@@ -214,8 +226,23 @@     <string name="from_completion">Count from completion</string>     <!-- Custom repeat: monthly on the last day. Noun phrase. -->     <string name="last_day_of_month">On the last day</string>-    <!-- Editor chip with no reminder set. Noun. -->-    <string name="reminder">Reminder</string>+    <!-- Editor chip with no reminder set / reminder sheet title for one-time tasks. Verb phrase. -->+    <string name="reminder">Remind me</string>+    <!-- Reminder sheet title for repeating tasks: the reminder fires for every occurrence. -->+    <string name="remind_each_time">Remind me each time</string>+    <!-- Repeating task reminder chip, same day as the occurrence; argument is a time. -->+    <string name="remind_at">Remind at <xliff:g id="time" example="8:00 AM">%s</xliff:g></string>+    <!-- Repeating task reminder chip, days before each occurrence; arguments are the count and a time. -->+    <plurals name="remind_days_before_at">+        <item quantity="one">Remind <xliff:g id="count" example="1">%1$d</xliff:g> day before, <xliff:g id="time" example="8:00 AM">%2$s</xliff:g></item>+        <item quantity="other">Remind <xliff:g id="count" example="2">%1$d</xliff:g> days before, <xliff:g id="time" example="8:00 AM">%2$s</xliff:g></item>+    </plurals>+    <!-- Reminder option for an all-day task: on the due day; argument is a time. -->+    <string name="reminder_on_the_day">On the day at <xliff:g id="time" example="9:00 AM">%s</xliff:g></string>+    <!-- Reminder option for an all-day task: the day before; argument is a time. -->+    <string name="reminder_day_before_at">The day before at <xliff:g id="time" example="9:00 AM">%s</xliff:g></string>+    <!-- Reminder option for repeating tasks: choose a time of day. Verb phrase. -->+    <string name="pick_time">Pick a time…</string>     <!-- Reminder option clearing it. Noun phrase. -->     <string name="no_reminder">No reminder</string>     <!-- Reminder option: when the task is due. Noun phrase. -->@@ -246,7 +273,7 @@     <!-- Tag dialog: field placeholder. Verb phrase. -->     <string name="add_tag">Add a tag</string>     <!-- Editor chip with no time estimate. Noun. -->-    <string name="estimate">Estimate</string>+    <string name="estimate">Time estimate</string>     <!-- Estimate value in minutes. -->     <plurals name="estimate_minutes">         <item quantity="one"><xliff:g id="count" example="1">%d</xliff:g> min</item>@@ -254,14 +281,14 @@     </plurals>     <!-- Estimate option clearing it. Noun phrase. -->     <string name="no_estimate">No estimate</string>-    <!-- Editor chip with no start date. Noun. -->-    <string name="start_date">Start date</string>+    <!-- Editor chip with no start date: keep the task out of Today/Upcoming until a date. Verb phrase. -->+    <string name="start_date">Hide until</string>     <!-- Editor chip with a start date; argument is the date. -->-    <string name="starts_on">Starts <xliff:g id="date" example="Mar 9">%s</xliff:g></string>-    <!-- Start date option clearing it. Noun phrase. -->-    <string name="no_start_date">No start date</string>-    <!-- Editor chip / dialog title for task dependencies. Adjective phrase. -->-    <string name="blocked_by">Blocked by</string>+    <string name="starts_on">Hidden until <xliff:g id="date" example="Mar 9">%s</xliff:g></string>+    <!-- Start date option clearing it. Verb phrase. -->+    <string name="no_start_date">Show it now</string>+    <!-- Editor chip / dialog title for task dependencies. Verb phrase. -->+    <string name="blocked_by">Waiting on…</string>     <!-- Editor chip with dependencies set. -->     <plurals name="waiting_on">         <item quantity="one">Waiting on <xliff:g id="count" example="1">%d</xliff:g> task</item>
todo/src/test/java/com/vayunmathur/todo/domain/RecurrenceTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/domain/RecurrenceTest.kt b/todo/src/test/java/com/vayunmathur/todo/domain/RecurrenceTest.ktindex a0ecdc7641..4aad9cd707 100644--- a/todo/src/test/java/com/vayunmathur/todo/domain/RecurrenceTest.kt+++ b/todo/src/test/java/com/vayunmathur/todo/domain/RecurrenceTest.kt@@ -96,4 +96,16 @@ class RecurrenceTest {         assertNull(Recurrence.parse("FREQ=HOURLY"))         assertEquals(Recurrence.Daily(1), Recurrence.parse("RRULE:FREQ=DAILY;INTERVAL=0"))     }++    @Test+    fun `first occurrence is today when the schedule allows, else the next matching day`() {+        // 2026-03-04 is a Wednesday.+        val today = d(2026, 3, 4)+        assertEquals(today, Recurrence.Daily().firstOnOrAfter(today))+        assertEquals(today, Recurrence.Weekly().firstOnOrAfter(today))+        assertEquals(d(2026, 3, 6), Recurrence.Weekly(1, setOf(DayOfWeek.FRIDAY)).firstOnOrAfter(today))+        assertEquals(d(2026, 3, 15), Recurrence.Monthly(1, 15).firstOnOrAfter(today))+        assertEquals(d(2026, 3, 31), Recurrence.Monthly(1, Recurrence.LAST_DAY).firstOnOrAfter(today))+        assertEquals(d(2026, 3, 31), Recurrence.Monthly(1, Recurrence.LAST_DAY).firstOnOrAfter(d(2026, 3, 31)))+    } }
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 ad7b351497..c4870445a5 100644--- a/todo/src/test/java/com/vayunmathur/todo/domain/RemindersTest.kt+++ b/todo/src/test/java/com/vayunmathur/todo/domain/RemindersTest.kt@@ -3,8 +3,10 @@ package com.vayunmathur.todo.domain import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalTime import kotlinx.datetime.TimeZone+import com.vayunmathur.todo.data.Todo import kotlin.test.Test import kotlin.test.assertEquals+import kotlin.test.assertNull  class RemindersTest {     private val zone = TimeZone.of("Europe/Berlin")@@ -25,4 +27,46 @@ class RemindersTest {         assertEquals(at(10, 8), Reminders.at(due, true, Reminders.Offset.HOUR_1, zone))         assertEquals(at(9, 9), Reminders.at(due, true, Reminders.Offset.DAY_1, zone))     }++    @Test+    fun `all-day tasks only offer day-level offsets`() {+        assertEquals(listOf(Reminders.Offset.AT_DUE, Reminders.Offset.DAY_1), Reminders.offsetsFor(allDay = true))+        assertEquals(Reminders.Offset.entries, Reminders.offsetsFor(allDay = false))+    }++    @Test+    fun `a future reminder fires as set`() {+        val todo = Todo(dueAt = at(10, 15), dueAllDay = false, reminderAt = at(10, 14))+        assertEquals(at(10, 14), Reminders.nextFire(todo, now = at(10, 8), zone = zone))+    }++    @Test+    fun `a past one-time reminder never fires again`() {+        val todo = Todo(dueAt = at(10, 15), dueAllDay = false, reminderAt = at(10, 14))+        assertNull(Reminders.nextFire(todo, now = at(10, 16), zone = zone))+    }++    @Test+    fun `an unchecked daily task still reminds at the next occurrence`() {+        val todo = Todo(dueAt = at(10, 8), dueAllDay = false, reminderAt = at(10, 7, 50), recurrence = "FREQ=DAILY")+        assertEquals(at(11, 7, 50), Reminders.nextFire(todo, now = at(10, 12), zone = zone))+        // Days overdue: picks up at the next upcoming occurrence, not a missed one.+        assertEquals(at(15, 7, 50), Reminders.nextFire(todo, now = at(15, 7), zone = zone))+        assertEquals(at(16, 7, 50), Reminders.nextFire(todo, now = at(15, 9), zone = zone))+    }++    @Test+    fun `weekly reminders keep their day-before lead`() {+        // 2026-03-10 is a Tuesday; remind Monday at 9.+        val due = DueDates.startOfDay(LocalDate(2026, 3, 10), zone)+        val todo = Todo(dueAt = due, dueAllDay = true, reminderAt = at(9, 9), recurrence = "FREQ=WEEKLY")+        assertEquals(at(16, 9), Reminders.nextFire(todo, now = at(9, 10), zone = zone))+    }++    @Test+    fun `done and after-completion tasks have no next reminder`() {+        val base = Todo(dueAt = at(10, 8), dueAllDay = false, reminderAt = at(10, 8), recurrence = "FREQ=DAILY")+        assertNull(Reminders.nextFire(base.copy(done = true), now = at(9, 0), zone = zone))+        assertNull(Reminders.nextFire(base.copy(recurrence = "FREQ=DAILY;X-FROM=COMPLETION"), now = at(10, 9), zone = zone))+    } }