Просмотр исходного кода

refactor: 移除 ReadConfigIntent 处理中的重复设置调用,优化状态管理

5151561 3 месяцев назад
Родитель
Сommit
82acd05e98

+ 7 - 35
app/src/main/java/io/legado/app/ui/config/readConfig/ReadConfigViewModel.kt

@@ -29,183 +29,155 @@ class ReadConfigViewModel(
             when (intent) {
                 is ReadConfigIntent.ScreenOrientationChanged -> {
                     ReadConfig.screenOrientation = intent.value
-                    readSettingsRepository.setScreenOrientation(intent.value)
                 }
 
                 is ReadConfigIntent.KeepLightChanged -> {
                     ReadConfig.keepLight = intent.value
-                    readSettingsRepository.setKeepLight(intent.value)
                 }
 
                 is ReadConfigIntent.HideStatusBarChanged -> {
-                    readSettingsRepository.setHideStatusBar(intent.value)
                     ReadBookConfig.hideStatusBar = intent.value
                     postEvent(EventBus.UP_CONFIG, arrayListOf(0, 2))
                 }
 
                 is ReadConfigIntent.HideNavigationBarChanged -> {
-                    readSettingsRepository.setHideNavigationBar(intent.value)
                     ReadBookConfig.hideNavigationBar = intent.value
                     postEvent(EventBus.UP_CONFIG, arrayListOf(0, 2))
                 }
 
                 is ReadConfigIntent.PaddingDisplayCutoutsChanged -> {
                     ReadConfig.paddingDisplayCutouts = intent.value
-                    readSettingsRepository.setPaddingDisplayCutouts(intent.value)
                 }
 
                 is ReadConfigIntent.TitleBarModeChanged -> {
                     ReadConfig.titleBarMode = intent.value
-                    readSettingsRepository.setTitleBarMode(intent.value)
                 }
 
                 is ReadConfigIntent.ReadMenuBlurAlphaChanged -> {
                     ReadBookConfig.readMenuBlurAlpha = intent.value
-                    readSettingsRepository.setReadMenuBlurAlpha(intent.value)
                     postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
                 }
 
                 is ReadConfigIntent.ReadBodyToLhChanged -> {
                     ReadBookConfig.readBodyToLh = intent.value
-                    readSettingsRepository.setReadBodyToLh(intent.value)
                 }
 
                 is ReadConfigIntent.DefaultSourceChangeAllChanged -> {
-                    readSettingsRepository.setDefaultSourceChangeAll(intent.value)
+                    ReadConfig.defaultSourceChangeAll = intent.value
                 }
 
                 is ReadConfigIntent.TextFullJustifyChanged -> {
-                    readSettingsRepository.setTextFullJustify(intent.value)
+                    ReadBookConfig.textFullJustify = intent.value
                     upLayout()
                 }
 
                 is ReadConfigIntent.TextBottomJustifyChanged -> {
-                    readSettingsRepository.setTextBottomJustify(intent.value)
+                    ReadBookConfig.textBottomJustify = intent.value
                     upLayout()
                 }
 
                 is ReadConfigIntent.AdaptSpecialStyleChanged -> {
                     ReadConfig.adaptSpecialStyle = intent.value
-                    readSettingsRepository.setAdaptSpecialStyle(intent.value)
                 }
 
                 is ReadConfigIntent.UseZhLayoutChanged -> {
-                    readSettingsRepository.setUseZhLayout(intent.value)
                     ReadBookConfig.useZhLayout = intent.value
                     upLayout()
                 }
 
                 is ReadConfigIntent.ShowBrightnessViewChanged -> {
-                    readSettingsRepository.setShowBrightnessView(intent.value)
+                    ReadBookConfig.showBrightnessView = intent.value
                 }
 
                 is ReadConfigIntent.BrightnessVwPosChanged -> {
-                    readSettingsRepository.setBrightnessVwPos(intent.value)
+                    ReadBookConfig.brightnessVwPos = intent.value
                 }
 
                 is ReadConfigIntent.UseUnderlineChanged -> {
                     ReadConfig.useUnderline = intent.value
-                    readSettingsRepository.setUseUnderline(intent.value)
                 }
 
                 is ReadConfigIntent.ReadSliderModeChanged -> {
                     ReadBookConfig.readSliderMode = intent.value
-                    readSettingsRepository.setReadSliderMode(intent.value)
                     postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
                 }
 
                 is ReadConfigIntent.DoubleHorizontalPageChanged -> {
                     ReadConfig.doubleHorizontalPage = intent.value
-                    readSettingsRepository.setDoubleHorizontalPage(intent.value)
                     upLayout()
                 }
 
                 is ReadConfigIntent.ProgressBarBehaviorChanged -> {
                     ReadConfig.progressBarBehavior = intent.value
-                    readSettingsRepository.setProgressBarBehavior(intent.value)
                     postEvent(EventBus.UP_SEEK_BAR, true)
                 }
 
                 is ReadConfigIntent.MouseWheelPageChanged -> {
                     ReadConfig.mouseWheelPage = intent.value
-                    readSettingsRepository.setMouseWheelPage(intent.value)
                 }
 
                 is ReadConfigIntent.VolumeKeyPageChanged -> {
                     ReadConfig.volumeKeyPage = intent.value
-                    readSettingsRepository.setVolumeKeyPage(intent.value)
                 }
 
                 is ReadConfigIntent.VolumeKeyPageOnPlayChanged -> {
                     ReadConfig.volumeKeyPageOnPlay = intent.value
-                    readSettingsRepository.setVolumeKeyPageOnPlay(intent.value)
                 }
 
                 is ReadConfigIntent.KeyPageOnLongPressChanged -> {
                     ReadConfig.keyPageOnLongPress = intent.value
-                    readSettingsRepository.setKeyPageOnLongPress(intent.value)
                 }
 
                 is ReadConfigIntent.PageTouchSlopChanged -> {
-                    readSettingsRepository.setPageTouchSlop(intent.value)
+                    ReadConfig.pageTouchSlop = intent.value
                     postEvent(EventBus.UP_CONFIG, arrayListOf(4))
                 }
 
                 is ReadConfigIntent.SliderVibratorChanged -> {
                     ReadConfig.sliderVibrator = intent.value
-                    readSettingsRepository.setSliderVibrator(intent.value)
                 }
 
                 is ReadConfigIntent.SelectVibratorChanged -> {
                     ReadConfig.selectVibrator = intent.value
-                    readSettingsRepository.setSelectVibrator(intent.value)
                 }
 
                 is ReadConfigIntent.AutoChangeSourceChanged -> {
                     ReadConfig.autoChangeSource = intent.value
-                    readSettingsRepository.setAutoChangeSource(intent.value)
                 }
 
                 is ReadConfigIntent.AutoSuggestDayNightChanged -> {
                     ReadConfig.autoSuggestDayNight = intent.value
-                    readSettingsRepository.setAutoSuggestDayNight(intent.value)
                 }
 
                 is ReadConfigIntent.SelectTextChanged -> {
                     ReadConfig.selectText = intent.value
-                    readSettingsRepository.setSelectText(intent.value)
                 }
 
                 is ReadConfigIntent.NoAnimScrollPageChanged -> {
-                    readSettingsRepository.setNoAnimScrollPage(intent.value)
+                    ReadConfig.noAnimScrollPage = intent.value
                     ReadBook.callBack?.upPageAnim()
                 }
 
                 is ReadConfigIntent.ClickImgWayChanged -> {
                     ReadConfig.clickImgWay = intent.value
-                    readSettingsRepository.setClickImgWay(intent.value)
                 }
 
                 is ReadConfigIntent.OptimizeRenderChanged -> {
                     ReadConfig.optimizeRender = intent.value
-                    readSettingsRepository.setOptimizeRender(intent.value)
                     upStyle()
                 }
 
                 is ReadConfigIntent.DisableReturnKeyChanged -> {
                     ReadConfig.disableReturnKey = intent.value
-                    readSettingsRepository.setDisableReturnKey(intent.value)
                 }
 
                 is ReadConfigIntent.ShowReadTitleAdditionChanged -> {
                     ReadConfig.showReadTitleAddition = intent.value
-                    readSettingsRepository.setShowReadTitleAddition(intent.value)
                     postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
                 }
 
                 is ReadConfigIntent.ShowMenuIconChanged -> {
                     ReadConfig.showMenuIcon = intent.value
-                    readSettingsRepository.setShowMenuIcon(intent.value)
                     postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
                 }