Let a default start follow the due, use the views' own matchers (#107)
Subtasks take no default due, and the change is noted in the changelog.
This commit is contained in:
1 parent
8fa15c282f
commit
82f087a73c
13 files changed
+193
-82
No files matched your search
@@ -7,6 +7,12 @@ All notable changes to this project are documented here. The format follows
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Default due and start dates for new tasks, under Settings → New task form. A new
|
||||
task can be due today, tomorrow, the day after, in a week or in a month, and
|
||||
start today, on its due date, or a day or a week before it. The old "Default
|
||||
start to today" switch carries over (#107).
|
||||
|
||||
## [1.3.2] - 2026-11-13
|
||||
|
||||
### Added
|
||||
|
||||
@@ -27,6 +27,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import de.jeanlucmakiola.agendula.data.di.LaunchHook
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.smartListNamed
|
||||
import de.jeanlucmakiola.agendula.ui.imports.importIntentUri
|
||||
import de.jeanlucmakiola.agendula.ui.navigation.AppShortcuts
|
||||
import de.jeanlucmakiola.agendula.ui.RootScreen
|
||||
@@ -252,15 +253,13 @@ class MainActivity : ComponentActivity() {
|
||||
ACTION_NEW_TASK -> return NavRequest.NewTask(
|
||||
listId = intent.getLongExtra(EXTRA_PRESET_LIST_ID, -1L).takeIf { it > 0L },
|
||||
filterId = intent.getLongExtra(EXTRA_FILTER_ID, -1L).takeIf { it > 0L },
|
||||
smartList = intent.getStringExtra(EXTRA_SMART_LIST)
|
||||
?.let { name -> SmartList.entries.firstOrNull { it.name == name } }
|
||||
// Widgets placed before 1.4 still carry the old flag.
|
||||
// Widgets placed before 1.4 still carry the old flag.
|
||||
smartList = smartListNamed(intent.getStringExtra(EXTRA_SMART_LIST))
|
||||
?: SmartList.TODAY.takeIf { intent.getBooleanExtra(EXTRA_DUE_TODAY, false) },
|
||||
returnHome = true,
|
||||
)
|
||||
ACTION_TODAY -> return NavRequest.OpenSmart(SmartList.TODAY)
|
||||
ACTION_OPEN_SMART -> intent.getStringExtra(EXTRA_SMART_LIST)
|
||||
?.let { name -> SmartList.entries.firstOrNull { it.name == name } }
|
||||
ACTION_OPEN_SMART -> smartListNamed(intent.getStringExtra(EXTRA_SMART_LIST))
|
||||
?.let { return NavRequest.OpenSmart(it) }
|
||||
ACTION_OPEN_LIST -> intent.getLongExtra(EXTRA_LIST_ID, -1L).takeIf { it > 0L }
|
||||
?.let { return NavRequest.OpenList(it) }
|
||||
|
||||
@@ -14,9 +14,7 @@ import de.jeanlucmakiola.agendula.domain.DefaultDueDate
|
||||
import de.jeanlucmakiola.agendula.domain.DefaultStartDate
|
||||
import de.jeanlucmakiola.agendula.domain.NewTaskDates
|
||||
import de.jeanlucmakiola.agendula.domain.SavedFilter
|
||||
import de.jeanlucmakiola.agendula.domain.DueWindow
|
||||
import de.jeanlucmakiola.agendula.domain.newTaskDates
|
||||
import de.jeanlucmakiola.agendula.domain.newTaskDue
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
import de.jeanlucmakiola.agendula.domain.TaskForm
|
||||
@@ -34,7 +32,6 @@ import de.jeanlucmakiola.floret.reminders.normalizeReminders
|
||||
import de.jeanlucmakiola.floret.reminders.reminderLeadsFor
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.first
|
||||
import java.time.DayOfWeek
|
||||
import java.time.LocalDate
|
||||
import kotlin.time.Clock
|
||||
@@ -160,14 +157,38 @@ data class Settings(
|
||||
fun hasOwnReminders(listId: Long, allDay: Boolean): Boolean =
|
||||
listId in (if (allDay) perListAllDayReminderOverride else perListReminderOverride)
|
||||
|
||||
/** The dates a new task starts with, added to a view of [viewWindows] that would show it due on [presetDue]. */
|
||||
/**
|
||||
* The dates a new task starts with, given the [presetDue] of the view it is
|
||||
* added from and whether that view would [show] it. A subtask takes no
|
||||
* default due, which could land after its parent's.
|
||||
*/
|
||||
fun defaultNewTaskDates(
|
||||
today: LocalDate,
|
||||
now: Instant,
|
||||
presetDue: LocalDate? = null,
|
||||
viewWindows: Set<DueWindow> = emptySet(),
|
||||
subtask: Boolean = false,
|
||||
show: (NewTaskDates) -> Boolean = { true },
|
||||
): NewTaskDates =
|
||||
newTaskDates(newTaskDue(defaultDueDate, presetDue, viewWindows, today), defaultStartDate, today, now)
|
||||
newTaskDates(if (subtask) DefaultDueDate.NONE else defaultDueDate, defaultStartDate, presetDue, today, now, show)
|
||||
|
||||
/** A title-only task for [listId], optionally under [parentId], with the default dates. */
|
||||
fun quickTask(
|
||||
title: String,
|
||||
listId: Long,
|
||||
parentId: Long? = null,
|
||||
today: LocalDate = LocalDate.now(),
|
||||
now: Instant = Clock.System.now(),
|
||||
): TaskForm {
|
||||
val dates = defaultNewTaskDates(today, now, subtask = parentId != null)
|
||||
return TaskForm(
|
||||
title = title,
|
||||
listId = listId,
|
||||
parentId = parentId,
|
||||
start = dates.start,
|
||||
due = dates.due,
|
||||
isAllDay = dates.isAllDay,
|
||||
)
|
||||
}
|
||||
|
||||
/** Whether [listId] has its own default reminders for timed or all-day tasks. */
|
||||
fun hasOwnReminders(listId: Long): Boolean =
|
||||
@@ -236,19 +257,6 @@ class SettingsPrefs @Inject constructor(
|
||||
p[COLLAPSED_SECTIONS] = if (collapsed) current + section.name else current - section.name
|
||||
}
|
||||
|
||||
/** A title-only task for [listId], optionally under [parentId], with the default dates. */
|
||||
suspend fun quickTask(title: String, listId: Long, parentId: Long? = null): TaskForm {
|
||||
val dates = settings.first().defaultNewTaskDates(LocalDate.now(), Clock.System.now())
|
||||
return TaskForm(
|
||||
title = title,
|
||||
listId = listId,
|
||||
parentId = parentId,
|
||||
start = dates.start,
|
||||
due = dates.due,
|
||||
isAllDay = dates.isAllDay,
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun setSortOrder(order: TaskSortOrder) = dataStore.edit { it[SORT_ORDER] = order.name }
|
||||
|
||||
suspend fun setSnoozeMinutes(minutes: Int) = dataStore.edit { it[SNOOZE_MINUTES] = minutes.coerceAtLeast(1) }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.jeanlucmakiola.agendula.domain
|
||||
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import kotlin.time.Instant
|
||||
|
||||
/** The due date a new task starts with, counted from the day it is created. */
|
||||
@@ -22,14 +23,16 @@ enum class DefaultStartDate {
|
||||
NONE, TODAY, DUE_DATE, DAY_BEFORE_DUE, WEEK_BEFORE_DUE;
|
||||
|
||||
val needsDue: Boolean get() = this != NONE && this != TODAY
|
||||
}
|
||||
|
||||
/**
|
||||
* A new task's due date: the default where a view of [viewWindows] still shows
|
||||
* the task, else the [presetDue] that keeps it there.
|
||||
*/
|
||||
fun newTaskDue(default: DefaultDueDate, presetDue: LocalDate?, viewWindows: Set<DueWindow>, today: LocalDate): LocalDate? =
|
||||
default.dateFrom(today)?.takeIf { viewWindows.admitsDue(it, today) } ?: presetDue
|
||||
/** The start for a task due on [due], kept between [today] and [due]. */
|
||||
fun dateFor(due: LocalDate, today: LocalDate): LocalDate? = when (this) {
|
||||
NONE -> null
|
||||
TODAY -> today
|
||||
DUE_DATE -> due
|
||||
DAY_BEFORE_DUE -> due.minusDays(1)
|
||||
WEEK_BEFORE_DUE -> due.minusWeeks(1)
|
||||
}?.let { minOf(maxOf(it, today), due) }
|
||||
}
|
||||
|
||||
/** A new task's dates; whole-day defaults make it all-day once it has a due date. */
|
||||
data class NewTaskDates(val start: Instant?, val due: Instant?, val isAllDay: Boolean)
|
||||
@@ -37,18 +40,55 @@ data class NewTaskDates(val start: Instant?, val due: Instant?, val isAllDay: Bo
|
||||
/**
|
||||
* The dates a new task opens with, given its [dueDate] (a preset or the default)
|
||||
* and the default [start]. Without a due date only [DefaultStartDate.TODAY]
|
||||
* applies, as a timed start at [now]. A start stays between today and the due date.
|
||||
* applies, as a timed start at [now].
|
||||
*/
|
||||
fun newTaskDates(dueDate: LocalDate?, start: DefaultStartDate, today: LocalDate, now: Instant): NewTaskDates {
|
||||
if (dueDate == null) {
|
||||
return NewTaskDates(start = now.takeIf { start == DefaultStartDate.TODAY }, due = null, isAllDay = false)
|
||||
}
|
||||
val startDate = when (start) {
|
||||
DefaultStartDate.NONE -> null
|
||||
DefaultStartDate.TODAY -> today
|
||||
DefaultStartDate.DUE_DATE -> dueDate
|
||||
DefaultStartDate.DAY_BEFORE_DUE -> dueDate.minusDays(1)
|
||||
DefaultStartDate.WEEK_BEFORE_DUE -> dueDate.minusWeeks(1)
|
||||
}?.let { minOf(maxOf(it, today), dueDate) }
|
||||
val startDate = start.dateFor(dueDate, today)
|
||||
return NewTaskDates(start = startDate?.let(::allDayInstantOf), due = allDayInstantOf(dueDate), isAllDay = true)
|
||||
}
|
||||
|
||||
/**
|
||||
* A new task's dates from the [due] and [start] defaults, or from [presetDue]
|
||||
* when there is no default due or the view the task is added from would not
|
||||
* [show] it with the default one.
|
||||
*/
|
||||
fun newTaskDates(
|
||||
due: DefaultDueDate,
|
||||
start: DefaultStartDate,
|
||||
presetDue: LocalDate?,
|
||||
today: LocalDate,
|
||||
now: Instant,
|
||||
show: (NewTaskDates) -> Boolean = { true },
|
||||
): NewTaskDates {
|
||||
val preset = newTaskDates(presetDue, start, today, now)
|
||||
val dueDate = due.dateFrom(today) ?: return preset
|
||||
return newTaskDates(dueDate, start, today, now).takeIf(show) ?: preset
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an open task with these dates shows in [smartList], or passes
|
||||
* [savedFilter]'s due windows; with neither it shows anywhere.
|
||||
*/
|
||||
fun NewTaskDates.showsIn(
|
||||
smartList: SmartList?,
|
||||
savedFilter: SavedFilter?,
|
||||
todayStart: Instant,
|
||||
todayEnd: Instant,
|
||||
zone: ZoneId = ZoneId.systemDefault(),
|
||||
): Boolean {
|
||||
val probe = Task(
|
||||
taskId = 0L, listId = 0L, title = "", description = null, location = null, url = null,
|
||||
priority = Priority.NONE, status = TaskStatus.NEEDS_ACTION, percentComplete = null,
|
||||
start = start, due = due, isAllDay = isAllDay, timeZone = null, completedAt = null,
|
||||
listColor = 0, taskColor = null, listName = null, accountName = null, parentId = null,
|
||||
isRecurring = false, distanceFromCurrent = null, created = null, lastModified = null,
|
||||
)
|
||||
return when {
|
||||
savedFilter != null -> savedFilter.due.isEmpty() || dueWindowOf(probe, todayStart, todayEnd, zone) in savedFilter.due
|
||||
smartList != null -> TaskFiltering.matches(probe, TaskFilter.Smart(smartList), todayStart, todayEnd)
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
@@ -68,17 +68,6 @@ fun dueWindowOf(
|
||||
}
|
||||
}
|
||||
|
||||
/** The window a task due on [date] falls in, seen on [today]. */
|
||||
fun dueWindowOf(date: LocalDate, today: LocalDate): DueWindow = when {
|
||||
date < today -> DueWindow.OVERDUE
|
||||
date == today -> DueWindow.TODAY
|
||||
else -> DueWindow.UPCOMING
|
||||
}
|
||||
|
||||
/** Whether a task due on [date] shows in a view of these windows; none admits any date. */
|
||||
fun Set<DueWindow>.admitsDue(date: LocalDate, today: LocalDate): Boolean =
|
||||
isEmpty() || dueWindowOf(date, today) in this
|
||||
|
||||
/**
|
||||
* The due date that keeps a new task in a view of these windows: today, then
|
||||
* tomorrow; a view that admits undated tasks, or only overdue ones, leaves it empty.
|
||||
|
||||
@@ -10,6 +10,9 @@ import kotlin.time.Instant
|
||||
*/
|
||||
enum class SmartList { ALL, TODAY, UPCOMING, OVERDUE, NO_DATE, COMPLETED }
|
||||
|
||||
/** The smart list called [name]; null for none or an unknown one. */
|
||||
fun smartListNamed(name: String?): SmartList? = SmartList.entries.firstOrNull { it.name == name }
|
||||
|
||||
/** What a task screen is showing: one real list, a smart list, or a tag. */
|
||||
sealed interface TaskFilter {
|
||||
data class OfList(val listId: Long) : TaskFilter
|
||||
|
||||
@@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
@@ -97,6 +98,8 @@ class TaskDetailViewModel @Inject constructor(
|
||||
fun addSubtask(title: String) = viewModelScope.launch {
|
||||
val parent = (state.value as? TaskDetailUiState.Content)?.detail?.task ?: return@launch
|
||||
if (title.isBlank()) return@launch
|
||||
runCatching { repository.createTask(settingsPrefs.quickTask(title.trim(), parent.listId, parent.taskId)) }
|
||||
runCatching {
|
||||
repository.createTask(settingsPrefs.settings.first().quickTask(title.trim(), parent.listId, parent.taskId))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,12 @@ import java.time.ZoneId
|
||||
import de.jeanlucmakiola.agendula.domain.populatedFields
|
||||
import de.jeanlucmakiola.agendula.domain.htmlToPlainText
|
||||
import de.jeanlucmakiola.agendula.domain.looksLikeHtml
|
||||
import de.jeanlucmakiola.agendula.domain.DefaultStartDate
|
||||
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
|
||||
import de.jeanlucmakiola.agendula.domain.calendarDate
|
||||
import de.jeanlucmakiola.agendula.domain.dueWindows
|
||||
import de.jeanlucmakiola.agendula.domain.showsIn
|
||||
import de.jeanlucmakiola.floret.time.DayWindow
|
||||
import de.jeanlucmakiola.agendula.domain.presetDue
|
||||
import de.jeanlucmakiola.agendula.domain.newTaskPreset
|
||||
import de.jeanlucmakiola.agendula.domain.normalizeTags
|
||||
@@ -137,6 +142,9 @@ class TaskEditViewModel @Inject constructor(
|
||||
/** Sections shown by default (a setting); the rest unfold via [revealField]. */
|
||||
private var defaultFields: Set<TaskFormField> = emptySet()
|
||||
|
||||
/** The default start a new task took, kept counted from its due until the start is picked. */
|
||||
private var startFollowsDue: DefaultStartDate? = null
|
||||
|
||||
/** The settings as the form was bound, for the defaults an all-day switch swaps in. */
|
||||
private var settings: Settings = Settings()
|
||||
|
||||
@@ -184,8 +192,13 @@ class TaskEditViewModel @Inject constructor(
|
||||
val today = LocalDate.now()
|
||||
val filter = presetFilterId?.let { settingsPrefs.savedFilter(it).first() }
|
||||
val preset = filter?.newTaskPreset(today)
|
||||
val viewWindows = filter?.due ?: presetSmartList?.dueWindows.orEmpty()
|
||||
val dates = settings.defaultNewTaskDates(today, Clock.System.now(), viewWindows.presetDue(today), viewWindows)
|
||||
val now = Clock.System.now()
|
||||
val (todayStart, todayEnd) = DayWindow.today(now, ZoneId.systemDefault())
|
||||
val presetDue = preset?.dueDate ?: presetSmartList?.dueWindows?.presetDue(today)
|
||||
val dates = settings.defaultNewTaskDates(today, now, presetDue, subtask = parentId != null) {
|
||||
it.showsIn(presetSmartList, filter, todayStart, todayEnd)
|
||||
}
|
||||
startFollowsDue = settings.defaultStartDate.takeIf { dates.start != null && dates.due != null }
|
||||
// A read-only or vanished default — or a widget's preset list, if it was
|
||||
// since deleted or turned read-only — would give the task a list it
|
||||
// cannot be saved to.
|
||||
@@ -223,6 +236,7 @@ class TaskEditViewModel @Inject constructor(
|
||||
bound = true
|
||||
editingTaskId = taskId
|
||||
editingOccurrence = occurrenceStart
|
||||
startFollowsDue = null
|
||||
setAside.clear()
|
||||
viewModelScope.launch {
|
||||
val settings = settingsPrefs.settings.first()
|
||||
@@ -334,12 +348,19 @@ class TaskEditViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun onStartChange(value: Instant?) = update {
|
||||
startFollowsDue = null
|
||||
val next = it.copy(start = value)
|
||||
next.withDatedReminders(lostDates = it.hasDates && !next.hasDates)
|
||||
}
|
||||
|
||||
fun onDueChange(value: Instant?) = update {
|
||||
val next = it.copy(due = value)
|
||||
val follow = startFollowsDue
|
||||
val start = if (follow != null && value != null && it.isAllDay) {
|
||||
follow.dateFor(value.calendarDate(allDay = true), LocalDate.now())?.let(::allDayInstantOf)
|
||||
} else {
|
||||
it.start
|
||||
}
|
||||
val next = it.copy(start = start, due = value)
|
||||
next.withDatedReminders(lostDates = it.hasDates && !next.hasDates)
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.smartListNamed
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
import kotlin.time.Instant
|
||||
import androidx.navigation.compose.NavHost
|
||||
@@ -243,8 +244,7 @@ fun AgendulaNavHost(
|
||||
val title = args?.getString(Dest.TaskEdit.ARG_TITLE)
|
||||
val tag = args?.getString(Dest.TaskEdit.ARG_TAG)
|
||||
val filterId = args?.getLong(Dest.TaskEdit.ARG_FILTER_ID)?.takeIf { it != Dest.NO_ID }
|
||||
val smartList = args?.getString(Dest.TaskEdit.ARG_SMART_LIST)
|
||||
?.let { name -> SmartList.entries.firstOrNull { it.name == name } }
|
||||
val smartList = smartListNamed(args?.getString(Dest.TaskEdit.ARG_SMART_LIST))
|
||||
val vm: TaskEditViewModel = hiltViewModel()
|
||||
LaunchedEffect(taskId, presetListId, parentId) {
|
||||
if (taskId != Dest.NO_ID) {
|
||||
|
||||
@@ -316,7 +316,7 @@ class TaskListViewModel @Inject constructor(
|
||||
/** Inline "add task" — a title into [listId], with the default dates. */
|
||||
fun quickAdd(title: String, listId: Long) = viewModelScope.launch {
|
||||
if (title.isBlank() || listId <= 0L) return@launch
|
||||
runCatching { repository.createTask(settingsPrefs.quickTask(title, listId)) }
|
||||
runCatching { repository.createTask(settingsPrefs.settings.first().quickTask(title, listId)) }
|
||||
}
|
||||
|
||||
private val _listWriteFailure = MutableStateFlow<ListWriteFailure?>(null)
|
||||
@@ -378,6 +378,8 @@ class TaskListViewModel @Inject constructor(
|
||||
/** Inline "add subtask" from an expanded list group — files it under [parent]. */
|
||||
fun quickAddSubtask(parent: Task, title: String) = viewModelScope.launch {
|
||||
if (title.isBlank() || parent.listId <= 0L) return@launch
|
||||
runCatching { repository.createTask(settingsPrefs.quickTask(title.trim(), parent.listId, parent.taskId)) }
|
||||
runCatching {
|
||||
repository.createTask(settingsPrefs.settings.first().quickTask(title.trim(), parent.listId, parent.taskId))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,18 @@ package de.jeanlucmakiola.agendula.domain
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.LocalDate
|
||||
import de.jeanlucmakiola.floret.time.DayWindow
|
||||
import java.time.ZoneId
|
||||
import kotlin.time.Instant
|
||||
|
||||
class NewTaskDefaultsTest {
|
||||
|
||||
private val today = LocalDate.of(2026, 1, 31)
|
||||
private val now = Instant.fromEpochMilliseconds(1_769_860_800_000)
|
||||
private val zone = ZoneId.systemDefault()
|
||||
|
||||
/** Today where the view tests run, as the smart lists read the device zone. */
|
||||
private val localToday = java.time.Instant.ofEpochMilli(now.toEpochMilliseconds()).atZone(zone).toLocalDate()
|
||||
|
||||
@Test
|
||||
fun `due defaults count from today`() {
|
||||
@@ -53,15 +59,38 @@ class NewTaskDefaultsTest {
|
||||
|
||||
@Test
|
||||
fun `the default due applies where the view still shows the task, else its preset`() {
|
||||
val upcoming = SmartList.UPCOMING.dueWindows
|
||||
assertThat(newTaskDue(DefaultDueDate.NEXT_WEEK, upcoming.presetDue(today), upcoming, today))
|
||||
.isEqualTo(today.plusWeeks(1))
|
||||
assertThat(newTaskDue(DefaultDueDate.TODAY, upcoming.presetDue(today), upcoming, today))
|
||||
.isEqualTo(today.plusDays(1))
|
||||
assertThat(newTaskDue(DefaultDueDate.NONE, upcoming.presetDue(today), upcoming, today))
|
||||
.isEqualTo(today.plusDays(1))
|
||||
val noDate = SmartList.NO_DATE.dueWindows
|
||||
assertThat(newTaskDue(DefaultDueDate.TOMORROW, noDate.presetDue(today), noDate, today)).isNull()
|
||||
assertThat(newTaskDue(DefaultDueDate.TOMORROW, null, emptySet(), today)).isEqualTo(today.plusDays(1))
|
||||
val (start, end) = DayWindow.today(now, zone)
|
||||
val upcoming = SmartList.UPCOMING.dueWindows.presetDue(localToday)
|
||||
fun inUpcoming(due: DefaultDueDate) = newTaskDates(due, DefaultStartDate.NONE, upcoming, localToday, now) {
|
||||
it.showsIn(SmartList.UPCOMING, null, start, end, zone)
|
||||
}.due
|
||||
assertThat(inUpcoming(DefaultDueDate.NEXT_WEEK)).isEqualTo(allDayInstantOf(localToday.plusWeeks(1)))
|
||||
assertThat(inUpcoming(DefaultDueDate.TODAY)).isEqualTo(allDayInstantOf(localToday.plusDays(1)))
|
||||
assertThat(inUpcoming(DefaultDueDate.NONE)).isEqualTo(allDayInstantOf(localToday.plusDays(1)))
|
||||
val noDate = newTaskDates(DefaultDueDate.TOMORROW, DefaultStartDate.NONE, null, localToday, now) {
|
||||
it.showsIn(SmartList.NO_DATE, null, start, end, zone)
|
||||
}
|
||||
assertThat(noDate.due).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a task starting today keeps its default due in Today`() {
|
||||
val (start, end) = DayWindow.today(now, zone)
|
||||
fun inToday(startDefault: DefaultStartDate) =
|
||||
newTaskDates(DefaultDueDate.NEXT_WEEK, startDefault, localToday, localToday, now) {
|
||||
it.showsIn(SmartList.TODAY, null, start, end, zone)
|
||||
}.due
|
||||
assertThat(inToday(DefaultStartDate.TODAY)).isEqualTo(allDayInstantOf(localToday.plusWeeks(1)))
|
||||
assertThat(inToday(DefaultStartDate.NONE)).isEqualTo(allDayInstantOf(localToday))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a saved filter checks only its due windows`() {
|
||||
val (start, end) = DayWindow.today(now, zone)
|
||||
val filter = SavedFilter(id = 1L, name = "Soon", due = setOf(DueWindow.TODAY), listIds = setOf(9L))
|
||||
val dates = newTaskDates(DefaultDueDate.TODAY, DefaultStartDate.NONE, localToday, localToday, now)
|
||||
assertThat(dates.showsIn(null, filter, start, end, zone)).isTrue()
|
||||
val later = newTaskDates(DefaultDueDate.TOMORROW, DefaultStartDate.NONE, localToday, localToday, now)
|
||||
assertThat(later.showsIn(null, filter, start, end, zone)).isFalse()
|
||||
}
|
||||
}
|
||||
@@ -116,18 +116,4 @@ class SavedFilterTest {
|
||||
assertThat(filter.withListsIn(setOf(2L)).anyList).isTrue()
|
||||
assertThat(filter.copy(listsElsewhere = true).withListsIn(setOf(2L)).anyList).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a due date is admitted only where the view would still show the task`() {
|
||||
val day = LocalDate.of(2026, 10, 10)
|
||||
assertThat(empty.due.admitsDue(day.plusDays(3), day)).isTrue()
|
||||
val todayOrUndated = setOf(DueWindow.TODAY, DueWindow.NO_DATE)
|
||||
assertThat(todayOrUndated.admitsDue(day, day)).isTrue()
|
||||
assertThat(todayOrUndated.admitsDue(day.plusDays(1), day)).isFalse()
|
||||
assertThat(setOf(DueWindow.OVERDUE).admitsDue(day.minusDays(1), day)).isTrue()
|
||||
assertThat(SmartList.NO_DATE.dueWindows.admitsDue(day, day)).isFalse()
|
||||
assertThat(SmartList.UPCOMING.dueWindows.admitsDue(day, day)).isFalse()
|
||||
assertThat(SmartList.UPCOMING.dueWindows.admitsDue(day.plusDays(1), day)).isTrue()
|
||||
assertThat(SmartList.ALL.dueWindows.admitsDue(day, day)).isTrue()
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,31 @@ class TaskEditViewModelTest {
|
||||
assertThat(vm.state.value.due).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a default start counted from the due moves with it until picked`() = runTest {
|
||||
val prefs = settingsPrefs().apply {
|
||||
setDefaultDueDate(DefaultDueDate.NEXT_MONTH)
|
||||
setDefaultStartDate(DefaultStartDate.WEEK_BEFORE_DUE)
|
||||
}
|
||||
val vm = TaskEditViewModel(repository, prefs).apply { bindNew() }
|
||||
val day = LocalDate.now()
|
||||
|
||||
vm.onDueChange(allDayInstantOf(day.plusDays(10)))
|
||||
assertThat(vm.state.value.start).isEqualTo(allDayInstantOf(day.plusDays(3)))
|
||||
|
||||
vm.onStartChange(allDayInstantOf(day.plusDays(1)))
|
||||
vm.onDueChange(allDayInstantOf(day.plusDays(20)))
|
||||
assertThat(vm.state.value.start).isEqualTo(allDayInstantOf(day.plusDays(1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a new subtask takes no default due`() = runTest {
|
||||
val prefs = settingsPrefs().apply { setDefaultDueDate(DefaultDueDate.TOMORROW) }
|
||||
val vm = TaskEditViewModel(repository, prefs).apply { bindNew(parentId = TASK_ID) }
|
||||
|
||||
assertThat(vm.state.value.due).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the old start-today switch carries over as a timed start`() {
|
||||
val prefs = settingsPrefs(preferencesOf(booleanPreferencesKey("default_start_today") to true))
|
||||
|
||||
Reference in new issue
Block a user