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

fix: 阅读界面配置响应性

HapeLee 5 месяцев назад
Родитель
Сommit
55b15c2de3

+ 1 - 0
app/src/main/java/io/legado/app/data/local/preferences/LocalPreferences.kt

@@ -13,6 +13,7 @@ object LocalPreferencesKeys {
     val SHOW_THEME_REFACTOR_TIP = booleanPreferencesKey("show_theme_refactor_tip")
     val SEARCH_LAYOUT_MODE = intPreferencesKey("search_layout_mode")
     val MATCH_MODE = intPreferencesKey("match_mode")
+    val EXPLORE_LAYOUT_MODE = intPreferencesKey("explore_layout_mode")
     val EXPLORE_LAYOUT_GRID_PORTRAIT = intPreferencesKey("explore_layout_grid_portrait")
     val EXPLORE_LAYOUT_GRID_LANDSCAPE = intPreferencesKey("explore_layout_grid_landscape")
     val READ_URL_IN_BROWSER = booleanPreferencesKey("read_url_in_browser")

+ 12 - 3
app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt

@@ -13,7 +13,6 @@ import io.legado.app.domain.usecase.SaveSearchBooksUseCase
 import android.content.res.Configuration
 import io.legado.app.data.local.preferences.LocalPreferencesKeys
 import io.legado.app.data.local.preferences.LocalPreferencesRepository
-import io.legado.app.help.config.AppConfig
 import io.legado.app.utils.stackTraceStr
 import kotlinx.collections.immutable.toImmutableList
 import kotlinx.coroutines.flow.MutableSharedFlow
@@ -61,7 +60,7 @@ class ExploreShowViewModel(
     private val _kindState = MutableStateFlow(ExploreShowKindState())
     private val _displayState = MutableStateFlow(
         ExploreShowDisplayState(
-            layoutState = AppConfig.exploreLayoutState,
+            layoutState = 0,
             gridCount = if (appCtx.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) 7 else 3,
         )
     )
@@ -91,6 +90,7 @@ class ExploreShowViewModel(
     init {
         observeBookshelf()
         combineUiState()
+        loadLayoutMode()
         loadGridCount()
     }
 
@@ -215,11 +215,20 @@ class ExploreShowViewModel(
     private fun toggleLayout() {
         _displayState.update {
             val layoutState = if (it.layoutState == 0) 1 else 0
-            AppConfig.exploreLayoutState = layoutState
+            viewModelScope.launch {
+                localPreferencesRepository.updatePreference(LocalPreferencesKeys.EXPLORE_LAYOUT_MODE, layoutState)
+            }
             it.copy(layoutState = layoutState)
         }
     }
 
+    private fun loadLayoutMode() {
+        viewModelScope.launch {
+            val mode = localPreferencesRepository.getPreference(LocalPreferencesKeys.EXPLORE_LAYOUT_MODE, 0).first()
+            _displayState.update { it.copy(layoutState = mode) }
+        }
+    }
+
     private fun loadGridCount() {
         viewModelScope.launch {
             val isLandscape = appCtx.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE