manager: Optimize slot selection dialog to remove unnecessary information

This commit is contained in:
ShirkNeko
2025-06-03 15:15:48 +08:00
parent 92f6f2f51e
commit ec0b26a174
3 changed files with 36 additions and 24 deletions

View File

@@ -1,6 +1,5 @@
package com.sukisu.ultra.ui.component package com.sukisu.ultra.ui.component
import android.content.Context
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.horizontalScroll
@@ -10,12 +9,10 @@ import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.sukisu.ultra.R import com.sukisu.ultra.R
import com.sukisu.ultra.ui.theme.ThemeConfig
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.SdStorage import androidx.compose.material.icons.filled.SdStorage
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@@ -32,13 +29,19 @@ fun SlotSelectionDialog(
onDismiss: () -> Unit, onDismiss: () -> Unit,
onSlotSelected: (String) -> Unit onSlotSelected: (String) -> Unit
) { ) {
val context = LocalContext.current
var currentSlot by remember { mutableStateOf<String?>(null) } var currentSlot by remember { mutableStateOf<String?>(null) }
var errorMessage by remember { mutableStateOf<String?>(null) } var errorMessage by remember { mutableStateOf<String?>(null) }
var selectedSlot by remember { mutableStateOf<String?>(null) }
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
try { try {
currentSlot = getCurrentSlot(context) currentSlot = getCurrentSlot()
// 设置默认选择为当前槽位
selectedSlot = when (currentSlot) {
"a" -> "a"
"b" -> "b"
else -> null
}
errorMessage = null errorMessage = null
} catch (e: Exception) { } catch (e: Exception) {
errorMessage = e.message errorMessage = e.message
@@ -103,12 +106,12 @@ fun SlotSelectionDialog(
val slotOptions = listOf( val slotOptions = listOf(
ListOption( ListOption(
titleText = stringResource(id = R.string.slot_a), titleText = stringResource(id = R.string.slot_a),
subtitleText = if (currentSlot == "a" || currentSlot == "_a") stringResource(id = R.string.currently_selected) else null, subtitleText = null,
icon = Icons.Filled.SdStorage icon = Icons.Filled.SdStorage
), ),
ListOption( ListOption(
titleText = stringResource(id = R.string.slot_b), titleText = stringResource(id = R.string.slot_b),
subtitleText = if (currentSlot == "b" || currentSlot == "_b") stringResource(id = R.string.currently_selected) else null, subtitleText = null,
icon = Icons.Filled.SdStorage icon = Icons.Filled.SdStorage
) )
) )
@@ -124,19 +127,20 @@ fun SlotSelectionDialog(
.fillMaxWidth() .fillMaxWidth()
.clip(MaterialTheme.shapes.medium) .clip(MaterialTheme.shapes.medium)
.background( .background(
color = if (option.subtitleText != null) { color = if (selectedSlot == when(index) {
0 -> "a"
else -> "b"
}) {
MaterialTheme.colorScheme.primary.copy(alpha = 0.9f) MaterialTheme.colorScheme.primary.copy(alpha = 0.9f)
} else { } else {
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f) MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
} }
) )
.clickable { .clickable {
onSlotSelected( selectedSlot = when(index) {
when (index) { 0 -> "a"
0 -> "a" else -> "b"
else -> "b" }
}
)
} }
.padding(vertical = 12.dp, horizontal = 16.dp), .padding(vertical = 12.dp, horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
@@ -144,7 +148,10 @@ fun SlotSelectionDialog(
Icon( Icon(
imageVector = option.icon, imageVector = option.icon,
contentDescription = null, contentDescription = null,
tint = if (option.subtitleText != null) { tint = if (selectedSlot == when(index) {
0 -> "a"
else -> "b"
}) {
MaterialTheme.colorScheme.onPrimary MaterialTheme.colorScheme.onPrimary
} else { } else {
MaterialTheme.colorScheme.primary MaterialTheme.colorScheme.primary
@@ -159,7 +166,10 @@ fun SlotSelectionDialog(
Text( Text(
text = option.titleText, text = option.titleText,
style = MaterialTheme.typography.titleMedium, style = MaterialTheme.typography.titleMedium,
color = if (option.subtitleText != null) { color = if (selectedSlot == when(index) {
0 -> "a"
else -> "b"
}) {
MaterialTheme.colorScheme.onPrimary MaterialTheme.colorScheme.onPrimary
} else { } else {
MaterialTheme.colorScheme.primary MaterialTheme.colorScheme.primary
@@ -169,7 +179,10 @@ fun SlotSelectionDialog(
Text( Text(
text = it, text = it,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = if (true) { color = if (selectedSlot == when(index) {
0 -> "a"
else -> "b"
}) {
MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.8f) MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.8f)
} else { } else {
MaterialTheme.colorScheme.onSurfaceVariant MaterialTheme.colorScheme.onSurfaceVariant
@@ -186,9 +199,10 @@ fun SlotSelectionDialog(
confirmButton = { confirmButton = {
TextButton( TextButton(
onClick = { onClick = {
currentSlot?.let { onSlotSelected(it) } selectedSlot?.let { onSlotSelected(it) }
onDismiss() onDismiss()
} },
enabled = selectedSlot != null
) { ) {
Text( Text(
text = stringResource(android.R.string.ok), text = stringResource(android.R.string.ok),
@@ -221,7 +235,7 @@ data class ListOption(
) )
// Utility function to get current slot // Utility function to get current slot
private fun getCurrentSlot(context: Context): String? { private fun getCurrentSlot(): String? {
return runCommandGetOutput(true, "getprop ro.boot.slot_suffix")?.let { return runCommandGetOutput(true, "getprop ro.boot.slot_suffix")?.let {
if (it.startsWith("_")) it.substring(1) else it if (it.startsWith("_")) it.substring(1) else it
} }

View File

@@ -289,7 +289,7 @@
<string name="horizon_getting_original_slot">获取原有槽位</string> <string name="horizon_getting_original_slot">获取原有槽位</string>
<string name="horizon_setting_target_slot">设置指定槽位</string> <string name="horizon_setting_target_slot">设置指定槽位</string>
<string name="horizon_restoring_original_slot">恢复默认槽位</string> <string name="horizon_restoring_original_slot">恢复默认槽位</string>
<string name="current_slot">当前槽位:%1$s </string> <string name="current_slot">当前系统默认槽位:%1$s </string>
<!-- Error Messages --> <!-- Error Messages -->
<string name="horizon_copy_failed">复制失败</string> <string name="horizon_copy_failed">复制失败</string>
<string name="horizon_unknown_error">未知错误</string> <string name="horizon_unknown_error">未知错误</string>
@@ -302,7 +302,6 @@
<string name="configuration">配置</string> <string name="configuration">配置</string>
<string name="app_settings">应用设置</string> <string name="app_settings">应用设置</string>
<string name="tools">工具</string> <string name="tools">工具</string>
<string name="currently_selected">当前</string>
<!-- String resources used in SuperUser --> <!-- String resources used in SuperUser -->
<string name="clear">清除</string> <string name="clear">清除</string>
<string name="apps_with_root">Root 权限应用</string> <string name="apps_with_root">Root 权限应用</string>

View File

@@ -291,7 +291,7 @@
<string name="horizon_getting_original_slot">Getting the original slot</string> <string name="horizon_getting_original_slot">Getting the original slot</string>
<string name="horizon_setting_target_slot">Setting the specified slot</string> <string name="horizon_setting_target_slot">Setting the specified slot</string>
<string name="horizon_restoring_original_slot">Restore Default Slot</string> <string name="horizon_restoring_original_slot">Restore Default Slot</string>
<string name="current_slot">Current Slot%1$s </string> <string name="current_slot">Current system default slot%1$s </string>
<!-- Error Messages --> <!-- Error Messages -->
<string name="horizon_copy_failed">Copy failed</string> <string name="horizon_copy_failed">Copy failed</string>
<string name="horizon_unknown_error">Unknown error</string> <string name="horizon_unknown_error">Unknown error</string>
@@ -304,7 +304,6 @@
<string name="configuration">Configure</string> <string name="configuration">Configure</string>
<string name="app_settings">Application Settings</string> <string name="app_settings">Application Settings</string>
<string name="tools">Tools</string> <string name="tools">Tools</string>
<string name="currently_selected">Currently</string>
<!-- String resources used in SuperUser --> <!-- String resources used in SuperUser -->
<string name="clear">Removals</string> <string name="clear">Removals</string>
<string name="apps_with_root">Applications with root privileges</string> <string name="apps_with_root">Applications with root privileges</string>