Quick-add solves its target as the editor does, from the view's task list too, skips read-only lists, keeps text per view and reads year-first short dates (#186)
This commit is contained in:
1 parent
1b370f2739
commit
456b7cddaa
10 files changed
+168
-65
No files matched your search
@@ -15,6 +15,12 @@ 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.NewTaskOrigin
|
||||
import de.jeanlucmakiola.agendula.domain.Priority
|
||||
import de.jeanlucmakiola.agendula.domain.dueWindows
|
||||
import de.jeanlucmakiola.agendula.domain.newTaskPreset
|
||||
import de.jeanlucmakiola.agendula.domain.presetDue
|
||||
import de.jeanlucmakiola.agendula.domain.showsIn
|
||||
import de.jeanlucmakiola.agendula.domain.QuickAddParse
|
||||
import de.jeanlucmakiola.agendula.domain.Rule
|
||||
import de.jeanlucmakiola.agendula.domain.RuleClock
|
||||
@@ -270,11 +276,13 @@ data class Settings(
|
||||
}
|
||||
|
||||
/**
|
||||
* A task from the quick-add bar, in a view of [scope] (`null` for none) read
|
||||
* against [clock]; `null` when there is no list to put it in. It goes to the
|
||||
* list [parse] names, else the one the scope keeps tasks to, else the default
|
||||
* list (one the scope admits, where it can), and takes the tags, priority and, without a date of its own, the due
|
||||
* date that keep it in the scope (see [scopePreset]). [writable] are the lists that take tasks.
|
||||
* A task from the quick-add bar added from [origin], within [scope] (`null`
|
||||
* for none) read against [clock]; `null` when there is no list to put it in.
|
||||
* It goes where the editor would put one added there: the list [parse] names,
|
||||
* else [origin]'s list, else the one the scope keeps tasks to, else the
|
||||
* default list (one of the filter's or the scope's lists, where it can). It
|
||||
* takes the tags, priority and, without a date of its own, the due date that
|
||||
* keep it in both (see [scopePreset], [newTaskPreset]). [writable] are the lists that take tasks.
|
||||
*/
|
||||
fun quickAddTask(
|
||||
parse: QuickAddParse,
|
||||
@@ -282,16 +290,29 @@ data class Settings(
|
||||
writable: List<TaskList>,
|
||||
clock: RuleClock,
|
||||
now: Instant = Clock.System.now(),
|
||||
origin: NewTaskOrigin = NewTaskOrigin(),
|
||||
): TaskForm? {
|
||||
fun usable(id: Long?) = id?.takeIf { writable.any { it.id == id } }
|
||||
val preset = scope.scopePreset(clock)
|
||||
val listId = parse.list?.id?.takeIf { id -> writable.any { it.id == id } }
|
||||
?: preset.listId?.takeIf { id -> writable.any { it.id == id } }
|
||||
?: defaultTaskList(writable, defaultListId, within = scope?.listUniverse().orEmpty())
|
||||
val filterPreset = origin.filter?.newTaskPreset(clock.today)
|
||||
val listId = usable(parse.list?.id)
|
||||
?: usable(origin.listId)
|
||||
?: usable(preset.listId)
|
||||
?: defaultTaskList(
|
||||
writable,
|
||||
defaultListId,
|
||||
within = filterPreset?.listIds?.takeIf { it.isNotEmpty() } ?: scope?.listUniverse().orEmpty(),
|
||||
)
|
||||
?: return null
|
||||
val due = parse.due
|
||||
val dates = when {
|
||||
due == null -> defaultNewTaskDates(clock.today, now, preset.dueDate) { dates ->
|
||||
scope == null || scope.dueVerdict(openTaskDated(dates.start, dates.due, dates.isAllDay), clock) != false
|
||||
due == null -> {
|
||||
val presetDue = filterPreset?.dueDate ?: preset.dueDate ?: origin.smartList?.dueWindows?.presetDue(clock.today)
|
||||
defaultNewTaskDates(clock.today, now, presetDue) { dates ->
|
||||
val probe = openTaskDated(dates.start, dates.due, dates.isAllDay)
|
||||
dates.showsIn(origin.smartList, origin.filter, clock.todayStart, clock.todayEnd, upcomingRange.end(now, clock.zone), clock) &&
|
||||
(scope == null || scope.dueVerdict(probe, clock) != false)
|
||||
}
|
||||
}
|
||||
due.time == null -> datesForDue(due.date, defaultStartDate, clock.today, now)
|
||||
else -> datesForTimedDue(due.date, due.time, defaultStartDate, clock.today, now, clock.zone)
|
||||
@@ -303,8 +324,8 @@ data class Settings(
|
||||
due = dates.due,
|
||||
isAllDay = dates.isAllDay,
|
||||
startsNow = dates.start == now,
|
||||
priority = preset.priority,
|
||||
tags = preset.tags,
|
||||
priority = maxOf(preset.priority, filterPreset?.priority ?: Priority.NONE),
|
||||
tags = (listOfNotNull(origin.tag) + filterPreset?.tags.orEmpty() + preset.tags).distinct(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -129,3 +129,14 @@ fun defaultTaskList(writable: List<TaskList>, defaultListId: Long?, within: Set<
|
||||
?: writable.firstOrNull { !it.isLocal }?.id
|
||||
?: writable.firstOrNull()?.id
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a new task is added from, past a view's scope: the list, tag, saved
|
||||
* filter or smart list a screen or a view's task list shows, which preset it.
|
||||
*/
|
||||
data class NewTaskOrigin(
|
||||
val listId: Long? = null,
|
||||
val tag: String? = null,
|
||||
val filter: SavedFilter? = null,
|
||||
val smartList: SmartList? = null,
|
||||
)
|
||||
@@ -103,8 +103,11 @@ data class QuickAddKeywords(
|
||||
}
|
||||
}
|
||||
|
||||
/** How a locale writes a day and month without the year: `20.11.`, `11/20`. */
|
||||
data class ShortDateFormat(val dayFirst: Boolean, val separator: Char) {
|
||||
/**
|
||||
* How a locale writes a day and month: `20.11.`, `11/20`, with the year after
|
||||
* them or, where [yearFirst], before them (`26-12-01`).
|
||||
*/
|
||||
data class ShortDateFormat(val dayFirst: Boolean, val separator: Char, val yearFirst: Boolean = false) {
|
||||
companion object {
|
||||
private const val SEPARATORS = "./-"
|
||||
|
||||
@@ -118,7 +121,8 @@ data class ShortDateFormat(val dayFirst: Boolean, val separator: Char) {
|
||||
if (day < 0 || month < 0) return ShortDateFormat(dayFirst = false, separator = '/')
|
||||
val first = minOf(day, month)
|
||||
val separator = pattern.drop(first).firstOrNull { it in SEPARATORS } ?: '/'
|
||||
return ShortDateFormat(dayFirst = day < month, separator = separator)
|
||||
val year = pattern.indexOf('y')
|
||||
return ShortDateFormat(dayFirst = day < month, separator = separator, yearFirst = year in 0 until first)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,7 +166,7 @@ data class QuickAddParse(
|
||||
* - a weekday, `fri` or `friday`: the next one, a week ahead on that day itself;
|
||||
* - `3d`, `2w`, `1m`: that many days, weeks or months ahead (up to 999);
|
||||
* - `2026-11-20`, or the locale's short form, `20.11.`, `20.11`, `20.11.26`,
|
||||
* `20.11.2026` (`11/20`, `11/20/26`…): without a year, a day already past is next year's.
|
||||
* `20.11.2026` (`11/20`, `11/20/26`, `26-11-20`…): without a year, a day already past is next year's.
|
||||
*
|
||||
* Words come from [QuickAddKeywords], in any case. The time is `9`, `14:30`, `14h30`, `9am`,
|
||||
* `2:30pm`; with one that doesn't read the whole token stays text.
|
||||
@@ -282,8 +286,13 @@ object QuickAddSyntax {
|
||||
private fun shortDate(word: String, context: QuickAddContext): LocalDate? {
|
||||
val format = context.shortDate
|
||||
val sep = Regex.escape(format.separator.toString())
|
||||
val match = Regex("""(\d{1,2})$sep(\d{1,2})(?:$sep(?:(\d{2}|\d{4}))?)?""").matchEntire(word) ?: return null
|
||||
val (first, second, yearText) = match.destructured
|
||||
val pattern = if (format.yearFirst) {
|
||||
"""(?:(\d{2}|\d{4})$sep)?(\d{1,2})$sep(\d{1,2})$sep?"""
|
||||
} else {
|
||||
"""(\d{1,2})$sep(\d{1,2})(?:$sep(?:(\d{2}|\d{4}))?)?"""
|
||||
}
|
||||
val groups = Regex(pattern).matchEntire(word)?.groupValues ?: return null
|
||||
val (first, second, yearText) = if (format.yearFirst) listOf(groups[2], groups[3], groups[1]) else groups.drop(1)
|
||||
val day = (if (format.dayFirst) first else second).toInt()
|
||||
val month = (if (format.dayFirst) second else first).toInt()
|
||||
if (yearText.isNotEmpty()) {
|
||||
|
||||
@@ -203,9 +203,11 @@ fun ListsScreen(
|
||||
val undo by homeTaskModel.undo.collectAsStateWithLifecycle()
|
||||
// The bar takes the FAB's place; with no list to add to, making one stays the FAB's.
|
||||
val quickAddShown = content?.view?.quickAdd == true && !noLists && quickAddLists?.isEmpty() != true && !searchActive && !editing
|
||||
// A receipt is about the view it was made in.
|
||||
LaunchedEffect(content?.view?.id) { quickAdd.dismissReceipt() }
|
||||
val scopedViewId = content?.view?.takeIf { it.scope != null }?.id
|
||||
// What was typed, and a receipt, are about the view they were made in.
|
||||
LaunchedEffect(content?.view?.id) { content?.view?.id?.let(quickAdd::onViewShown) }
|
||||
// A new task keeps to the scope the view's task list reads, the view's own when it has none.
|
||||
val scopedViewId = if (taskBlock != null) scopeFor(taskBlock) else content?.view?.takeIf { it.scope != null }?.id
|
||||
val quickAddScope = content?.scopeRule?.takeUnless { taskBlock?.ignoreScope == true }
|
||||
val viewSaveFailed by viewModel.viewSaveFailed.collectAsStateWithLifecycle()
|
||||
val actions = BlockActions(
|
||||
openFilter = onOpenFilter,
|
||||
@@ -264,7 +266,7 @@ fun ListsScreen(
|
||||
text = quickAdd.text,
|
||||
onTextChange = quickAdd::onTextChange,
|
||||
lists = quickAddLists.orEmpty(),
|
||||
onAdd = { parse -> quickAdd.add(quickAdd.text, parse, content?.scopeRule, taskFilter) },
|
||||
onAdd = { parse -> quickAdd.add(quickAdd.text, parse, quickAddScope, taskFilter, content?.view?.id) },
|
||||
onExpand = { parse ->
|
||||
onNewTask(NewTaskSeed(scopedViewId, taskFilter, parse.title, parse.list?.id, parse.due))
|
||||
},
|
||||
@@ -335,13 +337,14 @@ fun ListsScreen(
|
||||
.height(SnackChipHeight),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
// One chip: a refused write, else a removed block's undo, else a quick add, else the task block's undo.
|
||||
// One chip: a refused write, else a removed block's undo, else the task block's undo, else a quick add.
|
||||
val failure = writeFailure
|
||||
val receipt = undo
|
||||
val gone = removed
|
||||
val added = quickAddReceipt
|
||||
val notShown = (added as? QuickAddReceipt.NotShown).takeIf { failure == null && !viewSaveFailed && gone == null }
|
||||
val addFailed = added is QuickAddReceipt.Failed && failure == null && !viewSaveFailed && gone == null
|
||||
val added = quickAddReceipt?.takeIf { it.viewId == content?.view?.id }
|
||||
val quiet = failure == null && !viewSaveFailed && gone == null && receipt == null
|
||||
val notShown = (added as? QuickAddReceipt.NotShown)?.takeIf { quiet }
|
||||
val addFailed = added is QuickAddReceipt.Failed && quiet
|
||||
SnackChip(
|
||||
visible = failure != null || viewSaveFailed || gone != null || added != null || receipt != null,
|
||||
message = when {
|
||||
|
||||
@@ -95,7 +95,8 @@ import java.time.LocalDate
|
||||
* The quick-add bar at the bottom of a view or list: a field reading the `@date`
|
||||
* and `+list` syntax as it is typed (see [QuickAddSyntax]), its tokens marked and
|
||||
* what they stand for shown as chips above it. [onAdd] takes what was typed and
|
||||
* empties [text]; [onExpand] opens it in the full editor instead. Rides above the keyboard and
|
||||
* empties [text]; [onExpand] opens it in the full editor instead, leaving it in
|
||||
* the bar in case the editor is left without saving. Rides above the keyboard and
|
||||
* clears the navigation bar.
|
||||
*/
|
||||
@Composable
|
||||
@@ -124,10 +125,7 @@ fun QuickAddBar(
|
||||
onTextChange = onTextChange,
|
||||
canSubmit = parse.title.isNotBlank(),
|
||||
onSubmit = { onAdd(parse) },
|
||||
onExpand = {
|
||||
onExpand(parse)
|
||||
onTextChange("")
|
||||
},
|
||||
onExpand = { onExpand(parse) },
|
||||
tokens = parse.tokens,
|
||||
elevated = true,
|
||||
)
|
||||
|
||||
@@ -13,9 +13,9 @@ import de.jeanlucmakiola.agendula.domain.Rule
|
||||
import de.jeanlucmakiola.agendula.domain.RuleClock
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
import de.jeanlucmakiola.agendula.domain.TaskList
|
||||
import de.jeanlucmakiola.agendula.domain.DueSpec
|
||||
import de.jeanlucmakiola.agendula.domain.NewTaskOrigin
|
||||
import de.jeanlucmakiola.agendula.domain.SavedFilter
|
||||
import de.jeanlucmakiola.agendula.domain.asOpenTask
|
||||
import de.jeanlucmakiola.agendula.domain.dueWindows
|
||||
import de.jeanlucmakiola.agendula.domain.matches
|
||||
import de.jeanlucmakiola.floret.time.DayWindow
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -51,14 +51,28 @@ data class NewTaskSeed(
|
||||
|
||||
/** How a quick add went, when there is something to say. Not data classes: a repeat must still show. */
|
||||
sealed interface QuickAddReceipt {
|
||||
/** Added to list [listId], [listName], which the view doesn't show. */
|
||||
class NotShown(val listId: Long, val listName: String) : QuickAddReceipt
|
||||
/** The view the task was added in, if any. */
|
||||
val viewId: Long?
|
||||
|
||||
class Failed : QuickAddReceipt
|
||||
/** Added to list [listId], [listName], which the view doesn't show. */
|
||||
class NotShown(val listId: Long, val listName: String, override val viewId: Long?) : QuickAddReceipt
|
||||
|
||||
class Failed(override val viewId: Long?) : QuickAddReceipt
|
||||
}
|
||||
|
||||
/** Where a task added from a screen showing [filter] starts; nothing for none. */
|
||||
suspend fun SettingsPrefs.newTaskOrigin(filter: TaskFilter?): NewTaskOrigin = when (filter) {
|
||||
is TaskFilter.OfList -> NewTaskOrigin(listId = filter.listId)
|
||||
is TaskFilter.Tagged -> NewTaskOrigin(tag = filter.tag)
|
||||
is TaskFilter.Saved -> NewTaskOrigin(filter = savedFilter(filter.id).first())
|
||||
is TaskFilter.Matching -> NewTaskOrigin(filter = SavedFilter(0, "", filter.rule))
|
||||
is TaskFilter.Smart -> NewTaskOrigin(smartList = filter.list)
|
||||
is TaskFilter.DueOn, is TaskFilter.OfLists, null -> NewTaskOrigin()
|
||||
}
|
||||
|
||||
private const val RECEIPT_MS = 4_000L
|
||||
private const val KEY_TEXT = "quick_add_text"
|
||||
private const val KEY_VIEW = "quick_add_view"
|
||||
|
||||
/** The quick-add bar of a view or list: the lists it can name, and the adding. */
|
||||
@HiltViewModel
|
||||
@@ -91,14 +105,13 @@ class QuickAddViewModel @Inject constructor(
|
||||
private var receiptTimer: Job? = null
|
||||
|
||||
/**
|
||||
* Adds what [parse], read from [typed], holds within [scope] (`null` for none);
|
||||
* says so when the task falls outside it. [preset] is what the view's task list
|
||||
* shows, which gives the task a list, tags and a due date as its own new-task
|
||||
* action does, without narrowing what counts as shown. The write runs in the
|
||||
* application scope, so leaving the screen right after cannot cancel it; when
|
||||
* it fails, an empty bar gets [typed] back.
|
||||
* Adds what [parse], read from [typed], holds within [scope] (`null` for none),
|
||||
* from a screen showing [shows], as its new-task action would; says so when
|
||||
* the task falls outside the scope. The write runs in the application scope,
|
||||
* so leaving the screen right after cannot cancel it; when it fails, an empty
|
||||
* bar gets [typed] back. [viewId] is the view it is added in, if any.
|
||||
*/
|
||||
fun add(typed: String, parse: QuickAddParse, scope: Rule?, preset: TaskFilter? = null) {
|
||||
fun add(typed: String, parse: QuickAddParse, scope: Rule?, shows: TaskFilter? = null, viewId: Long? = null) {
|
||||
if (parse.title.isBlank()) return
|
||||
onTextChange("")
|
||||
val write = appScope.async {
|
||||
@@ -109,31 +122,35 @@ class QuickAddViewModel @Inject constructor(
|
||||
val zone = ZoneId.systemDefault()
|
||||
val (todayStart, todayEnd) = DayWindow.today(now, zone)
|
||||
val clock = RuleClock(todayStart, todayEnd, zone, settingsPrefs.firstDayOfWeek.first())
|
||||
val solved = listOfNotNull(scope, presetRule(preset)).let { if (it.size > 1) Rule.AllOf(it) else it.singleOrNull() }
|
||||
val form = settings.quickAddTask(parse, solved, writable, clock, now) ?: return@runCatching QuickAddReceipt.Failed()
|
||||
val origin = settingsPrefs.newTaskOrigin(shows)
|
||||
val form = settings.quickAddTask(parse, scope, writable, clock, now, origin)
|
||||
?: return@runCatching QuickAddReceipt.Failed(viewId)
|
||||
repository.createTask(form)
|
||||
if (scope == null || scope.matches(form.asOpenTask(), clock)) {
|
||||
null
|
||||
} else {
|
||||
QuickAddReceipt.NotShown(form.listId, writable.firstOrNull { it.id == form.listId }?.name.orEmpty())
|
||||
QuickAddReceipt.NotShown(form.listId, writable.firstOrNull { it.id == form.listId }?.name.orEmpty(), viewId)
|
||||
}
|
||||
}.getOrElse { QuickAddReceipt.Failed() }
|
||||
}.getOrElse { QuickAddReceipt.Failed(viewId) }
|
||||
}
|
||||
viewModelScope.launch {
|
||||
val receipt = write.await() ?: return@launch
|
||||
// The bar has moved on to another view meanwhile; this one's receipt and text are no business of it.
|
||||
if (receipt.viewId != shownViewId) return@launch
|
||||
if (receipt is QuickAddReceipt.Failed && text.isEmpty()) onTextChange(typed)
|
||||
show(receipt)
|
||||
}
|
||||
}
|
||||
|
||||
/** The rule a task shown by [filter] meets, as far as a new task can be made to. */
|
||||
private suspend fun presetRule(filter: TaskFilter?): Rule? = when (filter) {
|
||||
is TaskFilter.OfList -> Rule.InList(setOf(filter.listId))
|
||||
is TaskFilter.Tagged -> Rule.HasTag(filter.tag)
|
||||
is TaskFilter.Saved -> settingsPrefs.savedFilter(filter.id).first()?.rule
|
||||
is TaskFilter.Matching -> filter.rule
|
||||
is TaskFilter.Smart -> filter.list.dueWindows.singleOrNull()?.let { Rule.Due(DueSpec.Window(it)) }
|
||||
is TaskFilter.DueOn, is TaskFilter.OfLists, null -> null
|
||||
private var shownViewId: Long? = savedState[KEY_VIEW]
|
||||
|
||||
/** The bar now shows in view [viewId]; another view's text and receipt go. */
|
||||
fun onViewShown(viewId: Long?) {
|
||||
if (viewId == shownViewId) return
|
||||
shownViewId = viewId
|
||||
savedState[KEY_VIEW] = viewId
|
||||
onTextChange("")
|
||||
dismissReceipt()
|
||||
}
|
||||
|
||||
private fun show(receipt: QuickAddReceipt) {
|
||||
|
||||
@@ -207,7 +207,8 @@ fun TaskListScreen(
|
||||
// One add affordance, never two: a real list with the setting on gets a pinned
|
||||
// bottom quick-add bar; everything else (incl. smart lists, which have no single
|
||||
// target list) gets the floating "New task" button.
|
||||
val showBottomAddBar = content?.bottomAddBar == true && listId != null
|
||||
// A read-only share takes no tasks: it keeps the FAB, whose editor picks a list that does.
|
||||
val showBottomAddBar = content?.bottomAddBar == true && listId != null && content.list?.acceptsWrites == true
|
||||
|
||||
// Swipe-delete and completing a task both leave a floating undo chip; the
|
||||
// view model owns the window, so leaving the screen commits instead of losing it.
|
||||
@@ -338,7 +339,7 @@ fun TaskListScreen(
|
||||
text = quickAdd.text,
|
||||
onTextChange = quickAdd::onTextChange,
|
||||
lists = quickAddLists.orEmpty(),
|
||||
onAdd = { parse -> quickAdd.add(quickAdd.text, parse, scope) },
|
||||
onAdd = { parse -> quickAdd.add(quickAdd.text, parse, scope, shows = filter) },
|
||||
onExpand = { parse ->
|
||||
onNewTask(
|
||||
NewTaskSeed(
|
||||
@@ -506,7 +507,7 @@ private fun TaskListBody(
|
||||
val listId = (filter as? TaskFilter.OfList)?.listId
|
||||
// When the bottom quick-add bar is shown it already lives in the scaffold's
|
||||
// bottomBar (so `inner` covers it); otherwise reserve room to clear the FAB.
|
||||
val bottomBarShown = state.bottomAddBar && listId != null
|
||||
val bottomBarShown = state.bottomAddBar && listId != null && state.list?.acceptsWrites == true
|
||||
// While typing, the viewport ends at the keyboard (or at the quick-add bar
|
||||
// riding on it), so a focused add-subtask row can scroll fully above it.
|
||||
val imeVisible = WindowInsets.isImeVisible
|
||||
|
||||
@@ -8,12 +8,13 @@ import de.jeanlucmakiola.agendula.data.tasks.TasksRepository
|
||||
import de.jeanlucmakiola.agendula.domain.Rule
|
||||
import de.jeanlucmakiola.agendula.domain.View
|
||||
import de.jeanlucmakiola.agendula.domain.ViewIcon
|
||||
import de.jeanlucmakiola.agendula.domain.BlockType
|
||||
import de.jeanlucmakiola.agendula.domain.QuickAddParse
|
||||
import de.jeanlucmakiola.agendula.domain.RuleClock
|
||||
import de.jeanlucmakiola.agendula.domain.taskFilter
|
||||
import de.jeanlucmakiola.agendula.ui.quickadd.newTaskOrigin
|
||||
import de.jeanlucmakiola.agendula.domain.appliedScope
|
||||
import de.jeanlucmakiola.agendula.domain.defaultTaskList
|
||||
import de.jeanlucmakiola.agendula.domain.listUniverse
|
||||
import de.jeanlucmakiola.agendula.domain.newView
|
||||
import de.jeanlucmakiola.agendula.domain.scopePreset
|
||||
import de.jeanlucmakiola.floret.time.DayWindow
|
||||
import java.time.ZoneId
|
||||
import kotlin.time.Clock
|
||||
@@ -92,9 +93,11 @@ class EditViewViewModel @Inject constructor(
|
||||
val zone = ZoneId.systemDefault()
|
||||
val (todayStart, todayEnd) = DayWindow.today(now, zone)
|
||||
val clock = RuleClock(todayStart, todayEnd, zone, weekStart)
|
||||
val scope = draft.appliedScope(lists.mapTo(HashSet()) { it.id }).rule
|
||||
val id = scope.scopePreset(clock).listId?.takeIf { id -> writable.any { it.id == id } }
|
||||
?: defaultTaskList(writable, settings.defaultListId, within = scope?.listUniverse().orEmpty())
|
||||
// Worked out as the bar does: the view's task list presets the task, and keeps to the scope unless it ignores it.
|
||||
val taskBlock = draft.blocks.lastOrNull { it.type == BlockType.TASK_LIST }
|
||||
val scope = draft.appliedScope(lists.mapTo(HashSet()) { it.id }).rule?.takeUnless { taskBlock?.ignoreScope == true }
|
||||
val origin = settingsPrefs.newTaskOrigin(taskBlock?.source?.taskFilter)
|
||||
val id = settings.quickAddTask(QuickAddParse("-"), scope, writable, clock, now, origin)?.listId
|
||||
writable.firstOrNull { it.id == id }?.name
|
||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
|
||||
|
||||
|
||||
@@ -5,7 +5,12 @@ import de.jeanlucmakiola.agendula.domain.DefaultDueDate
|
||||
import de.jeanlucmakiola.agendula.domain.DefaultStartDate
|
||||
import de.jeanlucmakiola.agendula.domain.DueSpec
|
||||
import de.jeanlucmakiola.agendula.domain.DueWindow
|
||||
import de.jeanlucmakiola.agendula.domain.FilterCriteria
|
||||
import de.jeanlucmakiola.agendula.domain.LocalAccount
|
||||
import de.jeanlucmakiola.agendula.domain.NewTaskOrigin
|
||||
import de.jeanlucmakiola.agendula.domain.SavedFilter
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.TagMatch
|
||||
import de.jeanlucmakiola.agendula.domain.Priority
|
||||
import de.jeanlucmakiola.agendula.domain.QuickAddParse
|
||||
import de.jeanlucmakiola.agendula.domain.QuickDue
|
||||
@@ -51,7 +56,8 @@ class QuickAddTaskTest {
|
||||
scope: Rule? = null,
|
||||
settings: Settings = this.settings,
|
||||
lists: List<de.jeanlucmakiola.agendula.domain.TaskList> = writable,
|
||||
) = settings.quickAddTask(parse, scope, lists, clock, now)
|
||||
origin: NewTaskOrigin = NewTaskOrigin(),
|
||||
) = settings.quickAddTask(parse, scope, lists, clock, now, origin)
|
||||
|
||||
@Test
|
||||
fun `without a list or scope the task goes to the default list`() {
|
||||
@@ -164,6 +170,30 @@ class QuickAddTaskTest {
|
||||
assertThat(form.start).isEqualTo(now)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the list a screen shows comes before the scope's`() {
|
||||
val form = add(QuickAddParse("x"), scope = Rule.AllOf(listOf(Rule.InList(setOf(1L)), Rule.InList(setOf(3L)))), origin = NewTaskOrigin(listId = 3))!!
|
||||
assertThat(form.listId).isEqualTo(3L)
|
||||
assertThat(add(QuickAddParse("x", list = errands), origin = NewTaskOrigin(listId = 3))!!.listId).isEqualTo(2L)
|
||||
// A read-only one isn't.
|
||||
assertThat(add(QuickAddParse("x"), origin = NewTaskOrigin(listId = 9))!!.listId).isEqualTo(2L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a saved filter shown presets as the editor does, any-of tags included`() {
|
||||
val filter = SavedFilter(5, "Shop", FilterCriteria(listIds = setOf(1L, 3L), tags = setOf("shopping", "errands"), tagMatch = TagMatch.ANY))
|
||||
val form = add(QuickAddParse("x"), origin = NewTaskOrigin(filter = filter))!!
|
||||
assertThat(form.listId).isEqualTo(1L)
|
||||
assertThat(form.tags).containsExactly("errands")
|
||||
assertThat(filter.matches(form.asOpenTask(), clock)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a tag or smart list shown presets the tag or due`() {
|
||||
assertThat(add(QuickAddParse("x"), origin = NewTaskOrigin(tag = "home"))!!.tags).containsExactly("home")
|
||||
assertThat(add(QuickAddParse("x"), origin = NewTaskOrigin(smartList = SmartList.TODAY))!!.due).isEqualTo(allDayInstantOf(today))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a task the scope won't show is told apart`() {
|
||||
val scope = Rule.AllOf(listOf(Rule.InList(setOf(1L)), Rule.Due(DueSpec.Window(DueWindow.TODAY))))
|
||||
|
||||
@@ -162,6 +162,16 @@ class QuickAddSyntaxTest {
|
||||
assertThat(due("@20.11.", shortDate = us)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the year first where the locale writes it so`() {
|
||||
val swedish = ShortDateFormat(dayFirst = false, separator = '-', yearFirst = true)
|
||||
assertThat(due("@12-01", shortDate = swedish)?.date).isEqualTo(LocalDate.of(2026, 12, 1))
|
||||
assertThat(due("@11-20", shortDate = swedish)?.date).isEqualTo(LocalDate.of(2027, 11, 20))
|
||||
assertThat(due("@26-12-01", shortDate = swedish)?.date).isEqualTo(LocalDate.of(2026, 12, 1))
|
||||
assertThat(due("@2027-1-5", shortDate = swedish)?.date).isEqualTo(LocalDate.of(2027, 1, 5))
|
||||
assertThat(ShortDateFormat.of(Locale.forLanguageTag("sv-SE"))).isEqualTo(swedish)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `dates across the year's end and a leap day`() {
|
||||
val newYearsEve = LocalDate.of(2026, 12, 31)
|
||||
|
||||
Reference in new issue
Block a user