manager: show default value for app profile.

This commit is contained in:
weishu
2023-06-04 00:22:36 +08:00
parent 2d854f2f37
commit 807556f361
3 changed files with 20 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ fun SwitchItem(
title: String,
summary: String? = null,
checked: Boolean,
enabled: Boolean = true,
onCheckedChange: (Boolean) -> Unit
) {
ListItem(
@@ -24,7 +25,7 @@ fun SwitchItem(
{ Icon(icon, title) }
},
trailingContent = {
Switch(checked = checked, onCheckedChange = onCheckedChange)
Switch(checked = checked, enabled = enabled, onCheckedChange = onCheckedChange)
},
supportingContent = {
if (summary != null) {

View File

@@ -19,6 +19,7 @@ import me.weishu.kernelsu.ui.component.SwitchItem
fun AppProfileConfig(
modifier: Modifier = Modifier,
fixedName: Boolean,
enabled: Boolean,
profile: Natives.Profile,
onProfileChange: (Natives.Profile) -> Unit,
) {
@@ -33,7 +34,12 @@ fun AppProfileConfig(
SwitchItem(
title = stringResource(R.string.profile_unmount_modules),
checked = profile.umountModules,
checked = if (enabled) {
profile.umountModules
} else {
Natives.isDefaultUmountModules()
},
enabled = enabled,
onCheckedChange = { onProfileChange(profile.copy(umountModules = it)) }
)
}
@@ -43,7 +49,7 @@ fun AppProfileConfig(
@Composable
private fun AppProfileConfigPreview() {
var profile by remember { mutableStateOf(Natives.Profile("")) }
AppProfileConfig(fixedName = true, profile = profile) {
AppProfileConfig(fixedName = true, enabled = false, profile = profile) {
profile = it
}
}

View File

@@ -156,9 +156,11 @@ private fun AppProfileInner(
Mode.Default -> {
onProfileChange(profile.copy(rootUseDefault = true))
}
Mode.Template -> {
onProfileChange(profile.copy(rootUseDefault = false))
}
else -> {
onProfileChange(profile.copy(rootUseDefault = false))
}
@@ -199,10 +201,11 @@ private fun AppProfileInner(
var mode by rememberSaveable { mutableStateOf(Mode.Default) }
ProfileBox(mode, false) { mode = it }
Crossfade(targetState = mode, label = "") { currentMode ->
if (currentMode == Mode.Custom) {
val modifyEnabled = currentMode == Mode.Custom
AppProfileConfig(
fixedName = true,
profile = profile,
enabled = modifyEnabled,
onProfileChange = onProfileChange
)
}
@@ -210,7 +213,6 @@ private fun AppProfileInner(
}
}
}
}
}
private enum class Mode(@StringRes private val res: Int) {