Sfoglia il codice sorgente

feat: 扩展 AppSettings 数据类,增加更多应用设置选项并更新相关逻辑

5151561 3 mesi fa
parent
commit
0378c06af2

+ 41 - 4
app/src/main/java/io/legado/app/data/local/preferences/AppSettings.kt

@@ -2,14 +2,51 @@ package io.legado.app.data.local.preferences
 
 
 import androidx.compose.runtime.Stable
 import androidx.compose.runtime.Stable
 
 
-/**
- * 全应用设置的“唯一真理模型” - 强类型、不可变、业务语义化
- */
 @Stable
 @Stable
 data class AppSettings(
 data class AppSettings(
     val darkTheme: Boolean = false,
     val darkTheme: Boolean = false,
     val language: String = "auto",
     val language: String = "auto",
     val readAloudSpeed: Int = 5,
     val readAloudSpeed: Int = 5,
     val textWeight: Int = 1,
     val textWeight: Int = 1,
-    val showBrightnessView: Boolean = true
+    val showBrightnessView: String = "1",
+    val screenOrientation: String = "0",
+    val keepLight: String = "0",
+    val hideStatusBar: Boolean = false,
+    val hideNavigationBar: Boolean = false,
+    val paddingDisplayCutouts: Boolean = false,
+    val titleBarMode: String = "1",
+    val readMenuBlurAlpha: Int = 60,
+    val readBodyToLh: Boolean = true,
+    val defaultSourceChangeAll: Boolean = true,
+    val textFullJustify: Boolean = true,
+    val textBottomJustify: Boolean = true,
+    val adaptSpecialStyle: Boolean = true,
+    val useZhLayout: Boolean = false,
+    val brightnessVwPos: String = "1",
+    val brightnessAuto: Boolean = false,
+    val useUnderline: Boolean = false,
+    val readSliderMode: String = "0",
+    val doubleHorizontalPage: String = "0",
+    val progressBarBehavior: String = "page",
+    val mouseWheelPage: Boolean = true,
+    val volumeKeyPage: Boolean = true,
+    val volumeKeyPageOnPlay: Boolean = true,
+    val keyPageOnLongPress: Boolean = false,
+    val pageTouchSlop: Int = 0,
+    val sliderVibrator: Boolean = false,
+    val selectVibrator: Boolean = false,
+    val autoChangeSource: Boolean = true,
+    val autoSuggestDayNight: Boolean = false,
+    val selectText: Boolean = true,
+    val noAnimScrollPage: Boolean = false,
+    val clickImgWay: String = "2",
+    val optimizeRender: Boolean = false,
+    val disableReturnKey: Boolean = false,
+    val expandTextMenu: Boolean = false,
+    val showSelectMenuIcon: Boolean = true,
+    val showReadTitleAddition: Boolean = true,
+    val autoReadSpeed: Int = 10,
+    val prevKeys: String = "",
+    val nextKeys: String = "",
+    val showMenuIcon: Boolean = true
 )
 )

+ 181 - 27
app/src/main/java/io/legado/app/data/local/preferences/LocalPreferencesRepository.kt

@@ -1,12 +1,12 @@
 package io.legado.app.data.local.preferences
 package io.legado.app.data.local.preferences
 
 
 import android.content.Context
 import android.content.Context
-import android.content.res.Configuration
 import androidx.datastore.preferences.core.Preferences
 import androidx.datastore.preferences.core.Preferences
 import androidx.datastore.preferences.core.edit
 import androidx.datastore.preferences.core.edit
 import androidx.datastore.preferences.core.emptyPreferences
 import androidx.datastore.preferences.core.emptyPreferences
 import io.legado.app.constant.PreferKey
 import io.legado.app.constant.PreferKey
 import io.legado.app.help.config.AppConfigStore
 import io.legado.app.help.config.AppConfigStore
+import io.legado.app.help.config.compatDsBoolean
 import io.legado.app.help.config.compatDsInt
 import io.legado.app.help.config.compatDsInt
 import io.legado.app.help.config.compatDsString
 import io.legado.app.help.config.compatDsString
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.CoroutineScope
@@ -25,23 +25,60 @@ class LocalPreferencesRepository(private val context: Context) {
     private val dataStore = context.localDataStore
     private val dataStore = context.localDataStore
     private val repositoryScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
     private val repositoryScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
 
 
-    // 唯一状态真理守护者:桥接自 AppConfigStore 并洗白历史脏类型
     val appSettings: StateFlow<AppSettings> = AppConfigStore.preferencesFlow
     val appSettings: StateFlow<AppSettings> = AppConfigStore.preferencesFlow
-        .map { preferences ->
-            val themeMode = preferences.compatDsString(PreferKey.themeMode) ?: "0"
-            val isDark = when (themeMode) {
-                "1" -> false
-                "2" -> true
-                else -> {
-                    context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
-                }
-            }
+        .map { prefs ->
             AppSettings(
             AppSettings(
-                darkTheme = isDark,
-                language = preferences.compatDsString(PreferKey.language) ?: "auto",
-                readAloudSpeed = preferences.compatDsInt(PreferKey.ttsSpeechRate) ?: 5,
-                textWeight = preferences.compatDsInt("textWeight") ?: 1,
-                showBrightnessView = preferences.compatDsString(PreferKey.showBrightnessView) != "0"
+                darkTheme = prefs.compatDsString(PreferKey.themeMode).let {
+                    when (it) {
+                        "1" -> false
+                        "2" -> true
+                        else -> false
+                    }
+                },
+                language = prefs.compatDsString(PreferKey.language) ?: "auto",
+                readAloudSpeed = prefs.compatDsInt(PreferKey.ttsSpeechRate) ?: 5,
+                textWeight = prefs.compatDsInt("textWeight") ?: 1,
+                showBrightnessView = prefs.compatDsString(PreferKey.showBrightnessView) ?: "1",
+                screenOrientation = prefs.compatDsString(PreferKey.screenOrientation) ?: "0",
+                keepLight = prefs.compatDsString(PreferKey.keepLight) ?: "0",
+                hideStatusBar = prefs.compatDsBoolean(PreferKey.hideStatusBar) ?: false,
+                hideNavigationBar = prefs.compatDsBoolean(PreferKey.hideNavigationBar) ?: false,
+                paddingDisplayCutouts = prefs.compatDsBoolean(PreferKey.paddingDisplayCutouts) ?: false,
+                titleBarMode = prefs.compatDsString(PreferKey.titleBarMode) ?: "1",
+                readMenuBlurAlpha = prefs.compatDsInt(PreferKey.readMenuBlurAlpha) ?: 60,
+                readBodyToLh = prefs.compatDsBoolean(PreferKey.readBodyToLh) ?: true,
+                defaultSourceChangeAll = prefs.compatDsBoolean(PreferKey.defaultSourceChangeAll) ?: true,
+                textFullJustify = prefs.compatDsBoolean(PreferKey.textFullJustify) ?: true,
+                textBottomJustify = prefs.compatDsBoolean(PreferKey.textBottomJustify) ?: true,
+                adaptSpecialStyle = prefs.compatDsBoolean(PreferKey.adaptSpecialStyle) ?: true,
+                useZhLayout = prefs.compatDsBoolean(PreferKey.useZhLayout) ?: false,
+                brightnessVwPos = prefs.compatDsString(PreferKey.brightnessVwPos) ?: "1",
+                brightnessAuto = prefs.compatDsBoolean(PreferKey.brightnessAuto) ?: false,
+                useUnderline = prefs.compatDsBoolean(PreferKey.useUnderline) ?: false,
+                readSliderMode = prefs.compatDsString(PreferKey.readSliderMode) ?: "0",
+                doubleHorizontalPage = prefs.compatDsString(PreferKey.doublePageHorizontal) ?: "0",
+                progressBarBehavior = prefs.compatDsString(PreferKey.progressBarBehavior) ?: "page",
+                mouseWheelPage = prefs.compatDsBoolean(PreferKey.mouseWheelPage) ?: true,
+                volumeKeyPage = prefs.compatDsBoolean(PreferKey.volumeKeyPage) ?: true,
+                volumeKeyPageOnPlay = prefs.compatDsBoolean(PreferKey.volumeKeyPageOnPlay) ?: true,
+                keyPageOnLongPress = prefs.compatDsBoolean(PreferKey.keyPageOnLongPress) ?: false,
+                pageTouchSlop = prefs.compatDsInt(PreferKey.pageTouchSlop) ?: 0,
+                sliderVibrator = prefs.compatDsBoolean(PreferKey.sliderVibrator) ?: false,
+                selectVibrator = prefs.compatDsBoolean(PreferKey.selectVibrator) ?: false,
+                autoChangeSource = prefs.compatDsBoolean(PreferKey.autoChangeSource) ?: true,
+                autoSuggestDayNight = prefs.compatDsBoolean(PreferKey.autoSuggestDayNight) ?: false,
+                selectText = prefs.compatDsBoolean(PreferKey.selectText) ?: true,
+                noAnimScrollPage = prefs.compatDsBoolean(PreferKey.noAnimScrollPage) ?: false,
+                clickImgWay = prefs.compatDsString(PreferKey.clickImgWay) ?: "2",
+                optimizeRender = prefs.compatDsBoolean(PreferKey.optimizeRender) ?: false,
+                disableReturnKey = prefs.compatDsBoolean(PreferKey.disableReturnKey) ?: false,
+                expandTextMenu = prefs.compatDsBoolean(PreferKey.expandTextMenu) ?: false,
+                showSelectMenuIcon = prefs.compatDsBoolean(PreferKey.showSelectMenuIcon) ?: true,
+                showReadTitleAddition = prefs.compatDsBoolean(PreferKey.showReadTitleAddition) ?: true,
+                autoReadSpeed = prefs.compatDsInt(PreferKey.autoReadSpeed) ?: 10,
+                prevKeys = prefs.compatDsString(PreferKey.prevKeys) ?: "",
+                nextKeys = prefs.compatDsString(PreferKey.nextKeys) ?: "",
+                showMenuIcon = prefs.compatDsBoolean(PreferKey.showMenuIcon) ?: true
             )
             )
         }.stateIn(
         }.stateIn(
             scope = repositoryScope,
             scope = repositoryScope,
@@ -49,32 +86,149 @@ class LocalPreferencesRepository(private val context: Context) {
             initialValue = AppSettings()
             initialValue = AppSettings()
         )
         )
 
 
-    /**
-     * 优雅的闭包更新变换,物理落盘统一差异化批量投递
-     */
     fun updateSettings(transform: (AppSettings) -> AppSettings) {
     fun updateSettings(transform: (AppSettings) -> AppSettings) {
         val current = appSettings.value
         val current = appSettings.value
         val updated = transform(current)
         val updated = transform(current)
 
 
-        val changedPairs = mutableMapOf<String, Any?>()
+        val changes = mutableMapOf<String, Any?>()
         if (updated.darkTheme != current.darkTheme) {
         if (updated.darkTheme != current.darkTheme) {
-            changedPairs[PreferKey.themeMode] = if (updated.darkTheme) "2" else "1"
+            changes[PreferKey.themeMode] = if (updated.darkTheme) "2" else "1"
         }
         }
         if (updated.language != current.language) {
         if (updated.language != current.language) {
-            changedPairs[PreferKey.language] = updated.language
+            changes[PreferKey.language] = updated.language
         }
         }
         if (updated.readAloudSpeed != current.readAloudSpeed) {
         if (updated.readAloudSpeed != current.readAloudSpeed) {
-            changedPairs[PreferKey.ttsSpeechRate] = updated.readAloudSpeed
+            changes[PreferKey.ttsSpeechRate] = updated.readAloudSpeed
         }
         }
         if (updated.textWeight != current.textWeight) {
         if (updated.textWeight != current.textWeight) {
-            changedPairs["textWeight"] = updated.textWeight
+            changes["textWeight"] = updated.textWeight
         }
         }
         if (updated.showBrightnessView != current.showBrightnessView) {
         if (updated.showBrightnessView != current.showBrightnessView) {
-            changedPairs[PreferKey.showBrightnessView] = if (updated.showBrightnessView) "1" else "0"
+            changes[PreferKey.showBrightnessView] = updated.showBrightnessView
+        }
+        if (updated.screenOrientation != current.screenOrientation) {
+            changes[PreferKey.screenOrientation] = updated.screenOrientation
+        }
+        if (updated.keepLight != current.keepLight) {
+            changes[PreferKey.keepLight] = updated.keepLight
+        }
+        if (updated.hideStatusBar != current.hideStatusBar) {
+            changes[PreferKey.hideStatusBar] = updated.hideStatusBar
+        }
+        if (updated.hideNavigationBar != current.hideNavigationBar) {
+            changes[PreferKey.hideNavigationBar] = updated.hideNavigationBar
+        }
+        if (updated.paddingDisplayCutouts != current.paddingDisplayCutouts) {
+            changes[PreferKey.paddingDisplayCutouts] = updated.paddingDisplayCutouts
+        }
+        if (updated.titleBarMode != current.titleBarMode) {
+            changes[PreferKey.titleBarMode] = updated.titleBarMode
+        }
+        if (updated.readMenuBlurAlpha != current.readMenuBlurAlpha) {
+            changes[PreferKey.readMenuBlurAlpha] = updated.readMenuBlurAlpha
+        }
+        if (updated.readBodyToLh != current.readBodyToLh) {
+            changes[PreferKey.readBodyToLh] = updated.readBodyToLh
+        }
+        if (updated.defaultSourceChangeAll != current.defaultSourceChangeAll) {
+            changes[PreferKey.defaultSourceChangeAll] = updated.defaultSourceChangeAll
+        }
+        if (updated.textFullJustify != current.textFullJustify) {
+            changes[PreferKey.textFullJustify] = updated.textFullJustify
+        }
+        if (updated.textBottomJustify != current.textBottomJustify) {
+            changes[PreferKey.textBottomJustify] = updated.textBottomJustify
+        }
+        if (updated.adaptSpecialStyle != current.adaptSpecialStyle) {
+            changes[PreferKey.adaptSpecialStyle] = updated.adaptSpecialStyle
+        }
+        if (updated.useZhLayout != current.useZhLayout) {
+            changes[PreferKey.useZhLayout] = updated.useZhLayout
+        }
+        if (updated.brightnessVwPos != current.brightnessVwPos) {
+            changes[PreferKey.brightnessVwPos] = updated.brightnessVwPos
+        }
+        if (updated.brightnessAuto != current.brightnessAuto) {
+            changes[PreferKey.brightnessAuto] = updated.brightnessAuto
+        }
+        if (updated.useUnderline != current.useUnderline) {
+            changes[PreferKey.useUnderline] = updated.useUnderline
+        }
+        if (updated.readSliderMode != current.readSliderMode) {
+            changes[PreferKey.readSliderMode] = updated.readSliderMode
+        }
+        if (updated.doubleHorizontalPage != current.doubleHorizontalPage) {
+            changes[PreferKey.doublePageHorizontal] = updated.doubleHorizontalPage
+        }
+        if (updated.progressBarBehavior != current.progressBarBehavior) {
+            changes[PreferKey.progressBarBehavior] = updated.progressBarBehavior
+        }
+        if (updated.mouseWheelPage != current.mouseWheelPage) {
+            changes[PreferKey.mouseWheelPage] = updated.mouseWheelPage
+        }
+        if (updated.volumeKeyPage != current.volumeKeyPage) {
+            changes[PreferKey.volumeKeyPage] = updated.volumeKeyPage
+        }
+        if (updated.volumeKeyPageOnPlay != current.volumeKeyPageOnPlay) {
+            changes[PreferKey.volumeKeyPageOnPlay] = updated.volumeKeyPageOnPlay
+        }
+        if (updated.keyPageOnLongPress != current.keyPageOnLongPress) {
+            changes[PreferKey.keyPageOnLongPress] = updated.keyPageOnLongPress
+        }
+        if (updated.pageTouchSlop != current.pageTouchSlop) {
+            changes[PreferKey.pageTouchSlop] = updated.pageTouchSlop
+        }
+        if (updated.sliderVibrator != current.sliderVibrator) {
+            changes[PreferKey.sliderVibrator] = updated.sliderVibrator
+        }
+        if (updated.selectVibrator != current.selectVibrator) {
+            changes[PreferKey.selectVibrator] = updated.selectVibrator
+        }
+        if (updated.autoChangeSource != current.autoChangeSource) {
+            changes[PreferKey.autoChangeSource] = updated.autoChangeSource
+        }
+        if (updated.autoSuggestDayNight != current.autoSuggestDayNight) {
+            changes[PreferKey.autoSuggestDayNight] = updated.autoSuggestDayNight
+        }
+        if (updated.selectText != current.selectText) {
+            changes[PreferKey.selectText] = updated.selectText
+        }
+        if (updated.noAnimScrollPage != current.noAnimScrollPage) {
+            changes[PreferKey.noAnimScrollPage] = updated.noAnimScrollPage
+        }
+        if (updated.clickImgWay != current.clickImgWay) {
+            changes[PreferKey.clickImgWay] = updated.clickImgWay
+        }
+        if (updated.optimizeRender != current.optimizeRender) {
+            changes[PreferKey.optimizeRender] = updated.optimizeRender
+        }
+        if (updated.disableReturnKey != current.disableReturnKey) {
+            changes[PreferKey.disableReturnKey] = updated.disableReturnKey
+        }
+        if (updated.expandTextMenu != current.expandTextMenu) {
+            changes[PreferKey.expandTextMenu] = updated.expandTextMenu
+        }
+        if (updated.showSelectMenuIcon != current.showSelectMenuIcon) {
+            changes[PreferKey.showSelectMenuIcon] = updated.showSelectMenuIcon
+        }
+        if (updated.showReadTitleAddition != current.showReadTitleAddition) {
+            changes[PreferKey.showReadTitleAddition] = updated.showReadTitleAddition
+        }
+        if (updated.autoReadSpeed != current.autoReadSpeed) {
+            changes[PreferKey.autoReadSpeed] = updated.autoReadSpeed
+        }
+        if (updated.prevKeys != current.prevKeys) {
+            changes[PreferKey.prevKeys] = updated.prevKeys
+        }
+        if (updated.nextKeys != current.nextKeys) {
+            changes[PreferKey.nextKeys] = updated.nextKeys
+        }
+        if (updated.showMenuIcon != current.showMenuIcon) {
+            changes[PreferKey.showMenuIcon] = updated.showMenuIcon
         }
         }
 
 
-        if (changedPairs.isNotEmpty()) {
-            AppConfigStore.putAll(changedPairs)
+        if (changes.isNotEmpty()) {
+            AppConfigStore.putAll(changes)
         }
         }
     }
     }
 
 

+ 42 - 42
app/src/main/java/io/legado/app/ui/config/readConfig/ReadConfigScreen.kt

@@ -13,9 +13,9 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
 import androidx.compose.ui.res.stringArrayResource
 import androidx.compose.ui.res.stringArrayResource
 import androidx.compose.ui.res.stringResource
 import androidx.compose.ui.res.stringResource
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.dp
-import androidx.lifecycle.compose.collectAsStateWithLifecycle
 import io.legado.app.R
 import io.legado.app.R
 import io.legado.app.ui.book.read.sheet.ClickActionConfigSheet
 import io.legado.app.ui.book.read.sheet.ClickActionConfigSheet
+import io.legado.app.ui.theme.LocalAppSettings
 import io.legado.app.ui.theme.adaptiveContentPadding
 import io.legado.app.ui.theme.adaptiveContentPadding
 import io.legado.app.ui.widget.components.AppScaffold
 import io.legado.app.ui.widget.components.AppScaffold
 import io.legado.app.ui.widget.components.SplicedColumnGroup
 import io.legado.app.ui.widget.components.SplicedColumnGroup
@@ -38,7 +38,7 @@ fun ReadConfigScreen(
     val scrollBehavior = GlassTopAppBarDefaults.defaultScrollBehavior()
     val scrollBehavior = GlassTopAppBarDefaults.defaultScrollBehavior()
     var showPageKeySheet by remember { mutableStateOf(false) }
     var showPageKeySheet by remember { mutableStateOf(false) }
     var showClickActionSheet by remember { mutableStateOf(false) }
     var showClickActionSheet by remember { mutableStateOf(false) }
-    val state by viewModel.uiState.collectAsStateWithLifecycle()
+    val settings = LocalAppSettings.current
 
 
     AppScaffold(
     AppScaffold(
         modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
         modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
@@ -63,7 +63,7 @@ fun ReadConfigScreen(
                 SplicedColumnGroup(title = stringResource(R.string.screen_settings)) {
                 SplicedColumnGroup(title = stringResource(R.string.screen_settings)) {
                 DropdownListSettingItem(
                 DropdownListSettingItem(
                     title = stringResource(R.string.screen_direction),
                     title = stringResource(R.string.screen_direction),
-                    selectedValue = state.screenOrientation,
+                    selectedValue = settings.screenOrientation,
                     displayEntries = stringArrayResource(R.array.screen_direction_title),
                     displayEntries = stringArrayResource(R.array.screen_direction_title),
                     entryValues = stringArrayResource(R.array.screen_direction_value),
                     entryValues = stringArrayResource(R.array.screen_direction_value),
                     onValueChange = {
                     onValueChange = {
@@ -73,7 +73,7 @@ fun ReadConfigScreen(
 
 
                 DropdownListSettingItem(
                 DropdownListSettingItem(
                     title = stringResource(R.string.keep_light),
                     title = stringResource(R.string.keep_light),
-                    selectedValue = state.keepLight,
+                    selectedValue = settings.keepLight,
                     displayEntries = stringArrayResource(R.array.screen_time_out),
                     displayEntries = stringArrayResource(R.array.screen_time_out),
                     entryValues = stringArrayResource(R.array.screen_time_out_value),
                     entryValues = stringArrayResource(R.array.screen_time_out_value),
                     onValueChange = {
                     onValueChange = {
@@ -83,7 +83,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.pt_hide_status_bar),
                     title = stringResource(R.string.pt_hide_status_bar),
-                    checked = state.hideStatusBar,
+                    checked = settings.hideStatusBar,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.HideStatusBarChanged(it))
                         viewModel.onIntent(ReadConfigIntent.HideStatusBarChanged(it))
                     }
                     }
@@ -91,7 +91,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.pt_hide_navigation_bar),
                     title = stringResource(R.string.pt_hide_navigation_bar),
-                    checked = state.hideNavigationBar,
+                    checked = settings.hideNavigationBar,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.HideNavigationBarChanged(it))
                         viewModel.onIntent(ReadConfigIntent.HideNavigationBarChanged(it))
                     }
                     }
@@ -99,7 +99,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.padding_display_cutouts),
                     title = stringResource(R.string.padding_display_cutouts),
-                    checked = state.paddingDisplayCutouts,
+                    checked = settings.paddingDisplayCutouts,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.PaddingDisplayCutoutsChanged(it))
                         viewModel.onIntent(ReadConfigIntent.PaddingDisplayCutoutsChanged(it))
                     }
                     }
@@ -107,7 +107,7 @@ fun ReadConfigScreen(
 
 
                 DropdownListSettingItem(
                 DropdownListSettingItem(
                     title = stringResource(R.string.title_bar_mode),
                     title = stringResource(R.string.title_bar_mode),
-                    selectedValue = state.titleBarMode,
+                    selectedValue = settings.titleBarMode,
                     displayEntries = stringArrayResource(R.array.title_bar_mode),
                     displayEntries = stringArrayResource(R.array.title_bar_mode),
                     entryValues = stringArrayResource(R.array.title_bar_mode_value),
                     entryValues = stringArrayResource(R.array.title_bar_mode_value),
                     onValueChange = {
                     onValueChange = {
@@ -117,8 +117,8 @@ fun ReadConfigScreen(
 
 
                 SliderSettingItem(
                 SliderSettingItem(
                     title = stringResource(R.string.menu_alpha),
                     title = stringResource(R.string.menu_alpha),
-                    description = stringResource(R.string.menu_alpha_sum, state.readMenuBlurAlpha),
-                    value = state.readMenuBlurAlpha.toFloat(),
+                    description = stringResource(R.string.menu_alpha_sum, settings.readMenuBlurAlpha),
+                    value = settings.readMenuBlurAlpha.toFloat(),
                     defaultValue = 60f,
                     defaultValue = 60f,
                     valueRange = 0f..100f,
                     valueRange = 0f..100f,
                     onValueChange = {
                     onValueChange = {
@@ -128,7 +128,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.read_body_to_lh),
                     title = stringResource(R.string.read_body_to_lh),
-                    checked = state.readBodyToLh,
+                    checked = settings.readBodyToLh,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.ReadBodyToLhChanged(it))
                         viewModel.onIntent(ReadConfigIntent.ReadBodyToLhChanged(it))
                     }
                     }
@@ -137,7 +137,7 @@ fun ReadConfigScreen(
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.read_change_all),
                     title = stringResource(R.string.read_change_all),
                     description = stringResource(R.string.read_change_all_s),
                     description = stringResource(R.string.read_change_all_s),
-                    checked = state.defaultSourceChangeAll,
+                    checked = settings.defaultSourceChangeAll,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.DefaultSourceChangeAllChanged(it))
                         viewModel.onIntent(ReadConfigIntent.DefaultSourceChangeAllChanged(it))
                     }
                     }
@@ -145,7 +145,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.text_full_justify),
                     title = stringResource(R.string.text_full_justify),
-                    checked = state.textFullJustify,
+                    checked = settings.textFullJustify,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.TextFullJustifyChanged(it))
                         viewModel.onIntent(ReadConfigIntent.TextFullJustifyChanged(it))
                     }
                     }
@@ -153,7 +153,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.text_bottom_justify),
                     title = stringResource(R.string.text_bottom_justify),
-                    checked = state.textBottomJustify,
+                    checked = settings.textBottomJustify,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.TextBottomJustifyChanged(it))
                         viewModel.onIntent(ReadConfigIntent.TextBottomJustifyChanged(it))
                     }
                     }
@@ -161,7 +161,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.adapt_special_style),
                     title = stringResource(R.string.adapt_special_style),
-                    checked = state.adaptSpecialStyle,
+                    checked = settings.adaptSpecialStyle,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.AdaptSpecialStyleChanged(it))
                         viewModel.onIntent(ReadConfigIntent.AdaptSpecialStyleChanged(it))
                     }
                     }
@@ -169,7 +169,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.use_zh_layout),
                     title = stringResource(R.string.use_zh_layout),
-                    checked = state.useZhLayout,
+                    checked = settings.useZhLayout,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.UseZhLayoutChanged(it))
                         viewModel.onIntent(ReadConfigIntent.UseZhLayoutChanged(it))
                     }
                     }
@@ -177,7 +177,7 @@ fun ReadConfigScreen(
 
 
                     DropdownListSettingItem(
                     DropdownListSettingItem(
                     title = stringResource(R.string.show_brightness_view),
                     title = stringResource(R.string.show_brightness_view),
-                        selectedValue = state.showBrightnessView,
+                        selectedValue = settings.showBrightnessView,
                         displayEntries = stringArrayResource(R.array.brightness_bar_mode_title),
                         displayEntries = stringArrayResource(R.array.brightness_bar_mode_title),
                         entryValues = stringArrayResource(R.array.brightness_bar_mode_value),
                         entryValues = stringArrayResource(R.array.brightness_bar_mode_value),
                         onValueChange = {
                         onValueChange = {
@@ -185,10 +185,10 @@ fun ReadConfigScreen(
                     }
                     }
                 )
                 )
 
 
-                    if (state.showBrightnessView == "2") {
+                    if (settings.showBrightnessView == "2") {
                         DropdownListSettingItem(
                         DropdownListSettingItem(
                             title = stringResource(R.string.brightness_bar_position),
                             title = stringResource(R.string.brightness_bar_position),
-                            selectedValue = state.brightnessVwPos,
+                            selectedValue = settings.brightnessVwPos,
                             displayEntries = stringArrayResource(R.array.brightness_bar_position_title),
                             displayEntries = stringArrayResource(R.array.brightness_bar_position_title),
                             entryValues = stringArrayResource(R.array.brightness_bar_position_value),
                             entryValues = stringArrayResource(R.array.brightness_bar_position_value),
                             onValueChange = {
                             onValueChange = {
@@ -199,7 +199,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.use_underline),
                     title = stringResource(R.string.use_underline),
-                    checked = state.useUnderline,
+                    checked = settings.useUnderline,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.UseUnderlineChanged(it))
                         viewModel.onIntent(ReadConfigIntent.UseUnderlineChanged(it))
                     }
                     }
@@ -209,7 +209,7 @@ fun ReadConfigScreen(
             SplicedColumnGroup(title = stringResource(R.string.page_control)) {
             SplicedColumnGroup(title = stringResource(R.string.page_control)) {
                 DropdownListSettingItem(
                 DropdownListSettingItem(
                     title = stringResource(R.string.read_slider_mode),
                     title = stringResource(R.string.read_slider_mode),
-                    selectedValue = state.readSliderMode,
+                    selectedValue = settings.readSliderMode,
                     displayEntries = stringArrayResource(R.array.read_slider_mode),
                     displayEntries = stringArrayResource(R.array.read_slider_mode),
                     entryValues = stringArrayResource(R.array.read_slider_mode_value),
                     entryValues = stringArrayResource(R.array.read_slider_mode_value),
                     onValueChange = {
                     onValueChange = {
@@ -219,7 +219,7 @@ fun ReadConfigScreen(
 
 
                 DropdownListSettingItem(
                 DropdownListSettingItem(
                     title = stringResource(R.string.double_page_horizontal),
                     title = stringResource(R.string.double_page_horizontal),
-                    selectedValue = state.doubleHorizontalPage,
+                    selectedValue = settings.doubleHorizontalPage,
                     displayEntries = stringArrayResource(R.array.double_page_title),
                     displayEntries = stringArrayResource(R.array.double_page_title),
                     entryValues = stringArrayResource(R.array.double_page_value),
                     entryValues = stringArrayResource(R.array.double_page_value),
                     onValueChange = {
                     onValueChange = {
@@ -229,7 +229,7 @@ fun ReadConfigScreen(
 
 
                 DropdownListSettingItem(
                 DropdownListSettingItem(
                     title = stringResource(R.string.progress_bar_behavior),
                     title = stringResource(R.string.progress_bar_behavior),
-                    selectedValue = state.progressBarBehavior,
+                    selectedValue = settings.progressBarBehavior,
                     displayEntries = stringArrayResource(R.array.progress_bar_behavior_title),
                     displayEntries = stringArrayResource(R.array.progress_bar_behavior_title),
                     entryValues = stringArrayResource(R.array.progress_bar_behavior_value),
                     entryValues = stringArrayResource(R.array.progress_bar_behavior_value),
                     onValueChange = {
                     onValueChange = {
@@ -239,7 +239,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.mouse_wheel_page),
                     title = stringResource(R.string.mouse_wheel_page),
-                    checked = state.mouseWheelPage,
+                    checked = settings.mouseWheelPage,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.MouseWheelPageChanged(it))
                         viewModel.onIntent(ReadConfigIntent.MouseWheelPageChanged(it))
                     }
                     }
@@ -247,7 +247,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.volume_key_page),
                     title = stringResource(R.string.volume_key_page),
-                    checked = state.volumeKeyPage,
+                    checked = settings.volumeKeyPage,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.VolumeKeyPageChanged(it))
                         viewModel.onIntent(ReadConfigIntent.VolumeKeyPageChanged(it))
                     }
                     }
@@ -255,7 +255,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.volume_key_page_on_play),
                     title = stringResource(R.string.volume_key_page_on_play),
-                    checked = state.volumeKeyPageOnPlay,
+                    checked = settings.volumeKeyPageOnPlay,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.VolumeKeyPageOnPlayChanged(it))
                         viewModel.onIntent(ReadConfigIntent.VolumeKeyPageOnPlayChanged(it))
                     }
                     }
@@ -263,7 +263,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.key_page_on_long_press),
                     title = stringResource(R.string.key_page_on_long_press),
-                    checked = state.keyPageOnLongPress,
+                    checked = settings.keyPageOnLongPress,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.KeyPageOnLongPressChanged(it))
                         viewModel.onIntent(ReadConfigIntent.KeyPageOnLongPressChanged(it))
                     }
                     }
@@ -273,9 +273,9 @@ fun ReadConfigScreen(
                     title = stringResource(R.string.page_touch_slop_title),
                     title = stringResource(R.string.page_touch_slop_title),
                     description = stringResource(
                     description = stringResource(
                         R.string.page_touch_slop_summary,
                         R.string.page_touch_slop_summary,
-                        state.pageTouchSlop
+                        settings.pageTouchSlop
                     ),
                     ),
-                    value = state.pageTouchSlop.toFloat(),
+                    value = settings.pageTouchSlop.toFloat(),
                     defaultValue = 0f,
                     defaultValue = 0f,
                     valueRange = 0f..1000f,
                     valueRange = 0f..1000f,
                     onValueChange = {
                     onValueChange = {
@@ -287,7 +287,7 @@ fun ReadConfigScreen(
                 SplicedColumnGroup(title = stringResource(R.string.other)) {
                 SplicedColumnGroup(title = stringResource(R.string.other)) {
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.enable_slider_vibrator),
                     title = stringResource(R.string.enable_slider_vibrator),
-                    checked = state.sliderVibrator,
+                    checked = settings.sliderVibrator,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.SliderVibratorChanged(it))
                         viewModel.onIntent(ReadConfigIntent.SliderVibratorChanged(it))
                     }
                     }
@@ -295,7 +295,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.enable_select_vibrator),
                     title = stringResource(R.string.enable_select_vibrator),
-                    checked = state.selectVibrator,
+                    checked = settings.selectVibrator,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.SelectVibratorChanged(it))
                         viewModel.onIntent(ReadConfigIntent.SelectVibratorChanged(it))
                     }
                     }
@@ -303,7 +303,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.auto_change_source),
                     title = stringResource(R.string.auto_change_source),
-                    checked = state.autoChangeSource,
+                    checked = settings.autoChangeSource,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.AutoChangeSourceChanged(it))
                         viewModel.onIntent(ReadConfigIntent.AutoChangeSourceChanged(it))
                     }
                     }
@@ -312,7 +312,7 @@ fun ReadConfigScreen(
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.auto_switch_theme_reminder_title),
                     title = stringResource(R.string.auto_switch_theme_reminder_title),
                     description = stringResource(R.string.auto_switch_theme_reminder_desc),
                     description = stringResource(R.string.auto_switch_theme_reminder_desc),
-                    checked = state.autoSuggestDayNight,
+                    checked = settings.autoSuggestDayNight,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.AutoSuggestDayNightChanged(it))
                         viewModel.onIntent(ReadConfigIntent.AutoSuggestDayNightChanged(it))
                     }
                     }
@@ -320,7 +320,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.selectText),
                     title = stringResource(R.string.selectText),
-                    checked = state.selectText,
+                    checked = settings.selectText,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.SelectTextChanged(it))
                         viewModel.onIntent(ReadConfigIntent.SelectTextChanged(it))
                     }
                     }
@@ -328,7 +328,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.no_anim_scroll_page),
                     title = stringResource(R.string.no_anim_scroll_page),
-                    checked = state.noAnimScrollPage,
+                    checked = settings.noAnimScrollPage,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.NoAnimScrollPageChanged(it))
                         viewModel.onIntent(ReadConfigIntent.NoAnimScrollPageChanged(it))
                     }
                     }
@@ -336,7 +336,7 @@ fun ReadConfigScreen(
 
 
                 DropdownListSettingItem(
                 DropdownListSettingItem(
                     title = stringResource(R.string.click_image_way),
                     title = stringResource(R.string.click_image_way),
-                    selectedValue = state.clickImgWay,
+                    selectedValue = settings.clickImgWay,
                     displayEntries = stringArrayResource(R.array.click_image_way_title),
                     displayEntries = stringArrayResource(R.array.click_image_way_title),
                     entryValues = stringArrayResource(R.array.click_image_way_value),
                     entryValues = stringArrayResource(R.array.click_image_way_value),
                     onValueChange = {
                     onValueChange = {
@@ -347,7 +347,7 @@ fun ReadConfigScreen(
                 if (CanvasRecorderFactory.isSupport) {
                 if (CanvasRecorderFactory.isSupport) {
                     SwitchSettingItem(
                     SwitchSettingItem(
                         title = stringResource(R.string.enable_optimize_render),
                         title = stringResource(R.string.enable_optimize_render),
-                        checked = state.optimizeRender,
+                        checked = settings.optimizeRender,
                         onCheckedChange = {
                         onCheckedChange = {
                             viewModel.onIntent(ReadConfigIntent.OptimizeRenderChanged(it))
                             viewModel.onIntent(ReadConfigIntent.OptimizeRenderChanged(it))
                         }
                         }
@@ -361,7 +361,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.disable_return_key),
                     title = stringResource(R.string.disable_return_key),
-                    checked = state.disableReturnKey,
+                    checked = settings.disableReturnKey,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.DisableReturnKeyChanged(it))
                         viewModel.onIntent(ReadConfigIntent.DisableReturnKeyChanged(it))
                     }
                     }
@@ -374,7 +374,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.show_read_title_addition),
                     title = stringResource(R.string.show_read_title_addition),
-                    checked = state.showReadTitleAddition,
+                    checked = settings.showReadTitleAddition,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.ShowReadTitleAdditionChanged(it))
                         viewModel.onIntent(ReadConfigIntent.ShowReadTitleAdditionChanged(it))
                     }
                     }
@@ -382,7 +382,7 @@ fun ReadConfigScreen(
 
 
                 SwitchSettingItem(
                 SwitchSettingItem(
                     title = stringResource(R.string.show_menu_icon),
                     title = stringResource(R.string.show_menu_icon),
-                    checked = state.showMenuIcon,
+                    checked = settings.showMenuIcon,
                     onCheckedChange = {
                     onCheckedChange = {
                         viewModel.onIntent(ReadConfigIntent.ShowMenuIconChanged(it))
                         viewModel.onIntent(ReadConfigIntent.ShowMenuIconChanged(it))
                     }
                     }
@@ -394,8 +394,8 @@ fun ReadConfigScreen(
 
 
     PageKeySheet(
     PageKeySheet(
         show = showPageKeySheet,
         show = showPageKeySheet,
-        prevKeys = state.prevKeys,
-        nextKeys = state.nextKeys,
+        prevKeys = settings.prevKeys,
+        nextKeys = settings.nextKeys,
         onDismissRequest = { showPageKeySheet = false },
         onDismissRequest = { showPageKeySheet = false },
         onConfirm = { prevKeys, nextKeys ->
         onConfirm = { prevKeys, nextKeys ->
             viewModel.onIntent(ReadConfigIntent.PageKeysChanged(prevKeys, nextKeys))
             viewModel.onIntent(ReadConfigIntent.PageKeysChanged(prevKeys, nextKeys))

+ 125 - 184
app/src/main/java/io/legado/app/ui/config/readConfig/ReadConfigViewModel.kt

@@ -1,188 +1,175 @@
 package io.legado.app.ui.config.readConfig
 package io.legado.app.ui.config.readConfig
 
 
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.ViewModel
-import androidx.lifecycle.viewModelScope
 import io.legado.app.constant.EventBus
 import io.legado.app.constant.EventBus
-import io.legado.app.data.repository.ReadPreferences
-import io.legado.app.data.repository.ReadSettingsRepository
-import io.legado.app.help.config.ReadBookConfig
+import io.legado.app.data.local.preferences.LocalPreferencesRepository
 import io.legado.app.model.ReadBook
 import io.legado.app.model.ReadBook
 import io.legado.app.ui.book.read.page.provider.ChapterProvider
 import io.legado.app.ui.book.read.page.provider.ChapterProvider
 import io.legado.app.utils.postEvent
 import io.legado.app.utils.postEvent
-import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.flow.stateIn
-import kotlinx.coroutines.launch
 
 
 class ReadConfigViewModel(
 class ReadConfigViewModel(
-    private val readSettingsRepository: ReadSettingsRepository
+    private val localPreferencesRepository: LocalPreferencesRepository
 ) : ViewModel() {
 ) : ViewModel() {
 
 
-    val uiState = readSettingsRepository.preferences.map { it.toUiState() }.stateIn(
-        scope = viewModelScope,
-        started = SharingStarted.WhileSubscribed(5_000),
-        initialValue = ReadConfigUiState()
-    )
-
     fun onIntent(intent: ReadConfigIntent) {
     fun onIntent(intent: ReadConfigIntent) {
-        viewModelScope.launch {
-            when (intent) {
-                is ReadConfigIntent.ScreenOrientationChanged -> {
-                    ReadConfig.screenOrientation = intent.value
-                }
+        when (intent) {
+            is ReadConfigIntent.ScreenOrientationChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(screenOrientation = intent.value) }
+            }
 
 
-                is ReadConfigIntent.KeepLightChanged -> {
-                    ReadConfig.keepLight = intent.value
-                }
+            is ReadConfigIntent.KeepLightChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(keepLight = intent.value) }
+            }
 
 
-                is ReadConfigIntent.HideStatusBarChanged -> {
-                    ReadBookConfig.hideStatusBar = intent.value
-                    postEvent(EventBus.UP_CONFIG, arrayListOf(0, 2))
-                }
+            is ReadConfigIntent.HideStatusBarChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(hideStatusBar = intent.value) }
+                postEvent(EventBus.UP_CONFIG, arrayListOf(0, 2))
+            }
 
 
-                is ReadConfigIntent.HideNavigationBarChanged -> {
-                    ReadBookConfig.hideNavigationBar = intent.value
-                    postEvent(EventBus.UP_CONFIG, arrayListOf(0, 2))
-                }
+            is ReadConfigIntent.HideNavigationBarChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(hideNavigationBar = intent.value) }
+                postEvent(EventBus.UP_CONFIG, arrayListOf(0, 2))
+            }
 
 
-                is ReadConfigIntent.PaddingDisplayCutoutsChanged -> {
-                    ReadConfig.paddingDisplayCutouts = intent.value
-                }
+            is ReadConfigIntent.PaddingDisplayCutoutsChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(paddingDisplayCutouts = intent.value) }
+            }
 
 
-                is ReadConfigIntent.TitleBarModeChanged -> {
-                    ReadConfig.titleBarMode = intent.value
-                }
+            is ReadConfigIntent.TitleBarModeChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(titleBarMode = intent.value) }
+            }
 
 
-                is ReadConfigIntent.ReadMenuBlurAlphaChanged -> {
-                    ReadBookConfig.readMenuBlurAlpha = intent.value
-                    postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
-                }
+            is ReadConfigIntent.ReadMenuBlurAlphaChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(readMenuBlurAlpha = intent.value) }
+                postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
+            }
 
 
-                is ReadConfigIntent.ReadBodyToLhChanged -> {
-                    ReadBookConfig.readBodyToLh = intent.value
-                }
+            is ReadConfigIntent.ReadBodyToLhChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(readBodyToLh = intent.value) }
+            }
 
 
-                is ReadConfigIntent.DefaultSourceChangeAllChanged -> {
-                    ReadConfig.defaultSourceChangeAll = intent.value
-                }
+            is ReadConfigIntent.DefaultSourceChangeAllChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(defaultSourceChangeAll = intent.value) }
+            }
 
 
-                is ReadConfigIntent.TextFullJustifyChanged -> {
-                    ReadBookConfig.textFullJustify = intent.value
-                    upLayout()
-                }
+            is ReadConfigIntent.TextFullJustifyChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(textFullJustify = intent.value) }
+                upLayout()
+            }
 
 
-                is ReadConfigIntent.TextBottomJustifyChanged -> {
-                    ReadBookConfig.textBottomJustify = intent.value
-                    upLayout()
-                }
+            is ReadConfigIntent.TextBottomJustifyChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(textBottomJustify = intent.value) }
+                upLayout()
+            }
 
 
-                is ReadConfigIntent.AdaptSpecialStyleChanged -> {
-                    ReadConfig.adaptSpecialStyle = intent.value
-                }
+            is ReadConfigIntent.AdaptSpecialStyleChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(adaptSpecialStyle = intent.value) }
+            }
 
 
-                is ReadConfigIntent.UseZhLayoutChanged -> {
-                    ReadBookConfig.useZhLayout = intent.value
-                    upLayout()
-                }
+            is ReadConfigIntent.UseZhLayoutChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(useZhLayout = intent.value) }
+                upLayout()
+            }
 
 
-                is ReadConfigIntent.ShowBrightnessViewChanged -> {
-                    ReadBookConfig.showBrightnessView = intent.value
-                }
+            is ReadConfigIntent.ShowBrightnessViewChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(showBrightnessView = intent.value) }
+            }
 
 
-                is ReadConfigIntent.BrightnessVwPosChanged -> {
-                    ReadBookConfig.brightnessVwPos = intent.value
-                }
+            is ReadConfigIntent.BrightnessVwPosChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(brightnessVwPos = intent.value) }
+            }
 
 
-                is ReadConfigIntent.UseUnderlineChanged -> {
-                    ReadConfig.useUnderline = intent.value
-                }
+            is ReadConfigIntent.UseUnderlineChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(useUnderline = intent.value) }
+            }
 
 
-                is ReadConfigIntent.ReadSliderModeChanged -> {
-                    ReadBookConfig.readSliderMode = intent.value
-                    postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
-                }
+            is ReadConfigIntent.ReadSliderModeChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(readSliderMode = intent.value) }
+                postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
+            }
 
 
-                is ReadConfigIntent.DoubleHorizontalPageChanged -> {
-                    ReadConfig.doubleHorizontalPage = intent.value
-                    upLayout()
-                }
+            is ReadConfigIntent.DoubleHorizontalPageChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(doubleHorizontalPage = intent.value) }
+                upLayout()
+            }
 
 
-                is ReadConfigIntent.ProgressBarBehaviorChanged -> {
-                    ReadConfig.progressBarBehavior = intent.value
-                    postEvent(EventBus.UP_SEEK_BAR, true)
-                }
+            is ReadConfigIntent.ProgressBarBehaviorChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(progressBarBehavior = intent.value) }
+                postEvent(EventBus.UP_SEEK_BAR, true)
+            }
 
 
-                is ReadConfigIntent.MouseWheelPageChanged -> {
-                    ReadConfig.mouseWheelPage = intent.value
-                }
+            is ReadConfigIntent.MouseWheelPageChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(mouseWheelPage = intent.value) }
+            }
 
 
-                is ReadConfigIntent.VolumeKeyPageChanged -> {
-                    ReadConfig.volumeKeyPage = intent.value
-                }
+            is ReadConfigIntent.VolumeKeyPageChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(volumeKeyPage = intent.value) }
+            }
 
 
-                is ReadConfigIntent.VolumeKeyPageOnPlayChanged -> {
-                    ReadConfig.volumeKeyPageOnPlay = intent.value
-                }
+            is ReadConfigIntent.VolumeKeyPageOnPlayChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(volumeKeyPageOnPlay = intent.value) }
+            }
 
 
-                is ReadConfigIntent.KeyPageOnLongPressChanged -> {
-                    ReadConfig.keyPageOnLongPress = intent.value
-                }
+            is ReadConfigIntent.KeyPageOnLongPressChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(keyPageOnLongPress = intent.value) }
+            }
 
 
-                is ReadConfigIntent.PageTouchSlopChanged -> {
-                    ReadConfig.pageTouchSlop = intent.value
-                    postEvent(EventBus.UP_CONFIG, arrayListOf(4))
-                }
+            is ReadConfigIntent.PageTouchSlopChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(pageTouchSlop = intent.value) }
+                postEvent(EventBus.UP_CONFIG, arrayListOf(4))
+            }
 
 
-                is ReadConfigIntent.SliderVibratorChanged -> {
-                    ReadConfig.sliderVibrator = intent.value
-                }
+            is ReadConfigIntent.SliderVibratorChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(sliderVibrator = intent.value) }
+            }
 
 
-                is ReadConfigIntent.SelectVibratorChanged -> {
-                    ReadConfig.selectVibrator = intent.value
-                }
+            is ReadConfigIntent.SelectVibratorChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(selectVibrator = intent.value) }
+            }
 
 
-                is ReadConfigIntent.AutoChangeSourceChanged -> {
-                    ReadConfig.autoChangeSource = intent.value
-                }
+            is ReadConfigIntent.AutoChangeSourceChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(autoChangeSource = intent.value) }
+            }
 
 
-                is ReadConfigIntent.AutoSuggestDayNightChanged -> {
-                    ReadConfig.autoSuggestDayNight = intent.value
-                }
+            is ReadConfigIntent.AutoSuggestDayNightChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(autoSuggestDayNight = intent.value) }
+            }
 
 
-                is ReadConfigIntent.SelectTextChanged -> {
-                    ReadConfig.selectText = intent.value
-                }
+            is ReadConfigIntent.SelectTextChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(selectText = intent.value) }
+            }
 
 
-                is ReadConfigIntent.NoAnimScrollPageChanged -> {
-                    ReadConfig.noAnimScrollPage = intent.value
-                    ReadBook.callBack?.upPageAnim()
-                }
+            is ReadConfigIntent.NoAnimScrollPageChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(noAnimScrollPage = intent.value) }
+                ReadBook.callBack?.upPageAnim()
+            }
 
 
-                is ReadConfigIntent.ClickImgWayChanged -> {
-                    ReadConfig.clickImgWay = intent.value
-                }
+            is ReadConfigIntent.ClickImgWayChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(clickImgWay = intent.value) }
+            }
 
 
-                is ReadConfigIntent.OptimizeRenderChanged -> {
-                    ReadConfig.optimizeRender = intent.value
-                    upStyle()
-                }
+            is ReadConfigIntent.OptimizeRenderChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(optimizeRender = intent.value) }
+                upStyle()
+            }
 
 
-                is ReadConfigIntent.DisableReturnKeyChanged -> {
-                    ReadConfig.disableReturnKey = intent.value
-                }
+            is ReadConfigIntent.DisableReturnKeyChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(disableReturnKey = intent.value) }
+            }
 
 
-                is ReadConfigIntent.ShowReadTitleAdditionChanged -> {
-                    ReadConfig.showReadTitleAddition = intent.value
-                    postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
-                }
+            is ReadConfigIntent.ShowReadTitleAdditionChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(showReadTitleAddition = intent.value) }
+                postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
+            }
 
 
-                is ReadConfigIntent.ShowMenuIconChanged -> {
-                    ReadConfig.showMenuIcon = intent.value
-                    postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
-                }
+            is ReadConfigIntent.ShowMenuIconChanged -> {
+                localPreferencesRepository.updateSettings { it.copy(showMenuIcon = intent.value) }
+                postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
+            }
 
 
-                is ReadConfigIntent.PageKeysChanged -> {
-                    readSettingsRepository.setPageKeys(intent.prevKeys, intent.nextKeys)
+            is ReadConfigIntent.PageKeysChanged -> {
+                localPreferencesRepository.updateSettings {
+                    it.copy(prevKeys = intent.prevKeys, nextKeys = intent.nextKeys)
                 }
                 }
             }
             }
         }
         }
@@ -198,50 +185,4 @@ class ReadConfigViewModel(
         ReadBook.callBack?.upPageAnim(true)
         ReadBook.callBack?.upPageAnim(true)
         ReadBook.loadContent(false)
         ReadBook.loadContent(false)
     }
     }
-
-    private fun ReadPreferences.toUiState(): ReadConfigUiState {
-        return ReadConfigUiState(
-            screenOrientation = screenOrientation,
-            keepLight = keepLight,
-            hideStatusBar = hideStatusBar,
-            hideNavigationBar = hideNavigationBar,
-            paddingDisplayCutouts = paddingDisplayCutouts,
-            titleBarMode = titleBarMode,
-            readMenuBlurAlpha = readMenuBlurAlpha,
-            readBodyToLh = readBodyToLh,
-            defaultSourceChangeAll = defaultSourceChangeAll,
-            textFullJustify = textFullJustify,
-            textBottomJustify = textBottomJustify,
-            adaptSpecialStyle = adaptSpecialStyle,
-            useZhLayout = useZhLayout,
-            showBrightnessView = showBrightnessView,
-            brightnessVwPos = brightnessVwPos,
-            brightnessAuto = brightnessAuto,
-            useUnderline = useUnderline,
-            readSliderMode = readSliderMode,
-            doubleHorizontalPage = doubleHorizontalPage,
-            progressBarBehavior = progressBarBehavior,
-            mouseWheelPage = mouseWheelPage,
-            volumeKeyPage = volumeKeyPage,
-            volumeKeyPageOnPlay = volumeKeyPageOnPlay,
-            keyPageOnLongPress = keyPageOnLongPress,
-            pageTouchSlop = pageTouchSlop,
-            sliderVibrator = sliderVibrator,
-            selectVibrator = selectVibrator,
-            autoChangeSource = autoChangeSource,
-            autoSuggestDayNight = autoSuggestDayNight,
-            selectText = selectText,
-            noAnimScrollPage = noAnimScrollPage,
-            clickImgWay = clickImgWay,
-            optimizeRender = optimizeRender,
-            disableReturnKey = disableReturnKey,
-            expandTextMenu = expandTextMenu,
-            showSelectMenuIcon = showSelectMenuIcon,
-            showReadTitleAddition = showReadTitleAddition,
-            autoReadSpeed = autoReadSpeed,
-            prevKeys = prevKeys,
-            nextKeys = nextKeys,
-            showMenuIcon = showMenuIcon
-        )
-    }
 }
 }