- 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:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,9 +149,6 @@ fun KernelSUTheme(
|
||||
|
||||
if (darkTheme && !dynamicColor) {
|
||||
CardConfig.setDarkModeDefaults()
|
||||
} else {
|
||||
CardConfig.cardAlpha = 1f
|
||||
CardConfig.cardElevation = CardConfig.defaultElevation
|
||||
}
|
||||
|
||||
CardConfig.updateShadowEnabled(!isDarkModeWithCustomBackground)
|
||||
|
||||
Reference in New Issue
Block a user