diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt b/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt index 1261482..fd94dc3 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt @@ -316,8 +316,21 @@ class TaskEditViewModel @Inject constructor( } } - fun onStartChange(value: Instant?) = update { it.copy(start = value).withDefaultReminders() } - fun onDueChange(value: Instant?) = update { it.copy(due = value).withDefaultReminders() } + fun onStartChange(value: Instant?) = update { + it.copy(start = value).withDefaultReminders().withoutDatelessReminders() + } + fun onDueChange(value: Instant?) = update { + it.copy(due = value).withDefaultReminders().withoutDatelessReminders() + } + + /** A task left without dates has nothing for its reminders to count from, so they go with the last one (#159). */ + private fun TaskEditUiState.withoutDatelessReminders(): TaskEditUiState = + if (start != null || due != null || reminders.isEmpty()) { + this + } else { + copy(reminders = emptyList(), remindersChosen = true) + } + /** * All-day and timed values use different conventions (UTC midnight vs. a real * instant in the device zone), so the switch has to move the timestamps too —