manager: show App Profile manage screen when empty
This commit is contained in:
@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||||
import androidx.compose.material.icons.filled.ArrowDropUp
|
import androidx.compose.material.icons.filled.ArrowDropUp
|
||||||
|
import androidx.compose.material.icons.filled.Create
|
||||||
import androidx.compose.material.icons.filled.ReadMore
|
import androidx.compose.material.icons.filled.ReadMore
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@@ -36,6 +37,7 @@ import me.weishu.kernelsu.ui.viewmodel.getTemplateInfoById
|
|||||||
fun TemplateConfig(
|
fun TemplateConfig(
|
||||||
profile: Natives.Profile,
|
profile: Natives.Profile,
|
||||||
onViewTemplate: (id: String) -> Unit = {},
|
onViewTemplate: (id: String) -> Unit = {},
|
||||||
|
onManageTemplate: () -> Unit = {},
|
||||||
onProfileChange: (Natives.Profile) -> Unit
|
onProfileChange: (Natives.Profile) -> Unit
|
||||||
) {
|
) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
@@ -43,6 +45,7 @@ fun TemplateConfig(
|
|||||||
mutableStateOf(profile.rootTemplate ?: "")
|
mutableStateOf(profile.rootTemplate ?: "")
|
||||||
}
|
}
|
||||||
val profileTemplates = listAppProfileTemplates()
|
val profileTemplates = listAppProfileTemplates()
|
||||||
|
val noTemplates = profileTemplates.isEmpty()
|
||||||
|
|
||||||
ListItem(headlineContent = {
|
ListItem(headlineContent = {
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
@@ -55,13 +58,22 @@ fun TemplateConfig(
|
|||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
readOnly = true,
|
readOnly = true,
|
||||||
label = { Text(stringResource(R.string.profile_template)) },
|
label = { Text(stringResource(R.string.profile_template)) },
|
||||||
value = template,
|
value = template.ifEmpty { "None" },
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
if (expanded) Icon(Icons.Filled.ArrowDropUp, null)
|
if (noTemplates) {
|
||||||
|
IconButton(
|
||||||
|
onClick = onManageTemplate
|
||||||
|
) {
|
||||||
|
Icon(Icons.Filled.Create, null)
|
||||||
|
}
|
||||||
|
} else if (expanded) Icon(Icons.Filled.ArrowDropUp, null)
|
||||||
else Icon(Icons.Filled.ArrowDropDown, null)
|
else Icon(Icons.Filled.ArrowDropDown, null)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
if (profileTemplates.isEmpty()) {
|
||||||
|
return@ExposedDropdownMenuBox
|
||||||
|
}
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onDismissRequest = { expanded = false }
|
onDismissRequest = { expanded = false }
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ import me.weishu.kernelsu.ui.component.SwitchItem
|
|||||||
import me.weishu.kernelsu.ui.component.profile.AppProfileConfig
|
import me.weishu.kernelsu.ui.component.profile.AppProfileConfig
|
||||||
import me.weishu.kernelsu.ui.component.profile.RootProfileConfig
|
import me.weishu.kernelsu.ui.component.profile.RootProfileConfig
|
||||||
import me.weishu.kernelsu.ui.component.profile.TemplateConfig
|
import me.weishu.kernelsu.ui.component.profile.TemplateConfig
|
||||||
|
import me.weishu.kernelsu.ui.screen.destinations.AppProfileTemplateScreenDestination
|
||||||
import me.weishu.kernelsu.ui.screen.destinations.TemplateEditorScreenDestination
|
import me.weishu.kernelsu.ui.screen.destinations.TemplateEditorScreenDestination
|
||||||
import me.weishu.kernelsu.ui.util.LocalSnackbarHost
|
import me.weishu.kernelsu.ui.util.LocalSnackbarHost
|
||||||
import me.weishu.kernelsu.ui.util.forceStopApp
|
import me.weishu.kernelsu.ui.util.forceStopApp
|
||||||
@@ -121,6 +122,9 @@ fun AppProfileScreen(
|
|||||||
navigator.navigate(TemplateEditorScreenDestination(info))
|
navigator.navigate(TemplateEditorScreenDestination(info))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onManageTemplate = {
|
||||||
|
navigator.navigate(AppProfileTemplateScreenDestination())
|
||||||
|
},
|
||||||
onProfileChange = {
|
onProfileChange = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
if (it.allowSu && !it.rootUseDefault && it.rules.isNotEmpty()) {
|
if (it.allowSu && !it.rootUseDefault && it.rules.isNotEmpty()) {
|
||||||
@@ -148,6 +152,7 @@ private fun AppProfileInner(
|
|||||||
appIcon: @Composable () -> Unit,
|
appIcon: @Composable () -> Unit,
|
||||||
profile: Natives.Profile,
|
profile: Natives.Profile,
|
||||||
onViewTemplate: (id: String) -> Unit = {},
|
onViewTemplate: (id: String) -> Unit = {},
|
||||||
|
onManageTemplate: () -> Unit = {},
|
||||||
onProfileChange: (Natives.Profile) -> Unit,
|
onProfileChange: (Natives.Profile) -> Unit,
|
||||||
) {
|
) {
|
||||||
val isRootGranted = profile.allowSu
|
val isRootGranted = profile.allowSu
|
||||||
@@ -190,9 +195,12 @@ private fun AppProfileInner(
|
|||||||
}
|
}
|
||||||
Crossfade(targetState = mode, label = "") { currentMode ->
|
Crossfade(targetState = mode, label = "") { currentMode ->
|
||||||
if (currentMode == Mode.Template) {
|
if (currentMode == Mode.Template) {
|
||||||
TemplateConfig(profile = profile,
|
TemplateConfig(
|
||||||
|
profile = profile,
|
||||||
onViewTemplate = onViewTemplate,
|
onViewTemplate = onViewTemplate,
|
||||||
onProfileChange = onProfileChange)
|
onManageTemplate = onManageTemplate,
|
||||||
|
onProfileChange = onProfileChange
|
||||||
|
)
|
||||||
} else if (mode == Mode.Custom) {
|
} else if (mode == Mode.Custom) {
|
||||||
RootProfileConfig(
|
RootProfileConfig(
|
||||||
fixedName = true,
|
fixedName = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user