A task added from a block's custom rules gets the rule's presets (#59)
This commit is contained in:
1 parent
ee419a2b97
commit
03e050a14a
3 files changed
+22
-5
No files matched your search
@@ -8,6 +8,8 @@ import de.jeanlucmakiola.agendula.data.prefs.Settings
|
||||
import de.jeanlucmakiola.agendula.data.prefs.SettingsPrefs
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TaskConflictException
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TasksRepository
|
||||
import de.jeanlucmakiola.agendula.domain.Rule
|
||||
import de.jeanlucmakiola.agendula.domain.SavedFilter
|
||||
import de.jeanlucmakiola.agendula.domain.Priority
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
@@ -229,6 +231,7 @@ class TaskEditViewModel @Inject constructor(
|
||||
presetFilterId: Long? = null,
|
||||
presetSmartList: SmartList? = null,
|
||||
presetDueDate: LocalDate? = null,
|
||||
presetRule: Rule? = null,
|
||||
) {
|
||||
if (bound) return
|
||||
bound = true
|
||||
@@ -240,7 +243,9 @@ class TaskEditViewModel @Inject constructor(
|
||||
this@TaskEditViewModel.settings = settings
|
||||
defaultFields = settings.defaultEditFields
|
||||
val lists = runCatching { repository.taskLists().first() }.getOrElse { emptyList() }
|
||||
// A block's custom rules preset a new task as a saved filter with that rule does.
|
||||
val filter = presetFilterId?.let { settingsPrefs.savedFilter(it).first() }
|
||||
?: presetRule?.let { SavedFilter(0, "", it) }
|
||||
val now = Clock.System.now()
|
||||
val today = now.calendarDate(allDay = false)
|
||||
val preset = filter?.newTaskPreset(today)
|
||||
|
||||
@@ -220,6 +220,7 @@ fun AgendulaNavHost(
|
||||
filterId = (filter as? TaskFilter.Saved)?.id,
|
||||
smartList = (filter as? TaskFilter.Smart)?.list,
|
||||
due = (filter as? TaskFilter.DueOn)?.date,
|
||||
rule = (filter as? TaskFilter.Matching)?.rule,
|
||||
),
|
||||
)
|
||||
},
|
||||
@@ -298,6 +299,7 @@ fun AgendulaNavHost(
|
||||
val tag = args?.getString(Dest.TaskEdit.ARG_TAG)
|
||||
val filterId = args?.getLong(Dest.TaskEdit.ARG_FILTER_ID)?.takeIf { it != Dest.NO_ID }
|
||||
val smartList = smartListNamed(args?.getString(Dest.TaskEdit.ARG_SMART_LIST))
|
||||
val presetRule = args?.getString(Dest.TaskEdit.ARG_RULE)?.let { runCatching { Dest.TaskList.ruleOf(it) }.getOrNull() }
|
||||
val presetDue = args?.getString(Dest.TaskEdit.ARG_DUE)?.let { runCatching { java.time.LocalDate.parse(it) }.getOrNull() }
|
||||
val vm: TaskEditViewModel = hiltViewModel()
|
||||
LaunchedEffect(taskId, presetListId, parentId) {
|
||||
@@ -312,6 +314,7 @@ fun AgendulaNavHost(
|
||||
presetFilterId = filterId,
|
||||
presetSmartList = smartList,
|
||||
presetDueDate = presetDue,
|
||||
presetRule = presetRule,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.jeanlucmakiola.agendula.ui.navigation
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.navArgument
|
||||
import de.jeanlucmakiola.agendula.data.prefs.RuleCodec
|
||||
import de.jeanlucmakiola.agendula.domain.Rule
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
|
||||
@@ -18,6 +19,9 @@ import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
* being nullable, which sidesteps the lack of a nullable-Long [NavType].
|
||||
*/
|
||||
object Dest {
|
||||
/** The store a rule's lists are qualified by in a route: any one, the same both ways. */
|
||||
private const val ROUTE_STORE = "ROUTE"
|
||||
|
||||
|
||||
const val NO_ID = -1L
|
||||
|
||||
@@ -68,9 +72,6 @@ object Dest {
|
||||
const val ARG_DAY = "day"
|
||||
const val ARG_RULE = "rule"
|
||||
const val ARG_TITLE = "title"
|
||||
|
||||
/** The store a rule's lists are qualified by in a route: any one, the same both ways. */
|
||||
private const val ROUTE_STORE = "ROUTE"
|
||||
const val route = "taskList?$ARG_LIST_ID={$ARG_LIST_ID}&$ARG_SMART={$ARG_SMART}&$ARG_TAG={$ARG_TAG}" +
|
||||
"&$ARG_FILTER_ID={$ARG_FILTER_ID}&$ARG_VIEW={$ARG_VIEW}&$ARG_DAY={$ARG_DAY}" +
|
||||
"&$ARG_RULE={$ARG_RULE}&$ARG_TITLE={$ARG_TITLE}"
|
||||
@@ -102,6 +103,9 @@ object Dest {
|
||||
}
|
||||
|
||||
/** Reconstruct the filter from a destination's arguments. */
|
||||
/** [text], a rule as a route carries it, read back. */
|
||||
fun ruleOf(text: String): Rule = RuleCodec.decode(text, ROUTE_STORE)
|
||||
|
||||
fun filterOf(
|
||||
smart: String?,
|
||||
listId: Long,
|
||||
@@ -112,7 +116,7 @@ object Dest {
|
||||
title: String? = null,
|
||||
): TaskFilter = when {
|
||||
smart != null -> TaskFilter.Smart(SmartList.valueOf(smart))
|
||||
rule != null -> TaskFilter.Matching(RuleCodec.decode(rule, ROUTE_STORE), title)
|
||||
rule != null -> TaskFilter.Matching(ruleOf(rule), title)
|
||||
day != null -> TaskFilter.DueOn(java.time.LocalDate.parse(day))
|
||||
tag != null -> TaskFilter.Tagged(tag)
|
||||
filterId != NO_ID -> TaskFilter.Saved(filterId)
|
||||
@@ -173,6 +177,7 @@ object Dest {
|
||||
const val ARG_FILTER_ID = "filterId"
|
||||
const val ARG_SMART_LIST = "smartList"
|
||||
const val ARG_DUE = "due"
|
||||
const val ARG_RULE = "rule"
|
||||
const val route =
|
||||
"taskEdit?$ARG_TASK_ID={$ARG_TASK_ID}" +
|
||||
"&$ARG_PRESET_LIST_ID={$ARG_PRESET_LIST_ID}" +
|
||||
@@ -182,7 +187,8 @@ object Dest {
|
||||
"&$ARG_TAG={$ARG_TAG}" +
|
||||
"&$ARG_FILTER_ID={$ARG_FILTER_ID}" +
|
||||
"&$ARG_SMART_LIST={$ARG_SMART_LIST}" +
|
||||
"&$ARG_DUE={$ARG_DUE}"
|
||||
"&$ARG_DUE={$ARG_DUE}" +
|
||||
"&$ARG_RULE={$ARG_RULE}"
|
||||
|
||||
val arguments = listOf(
|
||||
navArgument(ARG_TASK_ID) { type = NavType.LongType; defaultValue = NO_ID },
|
||||
@@ -194,6 +200,7 @@ object Dest {
|
||||
navArgument(ARG_FILTER_ID) { type = NavType.LongType; defaultValue = NO_ID },
|
||||
navArgument(ARG_SMART_LIST) { type = NavType.StringType; nullable = true; defaultValue = null },
|
||||
navArgument(ARG_DUE) { type = NavType.StringType; nullable = true; defaultValue = null },
|
||||
navArgument(ARG_RULE) { type = NavType.StringType; nullable = true; defaultValue = null },
|
||||
)
|
||||
|
||||
fun buildEdit(taskId: Long, occurrenceStart: Long? = null): String =
|
||||
@@ -208,6 +215,7 @@ object Dest {
|
||||
filterId: Long? = null,
|
||||
smartList: SmartList? = null,
|
||||
due: java.time.LocalDate? = null,
|
||||
rule: Rule? = null,
|
||||
): String {
|
||||
val params = buildList {
|
||||
if (presetListId != null) add("$ARG_PRESET_LIST_ID=$presetListId")
|
||||
@@ -217,6 +225,7 @@ object Dest {
|
||||
if (filterId != null) add("$ARG_FILTER_ID=$filterId")
|
||||
if (smartList != null) add("$ARG_SMART_LIST=${smartList.name}")
|
||||
if (due != null) add("$ARG_DUE=$due")
|
||||
if (rule != null) add("$ARG_RULE=${android.net.Uri.encode(RuleCodec.encode(rule, ROUTE_STORE))}")
|
||||
}
|
||||
return if (params.isEmpty()) "taskEdit" else "taskEdit?${params.joinToString("&")}"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user