From 32cdcc6fbe9c88db21ca2b7ba068f8458dfd95c9 Mon Sep 17 00:00:00 2001 From: rifsxd Date: Wed, 28 May 2025 17:57:46 +0600 Subject: [PATCH] manager: improve layout and look of module cards --- .../com/rifsxd/ksunext/ui/screen/Module.kt | 249 ++++++++---------- manager/app/src/main/res/values/strings.xml | 2 + 2 files changed, 110 insertions(+), 141 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt index b5803e5d..a94646d0 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt @@ -113,6 +113,7 @@ import com.rifsxd.ksunext.ui.webui.WebUIXActivity import androidx.core.net.toUri import com.dergoogler.mmrl.platform.model.ModuleConfig import com.dergoogler.mmrl.platform.model.ModuleConfig.Companion.asModuleConfig +import com.dergoogler.mmrl.ui.component.LabelItem @OptIn(ExperimentalMaterial3Api::class) @Destination @@ -670,6 +671,38 @@ fun ModuleItem( Column( modifier = Modifier.fillMaxWidth(0.8f) ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(6.dp) + ) { + // Enabled/Disabled indicator + LabelItem( + text = if (module.enabled) stringResource(R.string.enabled) else stringResource(R.string.disabled), + style = if (module.enabled) + com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy( + containerColor = MaterialTheme.colorScheme.primaryContainer, + contentColor = MaterialTheme.colorScheme.onPrimaryContainer + ) + else + com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy( + containerColor = MaterialTheme.colorScheme.errorContainer, + contentColor = MaterialTheme.colorScheme.onErrorContainer + ) + ) + // Update notifier indicator + if (updateUrl.isNotEmpty() && !module.remove) { + LabelItem( + text = stringResource(R.string.module_update), + style = com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy( + containerColor = MaterialTheme.colorScheme.secondaryContainer, + contentColor = MaterialTheme.colorScheme.onSecondaryContainer + ) + ) + } + } + + Spacer(modifier = Modifier.height(8.dp)) + Text( text = module.name, fontSize = MaterialTheme.typography.titleMedium.fontSize, @@ -723,18 +756,84 @@ fun ModuleItem( } } - Spacer(modifier = Modifier.weight(1f)) - Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End, ) { - Switch( - enabled = !module.update, - checked = module.enabled, - onCheckedChange = onCheckChanged, - interactionSource = if (!module.hasWebUi) interactionSource else null - ) + var menuExpanded by remember { mutableStateOf(false) } + IconButton(onClick = { menuExpanded = true }) { + Icon( + imageVector = Icons.Filled.MoreVert, + contentDescription = "Module options" + ) + } + DropdownMenu( + expanded = menuExpanded, + onDismissRequest = { menuExpanded = false } + ) { + // WebUI + if (module.hasWebUi) { + DropdownMenuItem( + text = { Text(stringResource(R.string.open)) }, + onClick = { + menuExpanded = false + onClick(module) + } + ) + } + // ActionScript + if (module.hasActionScript) { + DropdownMenuItem( + text = { Text(stringResource(R.string.action)) }, + onClick = { + menuExpanded = false + navigator.navigate(ExecuteModuleActionScreenDestination(module.dirId)) + viewModel.markNeedRefresh() + } + ) + } + // Update + if (updateUrl.isNotEmpty() && !module.remove) { + DropdownMenuItem( + text = { Text(stringResource(R.string.module_update)) }, + onClick = { + menuExpanded = false + onUpdate(module) + } + ) + } + // Enable/Disable + DropdownMenuItem( + text = { + Text( + if (module.enabled) stringResource(R.string.disable) + else stringResource(R.string.enable) + ) + }, + onClick = { + menuExpanded = false + onCheckChanged(!module.enabled) + } + ) + // Restore/Uninstall + if (module.remove) { + DropdownMenuItem( + text = { Text(stringResource(R.string.restore)) }, + onClick = { + menuExpanded = false + onRestore(module) + } + ) + } else { + DropdownMenuItem( + text = { Text(stringResource(R.string.uninstall)) }, + onClick = { + menuExpanded = false + onUninstall(module) + } + ) + } + } } } @@ -751,139 +850,7 @@ fun ModuleItem( textDecoration = textDecoration ) - Spacer(modifier = Modifier.height(16.dp)) - - HorizontalDivider(thickness = Dp.Hairline) - - Spacer(modifier = Modifier.height(4.dp)) - - Row( - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - if (module.hasActionScript) { - FilledTonalButton( - modifier = Modifier.defaultMinSize(52.dp, 32.dp), - enabled = !module.remove && module.enabled, - onClick = { - navigator.navigate(ExecuteModuleActionScreenDestination(module.dirId)) - viewModel.markNeedRefresh() - }, - contentPadding = ButtonDefaults.TextButtonContentPadding - ) { - Icon( - modifier = Modifier.size(20.dp), - imageVector = Icons.Outlined.PlayArrow, - contentDescription = null - ) - if (!module.hasWebUi && updateUrl.isEmpty()) { - Text( - modifier = Modifier.padding(start = 7.dp), - text = stringResource(R.string.action), - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize - ) - } - } - - Spacer(modifier = Modifier.weight(0.1f, true)) - } - - if (module.hasWebUi) { - FilledTonalButton( - modifier = Modifier.defaultMinSize(52.dp, 32.dp), - enabled = !module.remove && module.enabled, - onClick = { onClick(module) }, - interactionSource = interactionSource, - contentPadding = ButtonDefaults.TextButtonContentPadding - ) { - Icon( - modifier = Modifier.size(20.dp), - imageVector = Icons.AutoMirrored.Outlined.Wysiwyg, - contentDescription = null - ) - if (!module.hasActionScript && updateUrl.isEmpty()) { - Text( - modifier = Modifier.padding(start = 7.dp), - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize, - text = stringResource(R.string.open) - ) - } - } - } - - Spacer(modifier = Modifier.weight(1f, true)) - - if (updateUrl.isNotEmpty()) { - Button( - modifier = Modifier.defaultMinSize(52.dp, 32.dp), - enabled = !module.remove, - onClick = { onUpdate(module) }, - shape = ButtonDefaults.textShape, - contentPadding = ButtonDefaults.TextButtonContentPadding - ) { - Icon( - modifier = Modifier.size(20.dp), - imageVector = Icons.Outlined.Download, - contentDescription = null - ) - if (!module.hasActionScript || !module.hasWebUi) { - Text( - modifier = Modifier.padding(start = 7.dp), - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize, - text = stringResource(R.string.module_update) - ) - } - } - - Spacer(modifier = Modifier.weight(0.1f, true)) - } - - if (module.remove) { - FilledTonalButton( - modifier = Modifier.defaultMinSize(52.dp, 32.dp), - onClick = { onRestore(module) }, - contentPadding = ButtonDefaults.TextButtonContentPadding - ) { - Icon( - modifier = Modifier.size(20.dp), - imageVector = Icons.Outlined.Restore, - contentDescription = null - ) - if (!module.hasActionScript && !module.hasWebUi && updateUrl.isEmpty()) { - Text( - modifier = Modifier.padding(start = 7.dp), - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize, - text = stringResource(R.string.restore) - ) - } - } - } else { - FilledTonalButton( - modifier = Modifier.defaultMinSize(52.dp, 32.dp), - enabled = true, - onClick = { onUninstall(module) }, - contentPadding = ButtonDefaults.TextButtonContentPadding - ) { - Icon( - modifier = Modifier.size(20.dp), - imageVector = Icons.Outlined.Delete, - contentDescription = null - ) - if (!module.hasActionScript && !module.hasWebUi && updateUrl.isEmpty()) { - Text( - modifier = Modifier.padding(start = 7.dp), - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize, - text = stringResource(R.string.uninstall) - ) - } - } - } - } + Spacer(modifier = Modifier.height(6.dp)) } } } diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml index bf8b3d1f..2e4dcd38 100644 --- a/manager/app/src/main/res/values/strings.xml +++ b/manager/app/src/main/res/values/strings.xml @@ -23,6 +23,8 @@ Ask your kernel developer to integrate KernelSU Next! Kernel version Hook mode + Enable + Disable Enabled Disabled Supported