From 294caf3debdeac666329844bcf825a93335b4647 Mon Sep 17 00:00:00 2001 From: weishu Date: Sat, 21 Oct 2023 13:54:32 +0800 Subject: [PATCH] manager: show App Profile manage screen when empty --- .../ui/component/profile/TemplateConfig.kt | 16 ++++++++++++++-- .../me/weishu/kernelsu/ui/screen/AppProfile.kt | 14 +++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/component/profile/TemplateConfig.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/component/profile/TemplateConfig.kt index 09978f055183..b1ed8a8b9d99 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/component/profile/TemplateConfig.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/component/profile/TemplateConfig.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material.icons.filled.ArrowDropUp +import androidx.compose.material.icons.filled.Create import androidx.compose.material.icons.filled.ReadMore import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.ExperimentalMaterial3Api @@ -36,6 +37,7 @@ import me.weishu.kernelsu.ui.viewmodel.getTemplateInfoById fun TemplateConfig( profile: Natives.Profile, onViewTemplate: (id: String) -> Unit = {}, + onManageTemplate: () -> Unit = {}, onProfileChange: (Natives.Profile) -> Unit ) { var expanded by remember { mutableStateOf(false) } @@ -43,6 +45,7 @@ fun TemplateConfig( mutableStateOf(profile.rootTemplate ?: "") } val profileTemplates = listAppProfileTemplates() + val noTemplates = profileTemplates.isEmpty() ListItem(headlineContent = { ExposedDropdownMenuBox( @@ -55,13 +58,22 @@ fun TemplateConfig( .fillMaxWidth(), readOnly = true, label = { Text(stringResource(R.string.profile_template)) }, - value = template, + value = template.ifEmpty { "None" }, onValueChange = {}, 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) }, ) + if (profileTemplates.isEmpty()) { + return@ExposedDropdownMenuBox + } ExposedDropdownMenu( expanded = expanded, onDismissRequest = { expanded = false } diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/AppProfile.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/AppProfile.kt index 8e372fcd90ec..cd98731f86c3 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/AppProfile.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/AppProfile.kt @@ -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.RootProfileConfig 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.util.LocalSnackbarHost import me.weishu.kernelsu.ui.util.forceStopApp @@ -117,10 +118,13 @@ fun AppProfileScreen( }, profile = profile, onViewTemplate = { - getTemplateInfoById(it)?.let { info-> + getTemplateInfoById(it)?.let { info -> navigator.navigate(TemplateEditorScreenDestination(info)) } }, + onManageTemplate = { + navigator.navigate(AppProfileTemplateScreenDestination()) + }, onProfileChange = { scope.launch { if (it.allowSu && !it.rootUseDefault && it.rules.isNotEmpty()) { @@ -148,6 +152,7 @@ private fun AppProfileInner( appIcon: @Composable () -> Unit, profile: Natives.Profile, onViewTemplate: (id: String) -> Unit = {}, + onManageTemplate: () -> Unit = {}, onProfileChange: (Natives.Profile) -> Unit, ) { val isRootGranted = profile.allowSu @@ -190,9 +195,12 @@ private fun AppProfileInner( } Crossfade(targetState = mode, label = "") { currentMode -> if (currentMode == Mode.Template) { - TemplateConfig(profile = profile, + TemplateConfig( + profile = profile, onViewTemplate = onViewTemplate, - onProfileChange = onProfileChange) + onManageTemplate = onManageTemplate, + onProfileChange = onProfileChange + ) } else if (mode == Mode.Custom) { RootProfileConfig( fixedName = true,