Apply the default reminder to a start-only task (#178)
A default whose date the task lacks now counts from the date it has, when no default counts from that one.
This commit is contained in:
1 parent
8cdf3ad709
commit
8e124fdb0e
8 files changed
+96
-14
No files matched your search
@@ -59,6 +59,12 @@ All notable changes to this project are documented here. The format follows
|
||||
all-day reminder time. With a tasks app as the store, both ends gain or
|
||||
drop their time together (#101).
|
||||
|
||||
### Fixed
|
||||
- A task with only a start date gets the default reminder too, counted from
|
||||
its start, when none of the default reminders is set from the start. Likewise
|
||||
a task with only a due date gets reminders set from the start, counted from
|
||||
its due date (#178).
|
||||
|
||||
## [1.3.2] - 2026-11-13
|
||||
|
||||
### Added
|
||||
|
||||
@@ -27,6 +27,7 @@ import de.jeanlucmakiola.agendula.domain.TaskGrouping
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSection
|
||||
import de.jeanlucmakiola.agendula.domain.groupingKey
|
||||
import de.jeanlucmakiola.agendula.domain.asTaskReminder
|
||||
import de.jeanlucmakiola.agendula.domain.forDates
|
||||
import de.jeanlucmakiola.agendula.domain.asReminderLead
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
@@ -207,6 +208,10 @@ data class Settings(
|
||||
fun defaultRemindersFor(listId: Long, allDay: Boolean): List<TaskReminder> =
|
||||
(if (allDay) allDayReminderLeadsFor(listId) else reminderLeadsFor(listId)).map { it.asTaskReminder() }
|
||||
|
||||
/** [defaultRemindersFor] a task with [hasStart] and [hasDue] — see [forDates]. */
|
||||
fun defaultRemindersFor(listId: Long, allDay: Boolean, hasStart: Boolean, hasDue: Boolean): List<TaskReminder> =
|
||||
defaultRemindersFor(listId, allDay).forDates(hasStart, hasDue)
|
||||
|
||||
/** Whether [listId] has its own default reminders for [allDay] tasks (an override, "none" included). */
|
||||
fun hasOwnReminders(listId: Long, allDay: Boolean): Boolean =
|
||||
listId in (if (allDay) perListAllDayReminderOverride else perListReminderOverride)
|
||||
|
||||
@@ -85,8 +85,9 @@ internal object ReminderPlanner {
|
||||
// ⚠️ Present-but-empty is "none", not "the default": the store's
|
||||
// answer for a task whose alarms another client turned off. A
|
||||
// default here would keep ringing for what the user switched off.
|
||||
// A default counts only from a date the task has; its own reminders
|
||||
// stand in each date for the other when the task lacks it.
|
||||
// A default counts from a date the task has, or from its one date when
|
||||
// no default does (#178); its own reminders stand in each date for the
|
||||
// other when the task lacks it.
|
||||
val reminders = own ?: defaultsFor(task, settings)
|
||||
val created = task.created?.toEpochMilliseconds()
|
||||
val dates = task.dates
|
||||
@@ -125,8 +126,7 @@ internal object ReminderPlanner {
|
||||
|
||||
/** The list's or the app's default reminders for [task], of the dates it has. */
|
||||
private fun defaultsFor(task: Task, settings: Settings): List<TaskReminder> =
|
||||
settings.defaultRemindersFor(task.listId, task.isAllDay)
|
||||
.filter { (if (it.fromStart) task.start else task.due) != null }
|
||||
settings.defaultRemindersFor(task.listId, task.isAllDay, task.start != null, task.due != null)
|
||||
|
||||
/**
|
||||
* [task]'s reminders once saved: its [own], with defaults older than the
|
||||
|
||||
@@ -8,6 +8,7 @@ import de.jeanlucmakiola.agendula.domain.TaskEnd
|
||||
import de.jeanlucmakiola.agendula.domain.TaskForm
|
||||
import de.jeanlucmakiola.agendula.domain.TaskReminder
|
||||
import de.jeanlucmakiola.agendula.domain.calendarDate
|
||||
import de.jeanlucmakiola.agendula.domain.forDates
|
||||
import java.time.ZoneId
|
||||
import kotlin.time.Instant
|
||||
|
||||
@@ -132,7 +133,7 @@ internal object StoredReminders {
|
||||
if (fresh.isEmpty()) return wanted
|
||||
val defaults = defaultsFor(form, settings, now, zone, keepPast)
|
||||
if (anchorsOf(start, due).isEmpty() || wanted.isEmpty()) return wanted.ifEmpty { defaults }
|
||||
val named = wanted.map { it.fromStart }.toSet()
|
||||
val named = namedEnds(form, wanted)
|
||||
return wanted + defaults.filter { it.fromStart in fresh && it.fromStart !in named }
|
||||
}
|
||||
|
||||
@@ -175,7 +176,9 @@ internal object StoredReminders {
|
||||
|
||||
/** What [switched] keeps of [reminders], or null when it swaps in the new kind's defaults. */
|
||||
fun keptAcrossSwitch(reminders: List<TaskReminder>, form: TaskForm, settings: Settings): List<TaskReminder>? {
|
||||
if (reminders.toSet() == settings.defaultRemindersFor(form.listId, !form.isAllDay).toSet()) return null
|
||||
val oldDefaults = settings.defaultRemindersFor(form.listId, !form.isAllDay)
|
||||
val ofItsDates = oldDefaults.forDates(form.start != null, form.due != null)
|
||||
if (reminders.toSet().let { it == oldDefaults.toSet() || it == ofItsDates.toSet() }) return null
|
||||
val kept = if (form.isAllDay) {
|
||||
reminders.map { it.inWholeDays() }
|
||||
} else {
|
||||
@@ -200,8 +203,8 @@ internal object StoredReminders {
|
||||
zone: ZoneId,
|
||||
): Set<Boolean> {
|
||||
if (form.rrule != null || wanted.isEmpty()) return emptySet()
|
||||
val named = wanted.map { it.fromStart }.toSet()
|
||||
val defaults = settings.defaultRemindersFor(form.listId, was.isAllDay)
|
||||
val named = namedEnds(form, wanted)
|
||||
val defaults = settings.defaultRemindersFor(form.listId, was.isAllDay, was.start != null, was.due != null)
|
||||
fun revived(fromStart: Boolean, before: Instant?, isNow: Instant?): Boolean {
|
||||
if (before == null || isNow == null || fromStart in named) return false
|
||||
val moved = if (was.isAllDay == form.isAllDay) {
|
||||
@@ -224,8 +227,14 @@ internal object StoredReminders {
|
||||
private fun anchorsOf(start: Any?, due: Any?): Set<Boolean> =
|
||||
setOfNotNull(true.takeIf { start != null }, false.takeIf { due != null })
|
||||
|
||||
/** The dates [wanted] count from on [form], as [TaskReminder.fromStart]. */
|
||||
private fun namedEnds(form: TaskForm, wanted: List<TaskReminder>): Set<Boolean> {
|
||||
val dates = TaskDates(form.start, form.due, form.isAllDay)
|
||||
return wanted.map { dates.reminderEnd(it.fromStart) == TaskEnd.START }.toSet()
|
||||
}
|
||||
|
||||
/**
|
||||
* The defaults [form] takes: those counting from a date it has. A one-off
|
||||
* The defaults [form] takes, of the dates it has (see [forDates]). A one-off
|
||||
* task leaves out what is already past — a start of "now" would ring at once.
|
||||
*/
|
||||
private fun defaultsFor(
|
||||
@@ -235,8 +244,7 @@ internal object StoredReminders {
|
||||
zone: ZoneId,
|
||||
keepPast: Boolean = false,
|
||||
): List<TaskReminder> =
|
||||
settings.defaultRemindersFor(form.listId, form.isAllDay).filter { reminder ->
|
||||
if ((if (reminder.fromStart) form.start else form.due) == null) return@filter false
|
||||
settings.defaultRemindersFor(form.listId, form.isAllDay, form.start != null, form.due != null).filter { reminder ->
|
||||
form.rrule != null || keepPast || ReminderPlanner.ringsAt(
|
||||
TaskDates(form.start, form.due, form.isAllDay, form.untimed),
|
||||
reminder.fromStart,
|
||||
|
||||
@@ -78,6 +78,17 @@ fun taskReminderDisplayOrder(allDay: Boolean, allDayMinuteOfDay: Int): Comparato
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* The default reminders of these that a task with [hasStart] and [hasDue] takes:
|
||||
* those counting from a date it has, or, when none does, all of them counting
|
||||
* from the one date it has (#178).
|
||||
*/
|
||||
fun List<TaskReminder>.forDates(hasStart: Boolean, hasDue: Boolean): List<TaskReminder> {
|
||||
val ofItsDates = filter { if (it.fromStart) hasStart else hasDue }
|
||||
if (ofItsDates.isNotEmpty() || hasStart == hasDue) return ofItsDates
|
||||
return map { it.copy(fromStart = hasStart) }.distinct()
|
||||
}
|
||||
|
||||
/** A default reminder's lead as a reminder of the task's own. */
|
||||
fun ReminderLead.asTaskReminder(): TaskReminder = TaskReminder(minutes, fromStart)
|
||||
|
||||
|
||||
@@ -413,4 +413,20 @@ class ReminderPlannerTest {
|
||||
assertThat(ReminderPlanner.triggers(task, null, settings, berlin, sinceCreated = false))
|
||||
.containsExactly(ScheduledReminder(4, due.toEpochMilliseconds() - 3_600_000L))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a task with only one date takes the defaults of the other from it (#178)`() {
|
||||
val start = Instant.fromEpochMilliseconds(millis(date.atTime(9, 0), berlin))
|
||||
val due = Instant.fromEpochMilliseconds(millis(date.atTime(18, 0), berlin))
|
||||
val startOnly = testTask(id = 11, start = start)
|
||||
val dueOnly = testTask(id = 12, due = due)
|
||||
val now = millis(date.atTime(0, 0), berlin)
|
||||
|
||||
assertThat(ReminderPlanner.plan(listOf(startOnly), emptyMap(), Settings(defaultReminders = listOf(15).asReminderLeads()), now, berlin))
|
||||
.containsExactly(ScheduledReminder(11, millis(date.atTime(8, 45), berlin)))
|
||||
val fromStart = Settings(defaultReminders = listOf(TaskReminder(60, fromStart = true).asReminderLead()))
|
||||
assertThat(ReminderPlanner.plan(listOf(dueOnly), emptyMap(), fromStart, now, berlin))
|
||||
.containsExactly(ScheduledReminder(12, millis(date.atTime(17, 0), berlin)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,4 +280,39 @@ class StoredRemindersTest {
|
||||
assertThat(switched(listOf(ownTime, TaskReminder(2_880)), form)).containsExactly(TaskReminder(2_880))
|
||||
assertThat(switched(listOf(ownTime), form)).containsExactly(dayBeforeDue, hourBeforeDue)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a task with only a start takes the due defaults from its start (#178)`() {
|
||||
val dueDefault = Settings()
|
||||
val startOnly = TaskForm(title = "t", listId = 1, start = now + 2.hours)
|
||||
assertThat(stored(startOnly, with = dueDefault)).containsExactly(TaskReminder(0, fromStart = true))
|
||||
assertThat(stored(startOnly, testTask(), with = dueDefault)).containsExactly(TaskReminder(0, fromStart = true))
|
||||
val startDefault = Settings(defaultReminders = listOf(TaskReminder(30, fromStart = true).asReminderLead()))
|
||||
val dueOnly = TaskForm(title = "t", listId = 1, due = now + 2.hours)
|
||||
assertThat(stored(dueOnly, with = startDefault)).containsExactly(TaskReminder(30))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a start of now takes no due default from it (#178)`() {
|
||||
val form = TaskForm(title = "t", listId = 1, start = now - 2.hours, startsNow = true)
|
||||
assertThat(stored(form, with = Settings())).isEmpty()
|
||||
assertThat(StoredReminders.pastDefaults(form, null, Settings(), now.toEpochMilliseconds(), zone)).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a due swapped for a start keeps the reminder that now counts from it`() {
|
||||
val current = testTask(due = now + 5.days)
|
||||
val form = TaskForm(title = "t", listId = 1, start = now + 2.days, reminders = listOf(TaskReminder(0)))
|
||||
assertThat(stored(form, current, with = Settings())).containsExactly(TaskReminder(0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a start-only default swaps when the task turns all-day`() {
|
||||
val legacy = Settings(defaultReminders = listOf(15).asReminderLeads(), defaultAllDayReminders = listOf(1_440).asReminderLeads())
|
||||
val start = allDayInstantOf(LocalDate.of(2026, 10, 3))
|
||||
val form = TaskForm(title = "t", listId = 1, start = start, isAllDay = true)
|
||||
assertThat(switched(listOf(TaskReminder(15, fromStart = true)), form, legacy))
|
||||
.containsExactly(TaskReminder(1_440, fromStart = true))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ class ListDefaultsHintTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the #121 case - only At due, a start-only task - says the list added none`() {
|
||||
fun `the #121 case - only At due, a start-only task - takes it from the start (#178)`() {
|
||||
val (reminders, hint) = hintForNew(TaskForm(title = "t", listId = 1, start = now + 2.days))
|
||||
assertThat(reminders).isEmpty()
|
||||
assertThat(hint).isEqualTo(ListDefaultsHint("Prywatny", none = true))
|
||||
assertThat(reminders).containsExactly(TaskReminder(0, fromStart = true))
|
||||
assertThat(hint).isEqualTo(ListDefaultsHint("Prywatny", none = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,5 +89,6 @@ class ListDefaultsHintTest {
|
||||
val timedDefaults = settings.defaultRemindersFor(2, allDay = false)
|
||||
assertThat(StoredReminders.keptAcrossSwitch(timedDefaults, form, settings)).isNull()
|
||||
assertThat(StoredReminders.keptAcrossSwitch(listOf(TaskReminder(1_440)), form, settings)).isNotNull()
|
||||
assertThat(StoredReminders.keptAcrossSwitch(listOf(atDue), form, settings)).isNull()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user