Browse Source

fix: 更新主题配置以支持自定义对比度设置

5151561 3 months ago
parent
commit
fcf8403d8d

+ 6 - 0
app/src/main/java/io/legado/app/ui/config/otherConfig/OtherConfigScreen.kt

@@ -22,6 +22,8 @@ import androidx.compose.ui.res.stringResource
 import androidx.compose.ui.unit.dp
 import androidx.lifecycle.compose.collectAsStateWithLifecycle
 import io.legado.app.R
+import io.legado.app.constant.PreferKey
+import io.legado.app.help.config.DsSync
 import io.legado.app.service.WebService
 import io.legado.app.ui.config.readMangaConfig.ReadMangaConfig
 import io.legado.app.ui.theme.LegadoTheme
@@ -40,6 +42,7 @@ import io.legado.app.ui.widget.components.topbar.GlassTopAppBarDefaults
 import io.legado.app.ui.widget.components.topbar.TopBarNavigationButton
 import io.legado.app.utils.restart
 import io.legado.app.utils.takePersistablePermissionSafely
+import kotlinx.coroutines.runBlocking
 import org.koin.androidx.compose.koinViewModel
 
 @OptIn(ExperimentalMaterial3Api::class)
@@ -104,6 +107,9 @@ fun OtherConfigScreen(
                     entryValues = stringArrayResource(R.array.language_value),
                     onValueChange = { newValue ->
                         OtherConfig.language = newValue
+                        // prefDelegate 的 DataStore 写入是异步的,restart() 会立刻杀进程,
+                        // 必须先同步落盘,否则下次启动从 DataStore 读回旧值,语言切换失效
+                        runBlocking { DsSync.putString(PreferKey.language, newValue) }
                         context.restart()
                     }
                 )

+ 1 - 3
app/src/main/java/io/legado/app/ui/config/themeConfig/ThemeConfig.kt

@@ -194,9 +194,7 @@ object ThemeConfig {
         postEvent(EventBus.RECREATE, "")
     }
 
-    var customContrast by prefDelegate(PreferKey.customContrast, "Default") {
-        postEvent(EventBus.RECREATE, "")
-    }
+    var customContrast by prefDelegate(PreferKey.customContrast, "Default")
 
     var launcherIcon by prefDelegate(PreferKey.launcherIcon, "ic_launcher")
 

+ 2 - 1
app/src/main/java/io/legado/app/ui/theme/AppTheme.kt

@@ -73,6 +73,7 @@ private fun AppThemeActual(
     val isPureBlack = ThemeConfig.isPureBlack
     val paletteStyleValue = ThemeConfig.paletteStyle
     val materialVersion = ThemeConfig.materialVersion
+    val customContrast = ThemeConfig.customContrast
     val composeEngine = ThemeConfig.composeEngine
     val customPrimary = ThemeConfig.cPrimary
     val customNightPrimary = ThemeConfig.cNPrimary
@@ -89,7 +90,7 @@ private fun AppThemeActual(
     val colorScheme = remember(
         context, appThemeMode, effectiveDarkTheme, isPureBlack, customPrimary, customNightPrimary,
         enableDeepPersonalization, customColors,
-        paletteStyleValue, materialVersion
+        paletteStyleValue, materialVersion, customContrast
     ) {
         if (appThemeMode == AppThemeMode.Custom &&
             enableDeepPersonalization &&