- Optimize the logic of obtaining the model number of Xiaomi devices

- Add custom transparency settings, adjust the default transparency in dark color mode
This commit is contained in:
ShirkNeko
2025-03-23 02:46:26 +08:00
parent 04db01cdbc
commit 82edd46e0e
4 changed files with 46 additions and 4 deletions

View File

@@ -489,7 +489,7 @@ private fun InfoCard() {
Spacer(Modifier.height(16.dp)) Spacer(Modifier.height(16.dp))
val deviceModel = Build.DEVICE val deviceModel = getDeviceModel(context)
InfoCardItem(stringResource(R.string.home_device_model), deviceModel) InfoCardItem(stringResource(R.string.home_device_model), deviceModel)
@@ -573,3 +573,21 @@ private fun WarningCardPreview() {
onClick = {}) 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
}
}

View File

@@ -58,6 +58,7 @@ fun saveCardConfig(context: Context) {
with(prefs.edit()) { with(prefs.edit()) {
putFloat("card_alpha", CardConfig.cardAlpha) putFloat("card_alpha", CardConfig.cardAlpha)
putBoolean("custom_background_enabled", CardConfig.cardElevation == 0.dp) putBoolean("custom_background_enabled", CardConfig.cardElevation == 0.dp)
putBoolean("is_custom_alpha_set", CardConfig.isCustomAlphaSet)
apply() apply()
} }
} }
@@ -117,10 +118,25 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
} }
// 初始化卡片配置 // 初始化卡片配置
val systemIsDark = isSystemInDarkTheme()
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
CardConfig.apply { CardConfig.apply {
cardAlpha = prefs.getFloat("card_alpha", 0.65f) cardAlpha = prefs.getFloat("card_alpha", 0.65f)
cardElevation = if (prefs.getBoolean("custom_background_enabled", false)) 0.dp else CardConfig.defaultElevation 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 isCustomBackgroundEnabled = false
CardConfig.cardElevation = CardConfig.defaultElevation CardConfig.cardElevation = CardConfig.defaultElevation
CardConfig.cardAlpha = 1f CardConfig.cardAlpha = 1f
CardConfig.isCustomAlphaSet = false
saveCardConfig(context) saveCardConfig(context)
cardAlpha = 0.65f
themeMode = 0
context.saveThemeMode(null)
} }
} }
) )
@@ -353,6 +373,8 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
onValueChange = { newValue -> onValueChange = { newValue ->
cardAlpha = newValue cardAlpha = newValue
CardConfig.cardAlpha = newValue CardConfig.cardAlpha = newValue
CardConfig.isCustomAlphaSet = true
prefs.edit().putBoolean("is_custom_alpha_set", true).apply()
prefs.edit().putFloat("card_alpha", newValue).apply() prefs.edit().putFloat("card_alpha", newValue).apply()
}, },
onValueChangeFinished = { onValueChangeFinished = {

View File

@@ -17,12 +17,14 @@ object CardConfig {
var cardAlpha by mutableStateOf(1f) var cardAlpha by mutableStateOf(1f)
var cardElevation by mutableStateOf(defaultElevation) var cardElevation by mutableStateOf(defaultElevation)
var isShadowEnabled by mutableStateOf(true) var isShadowEnabled by mutableStateOf(true)
var isCustomAlphaSet by mutableStateOf(false)
fun save(context: Context) { fun save(context: Context) {
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE) val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
prefs.edit().apply { prefs.edit().apply {
putFloat("card_alpha", cardAlpha) putFloat("card_alpha", cardAlpha)
putBoolean("custom_background_enabled", cardElevation == 0.dp) putBoolean("custom_background_enabled", cardElevation == 0.dp)
putBoolean("is_custom_alpha_set", isCustomAlphaSet)
apply() apply()
} }
} }
@@ -31,6 +33,7 @@ object CardConfig {
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE) val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
cardAlpha = prefs.getFloat("card_alpha", 1f) cardAlpha = prefs.getFloat("card_alpha", 1f)
cardElevation = if (prefs.getBoolean("custom_background_enabled", false)) 0.dp else defaultElevation cardElevation = if (prefs.getBoolean("custom_background_enabled", false)) 0.dp else defaultElevation
isCustomAlphaSet = prefs.getBoolean("is_custom_alpha_set", false)
} }
fun updateShadowEnabled(enabled: Boolean) { fun updateShadowEnabled(enabled: Boolean) {
@@ -39,9 +42,11 @@ object CardConfig {
} }
fun setDarkModeDefaults() { fun setDarkModeDefaults() {
if (!isCustomAlphaSet) {
cardAlpha = 0.5f cardAlpha = 0.5f
cardElevation = 0.dp cardElevation = 0.dp
} }
}
} }

View File

@@ -149,9 +149,6 @@ fun KernelSUTheme(
if (darkTheme && !dynamicColor) { if (darkTheme && !dynamicColor) {
CardConfig.setDarkModeDefaults() CardConfig.setDarkModeDefaults()
} else {
CardConfig.cardAlpha = 1f
CardConfig.cardElevation = CardConfig.defaultElevation
} }
CardConfig.updateShadowEnabled(!isDarkModeWithCustomBackground) CardConfig.updateShadowEnabled(!isDarkModeWithCustomBackground)