mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: modernize settings layout and choice dialogs
- Replace popup DropdownMenu in SettingsDropdown with standard Material 3 single-choice RadioButton dialog. - Standardize screen horizontal margins to 16dp and increase spacing between preference sections. - Insert outlineVariant HorizontalDividers between items inside each section card. - Apply RoundedCornerShape(12.dp) to OutlinedTextFields in Settings text dialogs. Assisted-by: Gemini 3.8 Flash
This commit is contained in:
@@ -1,18 +1,23 @@
|
||||
package com.topjohnwu.magisk.ui.component
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.ListItemDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -20,8 +25,11 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@@ -61,7 +69,6 @@ fun SettingsSwitch(
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsDropdown(
|
||||
title: String,
|
||||
@@ -72,30 +79,59 @@ fun SettingsDropdown(
|
||||
enabled: Boolean = true,
|
||||
onSelectedIndexChange: (Int) -> Unit
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
Box(modifier = modifier) {
|
||||
ListItem(
|
||||
headlineContent = { Text(title, style = MaterialTheme.typography.bodyLarge) },
|
||||
supportingContent = {
|
||||
val currentSummary = summary ?: items.getOrNull(selectedIndex) ?: ""
|
||||
if (currentSummary.isNotEmpty()) Text(currentSummary, style = MaterialTheme.typography.bodyMedium)
|
||||
},
|
||||
trailingContent = { Icon(Icons.Default.ArrowDropDown, contentDescription = null) },
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = Modifier.clickable(enabled = enabled, onClick = { expanded = true })
|
||||
)
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
|
||||
ListItem(
|
||||
headlineContent = { Text(title, style = MaterialTheme.typography.bodyLarge) },
|
||||
supportingContent = {
|
||||
val currentSummary = summary ?: items.getOrNull(selectedIndex) ?: ""
|
||||
if (currentSummary.isNotEmpty()) Text(currentSummary, style = MaterialTheme.typography.bodyMedium)
|
||||
},
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = modifier.clickable(enabled = enabled, onClick = { showDialog = true })
|
||||
)
|
||||
|
||||
if (showDialog) {
|
||||
MagiskDialog(
|
||||
onDismissRequest = { showDialog = false },
|
||||
title = title,
|
||||
dismissText = stringResource(android.R.string.cancel),
|
||||
onDismiss = { showDialog = false }
|
||||
) {
|
||||
items.forEachIndexed { index, item ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(item) },
|
||||
onClick = {
|
||||
onSelectedIndexChange(index)
|
||||
expanded = false
|
||||
val scrollState = rememberScrollState()
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(scrollState)
|
||||
.selectableGroup()
|
||||
) {
|
||||
items.forEachIndexed { index, item ->
|
||||
val isSelected = index == selectedIndex
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.selectable(
|
||||
selected = isSelected,
|
||||
onClick = {
|
||||
onSelectedIndexChange(index)
|
||||
showDialog = false
|
||||
},
|
||||
role = Role.RadioButton
|
||||
)
|
||||
.padding(vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
RadioButton(
|
||||
selected = isSelected,
|
||||
onClick = null
|
||||
)
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Text(
|
||||
text = item,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +147,6 @@ fun SmallTitle(
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = modifier.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
modifier = modifier.padding(start = 16.dp, top = 8.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
@@ -75,17 +76,17 @@ fun SettingsScreen(
|
||||
.padding(padding)
|
||||
.verticalScrollbar(scrollState, contentPadding = PaddingValues(vertical = 12.dp))
|
||||
.verticalScroll(scrollState)
|
||||
.padding(horizontal = 12.dp, vertical = 12.dp)
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||
) {
|
||||
CustomizationSection(viewModel = viewModel)
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Spacer(Modifier.height(16.dp))
|
||||
AppSettingsSection()
|
||||
if (Info.env.isActive) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Spacer(Modifier.height(16.dp))
|
||||
MagiskSection(viewModel = viewModel)
|
||||
}
|
||||
if (Info.showSuperUser) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Spacer(Modifier.height(16.dp))
|
||||
SuperuserSection(viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
@@ -134,6 +135,11 @@ private fun CustomizationSection(
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Color Mode
|
||||
val isDynamicColorSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
val resources = LocalResources.current
|
||||
@@ -163,6 +169,10 @@ private fun CustomizationSection(
|
||||
)
|
||||
|
||||
if (isRunningAsStub && ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.add_shortcut_title),
|
||||
summary = stringResource(CoreR.string.setting_add_shortcut_summary),
|
||||
@@ -211,6 +221,10 @@ private fun AppSettingsSection(
|
||||
|
||||
// Update Channel URL (for custom channel)
|
||||
if (updateChannel == Config.Value.CUSTOM_CHANNEL) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
if (showUrlDialog) {
|
||||
UpdateChannelUrlDialog(
|
||||
onDismiss = { showUrlDialog = false }
|
||||
@@ -223,6 +237,11 @@ private fun AppSettingsSection(
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// DoH Toggle
|
||||
var doh by remember { mutableStateOf(Config.doh) }
|
||||
SettingsSwitch(
|
||||
@@ -235,6 +254,11 @@ private fun AppSettingsSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Update Checker
|
||||
var checkUpdate by remember { mutableStateOf(Config.checkUpdate) }
|
||||
SettingsSwitch(
|
||||
@@ -247,6 +271,11 @@ private fun AppSettingsSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Download Path
|
||||
var showDownloadDialog by remember { mutableStateOf(false) }
|
||||
if (showDownloadDialog) {
|
||||
@@ -262,6 +291,11 @@ private fun AppSettingsSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Random Package Name
|
||||
var randName by remember { mutableStateOf(Config.randName) }
|
||||
SettingsSwitch(
|
||||
@@ -297,6 +331,11 @@ private fun MagiskSection(
|
||||
)
|
||||
|
||||
if (Const.Version.atLeast_24_0()) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Zygisk
|
||||
var zygisk by remember { mutableStateOf(Config.zygisk) }
|
||||
SettingsSwitch(
|
||||
@@ -313,6 +352,11 @@ private fun MagiskSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// DenyList
|
||||
val denyListEnabled by viewModel.denyListEnabled.collectAsStateWithLifecycle()
|
||||
SettingsSwitch(
|
||||
@@ -322,6 +366,11 @@ private fun MagiskSection(
|
||||
onCheckedChange = { viewModel.toggleDenyList(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// DenyList Config
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.settings_denylist_config_title),
|
||||
@@ -359,6 +408,10 @@ private fun SuperuserSection(
|
||||
Config.suTapjack = it
|
||||
}
|
||||
)
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
}
|
||||
|
||||
// Authentication
|
||||
@@ -379,6 +432,11 @@ private fun SuperuserSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Access Mode
|
||||
val accessEntries = remember {
|
||||
resources.getStringArray(CoreR.array.su_access).toList()
|
||||
@@ -394,6 +452,11 @@ private fun SuperuserSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Multiuser Mode
|
||||
val multiuserEntries = remember {
|
||||
resources.getStringArray(CoreR.array.multiuser_mode).toList()
|
||||
@@ -414,6 +477,11 @@ private fun SuperuserSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Mount Namespace Mode
|
||||
val namespaceEntries = remember {
|
||||
resources.getStringArray(CoreR.array.namespace).toList()
|
||||
@@ -433,6 +501,11 @@ private fun SuperuserSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Automatic Response
|
||||
val autoResponseEntries = remember {
|
||||
resources.getStringArray(CoreR.array.auto_response).toList()
|
||||
@@ -451,6 +524,11 @@ private fun SuperuserSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Request Timeout
|
||||
val timeoutEntries = remember {
|
||||
resources.getStringArray(CoreR.array.request_timeout).toList()
|
||||
@@ -469,6 +547,11 @@ private fun SuperuserSection(
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// SU Notification
|
||||
val notifEntries = remember {
|
||||
resources.getStringArray(CoreR.array.su_notification).toList()
|
||||
@@ -486,6 +569,10 @@ private fun SuperuserSection(
|
||||
|
||||
// Reauthenticate (SDK < O)
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
var reAuth by remember { mutableStateOf(Config.suReAuth) }
|
||||
SettingsSwitch(
|
||||
title = stringResource(CoreR.string.settings_su_reauth_title),
|
||||
@@ -500,6 +587,10 @@ private fun SuperuserSection(
|
||||
|
||||
// Restrict (version >= 30.1)
|
||||
if (Const.Version.atLeast_30_1()) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
var restrict by remember { mutableStateOf(Config.suRestrict) }
|
||||
SettingsSwitch(
|
||||
title = stringResource(CoreR.string.settings_su_restrict_title),
|
||||
@@ -540,6 +631,7 @@ private fun UpdateChannelUrlDialog(
|
||||
OutlinedTextField(
|
||||
value = url,
|
||||
onValueChange = { url = it },
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
@@ -573,6 +665,7 @@ private fun DownloadPathDialog(
|
||||
OutlinedTextField(
|
||||
value = path,
|
||||
onValueChange = { path = it },
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user