manager: Using SwitchItem instead of ListItem

This commit is contained in:
ShirkNeko
2025-06-01 00:07:17 +08:00
parent b551a54c8f
commit 7a62f91752
2 changed files with 68 additions and 144 deletions

View File

@@ -728,63 +728,46 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
} }
// 自定义背景开关 // 自定义背景开关
ListItem( SwitchItem(
headlineContent = { Text(stringResource(id = R.string.settings_custom_background)) }, icon = Icons.Filled.Wallpaper,
supportingContent = { Text(stringResource(id = R.string.settings_custom_background_summary)) }, title = stringResource(id = R.string.settings_custom_background),
leadingContent = { summary = stringResource(id = R.string.settings_custom_background_summary),
Icon( checked = isCustomBackgroundEnabled
Icons.Filled.Wallpaper, ) { isChecked ->
contentDescription = null, if (isChecked) {
tint = if (isCustomBackgroundEnabled) pickImageLauncher.launch("image/*")
MaterialTheme.colorScheme.primary } else {
else context.saveCustomBackground(null)
MaterialTheme.colorScheme.onSurfaceVariant isCustomBackgroundEnabled = false
) CardConfig.cardElevation
}, CardConfig.cardAlpha = 1f
trailingContent = { CardConfig.cardDim = 0f
Switch( CardConfig.isCustomAlphaSet = false
checked = isCustomBackgroundEnabled, CardConfig.isCustomDimSet = false
onCheckedChange = { isChecked -> CardConfig.isCustomBackgroundEnabled = false
if (isChecked) { saveCardConfig(context)
pickImageLauncher.launch("image/*") cardAlpha = 1f
} else { cardDim = 0f
context.saveCustomBackground(null)
isCustomBackgroundEnabled = false
CardConfig.cardElevation
CardConfig.cardAlpha = 1f
CardConfig.cardDim = 0f
CardConfig.isCustomAlphaSet = false
CardConfig.isCustomDimSet = false
CardConfig.isCustomBackgroundEnabled = false
saveCardConfig(context)
cardAlpha = 1f
cardDim = 0f
// 重置其他相关设置 // 重置其他相关设置
ThemeConfig.needsResetOnThemeChange = true ThemeConfig.needsResetOnThemeChange = true
ThemeConfig.preventBackgroundRefresh = false ThemeConfig.preventBackgroundRefresh = false
context.getSharedPreferences("theme_prefs", Context.MODE_PRIVATE) context.getSharedPreferences("theme_prefs", Context.MODE_PRIVATE)
.edit { .edit {
putBoolean( putBoolean(
"prevent_background_refresh", "prevent_background_refresh",
false false
) )
}
Toast.makeText(
context,
context.getString(R.string.background_removed),
Toast.LENGTH_SHORT
).show()
}
} }
)
}, Toast.makeText(
colors = ListItemDefaults.colors( context,
containerColor = Color.Transparent context.getString(R.string.background_removed),
) Toast.LENGTH_SHORT
) ).show()
}
}
// 透明度和亮度调节滑动条 // 透明度和亮度调节滑动条
AnimatedVisibility( AnimatedVisibility(

View File

@@ -158,17 +158,16 @@ fun SettingScreen(navigator: DestinationsNavigator) {
} }
KsuIsValid { KsuIsValid {
SwitchSettingItem( SwitchItem(
icon = Icons.Filled.FolderDelete, icon = Icons.Filled.FolderDelete,
title = stringResource(id = R.string.settings_umount_modules_default), title = stringResource(id = R.string.settings_umount_modules_default),
summary = stringResource(id = R.string.settings_umount_modules_default_summary), summary = stringResource(id = R.string.settings_umount_modules_default_summary),
checked = umountChecked, checked = umountChecked
onCheckedChange = { ) { enabled ->
if (Natives.setDefaultUmountModules(it)) { if (Natives.setDefaultUmountModules(enabled)) {
umountChecked = it umountChecked = enabled
}
} }
) }
} }
// SU 禁用开关(仅在兼容版本显示) // SU 禁用开关(仅在兼容版本显示)
@@ -177,18 +176,17 @@ fun SettingScreen(navigator: DestinationsNavigator) {
var isSuDisabled by rememberSaveable { var isSuDisabled by rememberSaveable {
mutableStateOf(!Natives.isSuEnabled()) mutableStateOf(!Natives.isSuEnabled())
} }
SwitchSettingItem( SwitchItem(
icon = Icons.Filled.RemoveModerator, icon = Icons.Filled.RemoveModerator,
title = stringResource(id = R.string.settings_disable_su), title = stringResource(id = R.string.settings_disable_su),
summary = stringResource(id = R.string.settings_disable_su_summary), summary = stringResource(id = R.string.settings_disable_su_summary),
checked = isSuDisabled, checked = isSuDisabled
onCheckedChange = { checked -> ) { enabled ->
val shouldEnable = !checked val shouldEnable = !enabled
if (Natives.setSuEnabled(shouldEnable)) { if (Natives.setSuEnabled(shouldEnable)) {
isSuDisabled = !shouldEnable isSuDisabled = enabled
}
} }
) }
} }
} }
} }
@@ -220,16 +218,15 @@ fun SettingScreen(navigator: DestinationsNavigator) {
prefs.getBoolean("check_update", true) prefs.getBoolean("check_update", true)
) )
} }
SwitchSettingItem( SwitchItem(
icon = Icons.Filled.Update, icon = Icons.Filled.Update,
title = stringResource(id = R.string.settings_check_update), title = stringResource(id = R.string.settings_check_update),
summary = stringResource(id = R.string.settings_check_update_summary), summary = stringResource(id = R.string.settings_check_update_summary),
checked = checkUpdate, checked = checkUpdate
onCheckedChange = { ) { enabled ->
prefs.edit {putBoolean("check_update", it) } prefs.edit { putBoolean("check_update", enabled) }
checkUpdate = it checkUpdate = enabled
} }
)
// WebUI引擎选择 // WebUI引擎选择
KsuIsValid { KsuIsValid {
@@ -304,32 +301,30 @@ fun SettingScreen(navigator: DestinationsNavigator) {
) )
} }
KsuIsValid { KsuIsValid {
SwitchSettingItem( SwitchItem(
icon = Icons.Filled.DeveloperMode, icon = Icons.Filled.DeveloperMode,
title = stringResource(id = R.string.enable_web_debugging), title = stringResource(id = R.string.enable_web_debugging),
summary = stringResource(id = R.string.enable_web_debugging_summary), summary = stringResource(id = R.string.enable_web_debugging_summary),
checked = enableWebDebugging, checked = enableWebDebugging
onCheckedChange = { ) { enabled ->
prefs.edit { putBoolean("enable_web_debugging", it) } prefs.edit { putBoolean("enable_web_debugging", enabled) }
enableWebDebugging = it enableWebDebugging = enabled
} }
)
AnimatedVisibility( AnimatedVisibility(
visible = enableWebDebugging && selectedEngine == "wx", visible = enableWebDebugging && selectedEngine == "wx",
enter = fadeIn() + expandVertically(), enter = fadeIn() + expandVertically(),
exit = fadeOut() + shrinkVertically() exit = fadeOut() + shrinkVertically()
) { ) {
SwitchSettingItem( SwitchItem(
icon = Icons.Filled.FormatListNumbered, icon = Icons.Filled.FormatListNumbered,
title = stringResource(id = R.string.use_webuix_eruda), title = stringResource(id = R.string.use_webuix_eruda),
summary = stringResource(id = R.string.use_webuix_eruda_summary), summary = stringResource(id = R.string.use_webuix_eruda_summary),
checked = useWebUIXEruda, checked = useWebUIXEruda
onCheckedChange = { ) { enabled ->
prefs.edit { putBoolean("use_webuix_eruda", it) } prefs.edit { putBoolean("use_webuix_eruda", enabled) }
useWebUIXEruda = it useWebUIXEruda = enabled
} }
)
} }
} }
@@ -558,60 +553,6 @@ fun SettingItem(
} }
} }
@Composable
fun SwitchSettingItem(
icon: ImageVector,
title: String,
summary: String? = null,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.clickable { onCheckedChange(!checked) }
.padding(horizontal = 16.dp, vertical = 12.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier
.padding(end = 16.dp)
.size(24.dp)
)
Column(modifier = Modifier.weight(1f)) {
Text(
text = title,
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onSurface
)
if (summary != null) {
Text(
text = summary,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = checked,
onCheckedChange = onCheckedChange,
colors = SwitchDefaults.colors(
checkedThumbColor = MaterialTheme.colorScheme.onPrimary,
checkedTrackColor = MaterialTheme.colorScheme.primary,
checkedIconColor = MaterialTheme.colorScheme.primary,
uncheckedThumbColor = MaterialTheme.colorScheme.outline,
uncheckedTrackColor = MaterialTheme.colorScheme.surfaceVariant,
uncheckedIconColor = MaterialTheme.colorScheme.surfaceVariant
)
)
}
}
@Composable @Composable
fun UninstallItem( fun UninstallItem(
navigator: DestinationsNavigator, navigator: DestinationsNavigator,