From 82edd46e0ea599e803cea1c95a664d4dd641ca75 Mon Sep 17 00:00:00 2001 From: ShirkNeko <2773800761@qq.com> Date: Sun, 23 Mar 2025 02:46:26 +0800 Subject: [PATCH] - Optimize the logic of obtaining the model number of Xiaomi devices - Add custom transparency settings, adjust the default transparency in dark color mode --- .../shirkneko/zako/sukisu/ui/screen/Home.kt | 20 ++++++++++++++++- .../zako/sukisu/ui/screen/MoreSettings.kt | 22 +++++++++++++++++++ .../zako/sukisu/ui/theme/CardManage.kt | 5 +++++ .../shirkneko/zako/sukisu/ui/theme/Theme.kt | 3 --- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt index b954775a..5dd45d2e 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt @@ -489,7 +489,7 @@ private fun InfoCard() { Spacer(Modifier.height(16.dp)) - val deviceModel = Build.DEVICE + val deviceModel = getDeviceModel(context) InfoCardItem(stringResource(R.string.home_device_model), deviceModel) @@ -572,4 +572,22 @@ private fun WarningCardPreview() { MaterialTheme.colorScheme.outlineVariant, onClick = {}) } +} + +private fun getDeviceModel(context: Context): String { + return try { + val marketName = context.getSystemService(Context.APP_OPS_SERVICE)?.let { appOps -> + val systemProperties = Class.forName("android.os.SystemProperties") + val getMethod = systemProperties.getMethod("get", String::class.java, String::class.java) + getMethod.invoke(null, "ro.product.marketname", "") as String + } ?: "" + + if (marketName.isNotEmpty()) { + marketName + } else { + Build.DEVICE + } + } catch (e: Exception) { + Build.DEVICE + } } \ No newline at end of file diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/MoreSettings.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/MoreSettings.kt index d66eab85..444561e5 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/MoreSettings.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/MoreSettings.kt @@ -58,6 +58,7 @@ fun saveCardConfig(context: Context) { with(prefs.edit()) { putFloat("card_alpha", CardConfig.cardAlpha) putBoolean("custom_background_enabled", CardConfig.cardElevation == 0.dp) + putBoolean("is_custom_alpha_set", CardConfig.isCustomAlphaSet) apply() } } @@ -117,10 +118,25 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) { } // 初始化卡片配置 + val systemIsDark = isSystemInDarkTheme() LaunchedEffect(Unit) { CardConfig.apply { cardAlpha = prefs.getFloat("card_alpha", 0.65f) cardElevation = if (prefs.getBoolean("custom_background_enabled", false)) 0.dp else CardConfig.defaultElevation + isCustomAlphaSet = prefs.getBoolean("is_custom_alpha_set", false) + + // 如果没有手动设置透明度,且是深色模式,则使用默认值 + if (!isCustomAlphaSet) { + val isDarkMode = ThemeConfig.forceDarkMode ?: systemIsDark + if (isDarkMode) { + cardAlpha = 0.5f + } + } + } + themeMode = when (ThemeConfig.forceDarkMode) { + true -> 2 + false -> 1 + null -> 0 } } @@ -335,7 +351,11 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) { isCustomBackgroundEnabled = false CardConfig.cardElevation = CardConfig.defaultElevation CardConfig.cardAlpha = 1f + CardConfig.isCustomAlphaSet = false saveCardConfig(context) + cardAlpha = 0.65f + themeMode = 0 + context.saveThemeMode(null) } } ) @@ -353,6 +373,8 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) { onValueChange = { newValue -> cardAlpha = newValue CardConfig.cardAlpha = newValue + CardConfig.isCustomAlphaSet = true + prefs.edit().putBoolean("is_custom_alpha_set", true).apply() prefs.edit().putFloat("card_alpha", newValue).apply() }, onValueChangeFinished = { diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/CardManage.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/CardManage.kt index e4e75a6b..535383dc 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/CardManage.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/CardManage.kt @@ -17,12 +17,14 @@ object CardConfig { var cardAlpha by mutableStateOf(1f) var cardElevation by mutableStateOf(defaultElevation) var isShadowEnabled by mutableStateOf(true) + var isCustomAlphaSet by mutableStateOf(false) fun save(context: Context) { val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE) prefs.edit().apply { putFloat("card_alpha", cardAlpha) putBoolean("custom_background_enabled", cardElevation == 0.dp) + putBoolean("is_custom_alpha_set", isCustomAlphaSet) apply() } } @@ -31,6 +33,7 @@ object CardConfig { val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE) cardAlpha = prefs.getFloat("card_alpha", 1f) cardElevation = if (prefs.getBoolean("custom_background_enabled", false)) 0.dp else defaultElevation + isCustomAlphaSet = prefs.getBoolean("is_custom_alpha_set", false) } fun updateShadowEnabled(enabled: Boolean) { @@ -39,8 +42,10 @@ object CardConfig { } fun setDarkModeDefaults() { + if (!isCustomAlphaSet) { cardAlpha = 0.5f cardElevation = 0.dp + } } } diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/Theme.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/Theme.kt index 4ef272eb..e95e96e8 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/Theme.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/theme/Theme.kt @@ -149,9 +149,6 @@ fun KernelSUTheme( if (darkTheme && !dynamicColor) { CardConfig.setDarkModeDefaults() - } else { - CardConfig.cardAlpha = 1f - CardConfig.cardElevation = CardConfig.defaultElevation } CardConfig.updateShadowEnabled(!isDarkModeWithCustomBackground)