manager: make template ui work

This commit is contained in:
weishu
2023-06-06 17:53:24 +08:00
parent 6d1ee60d67
commit c5bc1c8b15

View File

@@ -144,20 +144,33 @@ private fun AppProfileInner(
Crossfade(targetState = isRootGranted, label = "") { current -> Crossfade(targetState = isRootGranted, label = "") { current ->
Column { Column {
if (current) { if (current) {
val mode = if (profile.rootUseDefault) { val initialMode = if (profile.rootUseDefault) {
Mode.Default Mode.Default
} else if (profile.rootTemplate != null) { } else if (profile.rootTemplate != null) {
Mode.Template Mode.Template
} else { } else {
Mode.Custom Mode.Custom
} }
var mode by remember {
mutableStateOf(initialMode)
}
ProfileBox(mode, true) { ProfileBox(mode, true) {
onProfileChange(profile.copy(rootUseDefault = it == Mode.Default)) // template mode shouldn't change profile here!
if (it == Mode.Default || it == Mode.Custom) {
onProfileChange(profile.copy(rootUseDefault = it == Mode.Default))
}
mode = it
} }
Crossfade(targetState = mode, label = "") { currentMode -> Crossfade(targetState = mode, label = "") { currentMode ->
if (currentMode == Mode.Template) { if (currentMode == Mode.Template) {
var expanded by remember { mutableStateOf(false) } var expanded by remember { mutableStateOf(false) }
var template by rememberSaveable { mutableStateOf("None") } val templateNone = "None"
var template by rememberSaveable {
mutableStateOf(
profile.rootTemplate
?: templateNone
)
}
ListItem(headlineContent = { ListItem(headlineContent = {
ExposedDropdownMenuBox( ExposedDropdownMenuBox(
expanded = expanded, expanded = expanded,
@@ -168,7 +181,17 @@ private fun AppProfileInner(
readOnly = true, readOnly = true,
label = { Text(stringResource(R.string.profile_template)) }, label = { Text(stringResource(R.string.profile_template)) },
value = template, value = template,
onValueChange = {}, onValueChange = {
if (template != templateNone) {
onProfileChange(
profile.copy(
rootTemplate = it,
rootUseDefault = false
)
)
template = it
}
},
trailingIcon = { trailingIcon = {
if (expanded) Icon(Icons.Filled.ArrowDropUp, null) if (expanded) Icon(Icons.Filled.ArrowDropUp, null)
else Icon(Icons.Filled.ArrowDropDown, null) else Icon(Icons.Filled.ArrowDropDown, null)