Tag conditions can name a tag no task carries yet (#172)
This commit is contained in:
1 parent
02f842016f
commit
34657f90ff
3 files changed
+55
-14
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package de.jeanlucmakiola.agendula.ui.filters
|
||||
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -23,10 +24,13 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.unit.dp
|
||||
import de.jeanlucmakiola.agendula.R
|
||||
import de.jeanlucmakiola.agendula.domain.DueSpec
|
||||
@@ -39,8 +43,11 @@ import de.jeanlucmakiola.floret.components.CustomAmountEditor
|
||||
import de.jeanlucmakiola.floret.components.CustomExpandRow
|
||||
import de.jeanlucmakiola.floret.components.FullScreenPicker
|
||||
import de.jeanlucmakiola.floret.components.GroupedHint
|
||||
import de.jeanlucmakiola.floret.components.GroupedListInset
|
||||
import de.jeanlucmakiola.floret.components.GroupedRow
|
||||
import de.jeanlucmakiola.floret.components.GroupedSectionHeader
|
||||
import de.jeanlucmakiola.floret.components.GroupedSurface
|
||||
import de.jeanlucmakiola.floret.components.InlineTextField
|
||||
import de.jeanlucmakiola.floret.components.OptionPicker
|
||||
import de.jeanlucmakiola.floret.components.Position
|
||||
import de.jeanlucmakiola.floret.components.positionOf
|
||||
@@ -202,26 +209,58 @@ internal fun ListsPicker(
|
||||
}
|
||||
}
|
||||
|
||||
/** The tag a tag condition names, from the ones in use. */
|
||||
/** The tag a tag condition names: one in use, or another one typed in. */
|
||||
@Composable
|
||||
internal fun TagPicker(tags: List<String>, selected: String?, onSelect: (String) -> Unit, onDismiss: () -> Unit) {
|
||||
val options = remember(tags, selected) {
|
||||
(tags + listOfNotNull(selected)).distinct().sortedWith(String.CASE_INSENSITIVE_ORDER)
|
||||
}
|
||||
if (options.isEmpty()) {
|
||||
FullScreenPicker(title = stringResource(R.string.filter_section_tags), onDismiss = onDismiss) {
|
||||
GroupedHint(stringResource(R.string.filter_tags_none))
|
||||
val pick = { tag: String ->
|
||||
onSelect(tag)
|
||||
onDismiss()
|
||||
}
|
||||
FullScreenPicker(title = stringResource(R.string.filter_section_tags), onDismiss = onDismiss) {
|
||||
if (options.isEmpty()) GroupedHint(stringResource(R.string.filter_tags_none))
|
||||
val count = options.size + 1
|
||||
options.forEachIndexed { index, tag ->
|
||||
GroupedRow(
|
||||
title = tag,
|
||||
position = positionOf(index, count),
|
||||
checked = tag == selected,
|
||||
onClick = { pick(tag) },
|
||||
)
|
||||
}
|
||||
return
|
||||
var expanded by rememberSaveable { mutableStateOf(options.isEmpty()) }
|
||||
var typed by rememberSaveable { mutableStateOf("") }
|
||||
CustomExpandRow(
|
||||
title = stringResource(R.string.filter_tag_other),
|
||||
position = positionOf(options.size, count),
|
||||
expanded = expanded,
|
||||
onExpandedChange = { expanded = it },
|
||||
) {
|
||||
GroupedSurface(position = Position.Bottom, modifier = Modifier.padding(horizontal = GroupedListInset)) {
|
||||
Row(
|
||||
modifier = Modifier.padding(start = 16.dp, end = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
InlineTextField(
|
||||
value = typed,
|
||||
onValueChange = { typed = it },
|
||||
placeholder = stringResource(R.string.filter_tag_other_hint),
|
||||
capitalization = KeyboardCapitalization.None,
|
||||
imeAction = ImeAction.Done,
|
||||
onImeAction = { typed.trim().takeIf { it.isNotEmpty() }?.let(pick) },
|
||||
modifier = Modifier.weight(1f).padding(vertical = 12.dp),
|
||||
)
|
||||
TextButton(
|
||||
onClick = { pick(typed.trim()) },
|
||||
enabled = typed.isNotBlank(),
|
||||
) { Text(stringResource(R.string.reminder_custom_set)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
}
|
||||
OptionPicker(
|
||||
title = stringResource(R.string.filter_section_tags),
|
||||
options = options,
|
||||
selected = selected,
|
||||
label = { it.orEmpty() },
|
||||
onSelect = { it?.let(onSelect) },
|
||||
onDismiss = onDismiss,
|
||||
)
|
||||
}
|
||||
|
||||
/** The priority a priority condition asks for at least. */
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import de.jeanlucmakiola.agendula.domain.smartListNamed
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
import kotlin.time.Instant
|
||||
@@ -35,7 +36,6 @@ import de.jeanlucmakiola.agendula.ui.filters.RuleEditResult
|
||||
import de.jeanlucmakiola.agendula.ui.filters.RuleEditScreen
|
||||
import de.jeanlucmakiola.agendula.ui.filters.RuleEditViewModel
|
||||
import de.jeanlucmakiola.agendula.ui.filters.RulePurpose
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import de.jeanlucmakiola.agendula.ui.imports.ImportScreen
|
||||
import de.jeanlucmakiola.agendula.ui.lists.ListsScreen
|
||||
import de.jeanlucmakiola.agendula.ui.settings.SettingsScreen
|
||||
|
||||
@@ -355,6 +355,8 @@
|
||||
<string name="filter_value_no_list">No list</string>
|
||||
<string name="filter_lists_none">No lists yet.</string>
|
||||
<string name="filter_tags_none">No open task has a tag yet.</string>
|
||||
<string name="filter_tag_other">Other tag…</string>
|
||||
<string name="filter_tag_other_hint">Tag</string>
|
||||
<string name="filter_template_empty">Start empty</string>
|
||||
<string name="filter_template_empty_hint">Pick every rule yourself</string>
|
||||
<string name="filter_templates_header">Templates</string>
|
||||
|
||||
Reference in new issue
Block a user