Keep the default due where no date would show the task, tidy up (#107)
This commit is contained in:
1 parent
82f087a73c
commit
2e7b5cf3f8
8 files changed
+45
-34
No files matched your search
@@ -18,6 +18,7 @@ import de.jeanlucmakiola.agendula.domain.newTaskDates
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
import de.jeanlucmakiola.agendula.domain.TaskForm
|
||||
import de.jeanlucmakiola.agendula.domain.calendarDate
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFormField
|
||||
import de.jeanlucmakiola.agendula.domain.TaskReminder
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSection
|
||||
@@ -176,8 +177,8 @@ data class Settings(
|
||||
title: String,
|
||||
listId: Long,
|
||||
parentId: Long? = null,
|
||||
today: LocalDate = LocalDate.now(),
|
||||
now: Instant = Clock.System.now(),
|
||||
today: LocalDate = now.calendarDate(allDay = false),
|
||||
): TaskForm {
|
||||
val dates = defaultNewTaskDates(today, now, subtask = parentId != null)
|
||||
return TaskForm(
|
||||
|
||||
@@ -129,6 +129,15 @@ data class Task(
|
||||
get() = if (occurrenceStart == null) "$taskId" else "$taskId@${occurrenceStart.toEpochMilliseconds()}"
|
||||
}
|
||||
|
||||
/** An open, unsaved task with only these dates, to ask a view whether it would show one. */
|
||||
fun openTaskDated(start: Instant?, due: Instant?, isAllDay: Boolean): Task = 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,
|
||||
)
|
||||
|
||||
/** Detail bundle: a task, its parent (if it's a subtask), and its direct children. */
|
||||
data class TaskDetail(
|
||||
val task: Task,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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. */
|
||||
@@ -42,7 +41,7 @@ data class NewTaskDates(val start: Instant?, val due: Instant?, val isAllDay: Bo
|
||||
* and the default [start]. Without a due date only [DefaultStartDate.TODAY]
|
||||
* applies, as a timed start at [now].
|
||||
*/
|
||||
fun newTaskDates(dueDate: LocalDate?, start: DefaultStartDate, today: LocalDate, now: Instant): NewTaskDates {
|
||||
fun datesForDue(dueDate: LocalDate?, start: DefaultStartDate, today: LocalDate, now: Instant): NewTaskDates {
|
||||
if (dueDate == null) {
|
||||
return NewTaskDates(start = now.takeIf { start == DefaultStartDate.TODAY }, due = null, isAllDay = false)
|
||||
}
|
||||
@@ -52,8 +51,8 @@ fun newTaskDates(dueDate: LocalDate?, start: DefaultStartDate, today: LocalDate,
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* when there is no default due, or when the view the task is added from would
|
||||
* [show] it with the preset but not with the default.
|
||||
*/
|
||||
fun newTaskDates(
|
||||
due: DefaultDueDate,
|
||||
@@ -63,9 +62,10 @@ fun newTaskDates(
|
||||
now: Instant,
|
||||
show: (NewTaskDates) -> Boolean = { true },
|
||||
): NewTaskDates {
|
||||
val preset = newTaskDates(presetDue, start, today, now)
|
||||
val preset = datesForDue(presetDue, start, today, now)
|
||||
val dueDate = due.dateFrom(today) ?: return preset
|
||||
return newTaskDates(dueDate, start, today, now).takeIf(show) ?: preset
|
||||
val dated = datesForDue(dueDate, start, today, now)
|
||||
return listOf(dated, preset).firstOrNull(show) ?: dated
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,17 +77,10 @@ fun NewTaskDates.showsIn(
|
||||
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,
|
||||
)
|
||||
val probe = openTaskDated(start, due, isAllDay)
|
||||
return when {
|
||||
savedFilter != null -> savedFilter.due.isEmpty() || dueWindowOf(probe, todayStart, todayEnd, zone) in savedFilter.due
|
||||
savedFilter != null -> savedFilter.due.isEmpty() || dueWindowOf(probe, todayStart, todayEnd) in savedFilter.due
|
||||
smartList != null -> TaskFiltering.matches(probe, TaskFilter.Smart(smartList), todayStart, todayEnd)
|
||||
else -> true
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class TaskDetailViewModel @Inject constructor(
|
||||
runCatching { repository.duplicateTask(task.taskId, task.occurrenceStart) }.onSuccess(onCopied)
|
||||
}
|
||||
|
||||
/** Add a subtask (title only) under the currently-shown task. */
|
||||
/** Add a subtask by title under the currently-shown task, with the default start. */
|
||||
fun addSubtask(title: String) = viewModelScope.launch {
|
||||
val parent = (state.value as? TaskDetailUiState.Content)?.detail?.task ?: return@launch
|
||||
if (title.isBlank()) return@launch
|
||||
|
||||
@@ -189,10 +189,10 @@ class TaskEditViewModel @Inject constructor(
|
||||
this@TaskEditViewModel.settings = settings
|
||||
defaultFields = settings.defaultEditFields
|
||||
val lists = runCatching { repository.taskLists().first() }.getOrElse { emptyList() }
|
||||
val today = LocalDate.now()
|
||||
val filter = presetFilterId?.let { settingsPrefs.savedFilter(it).first() }
|
||||
val preset = filter?.newTaskPreset(today)
|
||||
val now = Clock.System.now()
|
||||
val today = now.calendarDate(allDay = false)
|
||||
val preset = filter?.newTaskPreset(today)
|
||||
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) {
|
||||
|
||||
@@ -18,7 +18,6 @@ import androidx.compose.material3.MaterialTheme
|
||||
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
|
||||
|
||||
@@ -495,7 +495,7 @@
|
||||
<string name="settings_default_list_first">First available list</string>
|
||||
<string name="settings_add_subtask_row">Show \"add a subtask\" row</string>
|
||||
<string name="settings_add_subtask_row_hint">An add field at the end of an expanded task\'s subtasks</string>
|
||||
<!-- Unused since 1.4; kept until Weblate drops their translations. -->
|
||||
<!-- Unused since 1.4; kept while translations still carry them, as an extra translation fails the build. -->
|
||||
<string name="settings_default_start_today">Default start to today</string>
|
||||
<string name="settings_default_start_today_hint">Pre-fill a new task\'s start with today\'s date</string>
|
||||
<string name="settings_default_due_date">Default due date</string>
|
||||
|
||||
Reference in new issue
Block a user