This commit is contained in:
ShirkNeko
2025-06-02 02:11:40 +08:00
14 changed files with 121 additions and 5 deletions

View File

@@ -4,6 +4,8 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.ComponentName
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
@@ -106,6 +108,19 @@ fun saveCardConfig(context: Context) {
CardConfig.save(context)
}
fun toggleLauncherIcon(context: Context, useAlt: Boolean) {
val pm = context.packageManager
val main = ComponentName(context, MainActivity::class.java.name)
val alt = ComponentName(context, "${MainActivity::class.java.name}Alias")
if (useAlt) {
pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
pm.setComponentEnabledSetting(alt, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
} else {
pm.setComponentEnabledSetting(alt, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
}
}
@SuppressLint("LocalContextConfigurationRead", "ObsoleteSdkInt")
@OptIn(ExperimentalMaterial3Api::class)
@Destination<RootGraph>
@@ -341,6 +356,16 @@ fun MoreSettingsScreen() {
mutableStateOf(ThemeConfig.customBackgroundUri != null)
}
// Alternate icon state
var useAltIcon by remember { mutableStateOf(prefs.getBoolean("use_alt_icon", false)) }
val onUseAltIconChange = { newValue: Boolean ->
prefs.edit { putBoolean("use_alt_icon", newValue) }
useAltIcon = newValue
toggleLauncherIcon(context, newValue)
Toast.makeText(context, context.getString(R.string.icon_switched), Toast.LENGTH_SHORT).show()
}
// 图片编辑状态
var showImageEditor by remember { mutableStateOf(false) }
var selectedImageUri by remember { mutableStateOf<Uri?>(null) }
@@ -875,6 +900,16 @@ fun MoreSettingsScreen() {
SettingsCard(
title = stringResource(R.string.custom_settings)
) {
// 图标切换by lshwjgpt
SwitchItem(
icon = Icons.Default.Android,
title = stringResource(R.string.icon_switch_title),
summary = stringResource(R.string.icon_switch_summary),
checked = useAltIcon
) {
onUseAltIconChange(it)
}
// 添加简洁模式开关
SwitchItem(
icon = Icons.Filled.Brush,
@@ -1326,4 +1361,4 @@ private fun TopBar(
windowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
scrollBehavior = scrollBehavior
)
}
}