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

Merge pull request #1738 from 52fisher/fix-bugs

fix: 击区域设置选项点击无效、关闭预见性返回后仍显示动画、阅读记录视图模式持久化
Kudomaga 4 месяцев назад
Родитель
Сommit
ef2bf67695

+ 1 - 0
app/src/main/java/io/legado/app/constant/PreferKey.kt

@@ -293,6 +293,7 @@ object PreferKey {
     const val bookshelfRefreshingLimit = "bookshelfRefreshingLimit"
     const val systemMediaControlCompatibilityChange = "systemMediaControlCompatibilityChange"
     const val isPredictiveBackEnabled = "isPredictiveBackEnabled"
+    const val readRecordDisplayMode = "readRecordDisplayMode"
     const val replaceSortMode = "desc"
     const val readBarStyle = "readBarStyle"
     const val readMenuBgColor = "readMenuBgColor"

+ 9 - 1
app/src/main/java/io/legado/app/ui/book/readRecord/ReadRecordViewModel.kt

@@ -3,6 +3,7 @@ package io.legado.app.ui.book.readRecord
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import cn.hutool.core.date.DateUtil
+import io.legado.app.constant.PreferKey
 import io.legado.app.data.entities.readRecord.ReadRecord
 import io.legado.app.data.entities.readRecord.ReadRecordDetail
 import io.legado.app.data.entities.readRecord.ReadRecordSession
@@ -20,6 +21,9 @@ import kotlinx.coroutines.launch
 import java.time.LocalDate
 import java.time.format.DateTimeFormatter
 import java.util.Date
+import splitties.init.appCtx
+import io.legado.app.utils.getPrefString
+import io.legado.app.utils.putPrefString
 
 data class ReadRecordUiState(
     val isLoading: Boolean = true,
@@ -45,7 +49,10 @@ class ReadRecordViewModel(
     private val bookRepository: BookRepository
 ) : ViewModel() {
 
-    private val _displayMode = MutableStateFlow(DisplayMode.AGGREGATE)
+    private val _displayMode = MutableStateFlow(
+        runCatching { DisplayMode.valueOf(appCtx.getPrefString(PreferKey.readRecordDisplayMode) ?: DisplayMode.AGGREGATE.name) }
+            .getOrDefault(DisplayMode.AGGREGATE)
+    )
     val displayMode = _displayMode.asStateFlow()
     private val _searchKey = MutableStateFlow("")
     private val _selectedDate = MutableStateFlow<LocalDate?>(null)
@@ -130,6 +137,7 @@ class ReadRecordViewModel(
 
     fun setDisplayMode(mode: DisplayMode) {
         _displayMode.value = mode
+        appCtx.putPrefString(PreferKey.readRecordDisplayMode, mode.name)
     }
 
     fun setSelectedDate(date: LocalDate?) {

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

@@ -15,6 +15,7 @@ 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.ui.book.read.sheet.ClickActionConfigSheet
 import io.legado.app.ui.theme.adaptiveContentPadding
 import io.legado.app.ui.widget.components.AppScaffold
 import io.legado.app.ui.widget.components.SplicedColumnGroup
@@ -36,6 +37,7 @@ fun ReadConfigScreen(
 ) {
     val scrollBehavior = GlassTopAppBarDefaults.defaultScrollBehavior()
     var showPageKeySheet by remember { mutableStateOf(false) }
+    var showClickActionSheet by remember { mutableStateOf(false) }
     val state by viewModel.uiState.collectAsStateWithLifecycle()
 
     AppScaffold(
@@ -354,7 +356,7 @@ fun ReadConfigScreen(
 
                 ClickableSettingItem(
                     title = stringResource(R.string.click_regional_config),
-                    onClick = { /* 暂时留空 */ }
+                    onClick = { showClickActionSheet = true }
                 )
 
                 SwitchSettingItem(
@@ -400,4 +402,10 @@ fun ReadConfigScreen(
             showPageKeySheet = false
         }
     )
+
+    if (showClickActionSheet) {
+        ClickActionConfigSheet(
+            onDismissRequest = { showClickActionSheet = false },
+        )
+    }
 }

+ 14 - 8
app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@@ -13,6 +13,8 @@ import androidx.compose.animation.ExperimentalSharedTransitionApi
 import androidx.compose.animation.SharedTransitionLayout
 import androidx.compose.animation.core.FastOutSlowInEasing
 import androidx.compose.animation.core.LinearOutSlowInEasing
+import androidx.compose.animation.EnterTransition
+import androidx.compose.animation.ExitTransition
 import androidx.compose.animation.core.tween
 import androidx.compose.animation.fadeIn
 import androidx.compose.animation.fadeOut
@@ -289,14 +291,18 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
                     ) + fadeOut(animationSpec = tween(durationMillis = 360)))
                 },
                 predictivePopTransitionSpec = { _ ->
-                    (slideIntoContainer(
-                        towards = AnimatedContentTransitionScope.SlideDirection.Start,
-                        animationSpec = tween(easing = FastOutSlowInEasing),
-                        initialOffset = { fullWidth -> -fullWidth / 4 }
-                    ) + fadeIn(animationSpec = tween(easing = LinearOutSlowInEasing))) togetherWith (scaleOut(
-                        targetScale = 0.8f,
-                        animationSpec = tween(easing = FastOutSlowInEasing)
-                    ) + fadeOut(animationSpec = tween()))
+                    if (!AppConfig.isPredictiveBackEnabled) {
+                        EnterTransition.None togetherWith ExitTransition.None
+                    } else {
+                        (slideIntoContainer(
+                            towards = AnimatedContentTransitionScope.SlideDirection.Start,
+                            animationSpec = tween(easing = FastOutSlowInEasing),
+                            initialOffset = { fullWidth -> -fullWidth / 4 }
+                        ) + fadeIn(animationSpec = tween(easing = LinearOutSlowInEasing))) togetherWith (scaleOut(
+                            targetScale = 0.8f,
+                            animationSpec = tween(easing = FastOutSlowInEasing)
+                        ) + fadeOut(animationSpec = tween()))
+                    }
                 },
                 onBack = { MainNavigator.navigateBack(this@MainActivity, backStack) },
                 entryProvider = mainEntryProvider(

+ 14 - 10
app/src/main/java/io/legado/app/ui/main/MainNavGraph.kt

@@ -635,16 +635,20 @@ fun MainActivity.mainEntryProvider(
                         fadeOut(animationSpec = tween(300))
             } else null
         } + NavDisplay.predictivePopTransitionSpec { _ ->
-            val to = targetState.key
-            val toStr = to.toString()
-            if (to is MainRouteHome || to is MainRouteExploreShow || to is MainRouteSearch ||
-                toStr.startsWith("MainRouteHome") || toStr.startsWith("MainRouteExploreShow") || toStr.startsWith(
-                    "MainRouteSearch"
-                )
-            ) {
-                fadeIn(animationSpec = tween(300)) togetherWith
-                        fadeOut(animationSpec = tween(300))
-            } else null
+            if (!AppConfig.isPredictiveBackEnabled) {
+                null
+            } else {
+                val to = targetState.key
+                val toStr = to.toString()
+                if (to is MainRouteHome || to is MainRouteExploreShow || to is MainRouteSearch ||
+                    toStr.startsWith("MainRouteHome") || toStr.startsWith("MainRouteExploreShow") || toStr.startsWith(
+                        "MainRouteSearch"
+                    )
+                ) {
+                    fadeIn(animationSpec = tween(300)) togetherWith
+                            fadeOut(animationSpec = tween(300))
+                } else null
+            }
         }
     ) { route ->
         val bookInfoViewModel = koinViewModel<BookInfoViewModel>(key = "BookInfo:${route.bookUrl}")

+ 25 - 18
app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt

@@ -6,6 +6,8 @@ import androidx.activity.compose.LocalActivity
 import androidx.compose.animation.AnimatedContentTransitionScope
 import androidx.compose.animation.core.FastOutSlowInEasing
 import androidx.compose.animation.core.LinearOutSlowInEasing
+import androidx.compose.animation.EnterTransition
+import androidx.compose.animation.ExitTransition
 import androidx.compose.animation.core.tween
 import androidx.compose.animation.fadeIn
 import androidx.compose.animation.fadeOut
@@ -19,6 +21,7 @@ import androidx.navigation3.runtime.entryProvider
 import androidx.navigation3.runtime.rememberNavBackStack
 import androidx.navigation3.ui.NavDisplay
 import io.legado.app.base.BaseComposeActivity
+import io.legado.app.help.config.AppConfig
 import io.legado.app.ui.replace.edit.ReplaceEditRouteScreen
 import io.legado.app.ui.replace.edit.ReplaceEditViewModel
 import io.legado.app.ui.theme.AppTheme
@@ -108,24 +111,28 @@ class ReplaceRuleActivity : BaseComposeActivity() {
                     ))
                 },
                 predictivePopTransitionSpec = { _ ->
-                    (slideIntoContainer(
-                        towards = AnimatedContentTransitionScope.SlideDirection.Start,
-                        animationSpec = tween(
-                            easing = FastOutSlowInEasing
-                        ),
-                        initialOffset = { fullWidth -> -fullWidth / 4 }
-                    ) + fadeIn(
-                        animationSpec = tween(
-                            easing = LinearOutSlowInEasing
-                        )
-                    )) togetherWith (scaleOut(
-                        targetScale = 0.8f,
-                        animationSpec = tween(
-                            easing = FastOutSlowInEasing
-                        )
-                    ) + fadeOut(
-                        animationSpec = tween()
-                    ))
+                    if (!AppConfig.isPredictiveBackEnabled) {
+                        EnterTransition.None togetherWith ExitTransition.None
+                    } else {
+                        (slideIntoContainer(
+                            towards = AnimatedContentTransitionScope.SlideDirection.Start,
+                            animationSpec = tween(
+                                easing = FastOutSlowInEasing
+                            ),
+                            initialOffset = { fullWidth -> -fullWidth / 4 }
+                        ) + fadeIn(
+                            animationSpec = tween(
+                                easing = LinearOutSlowInEasing
+                            )
+                        )) togetherWith (scaleOut(
+                            targetScale = 0.8f,
+                            animationSpec = tween(
+                                easing = FastOutSlowInEasing
+                            )
+                        ) + fadeOut(
+                            animationSpec = tween()
+                        ))
+                    }
                 },
                 onBack = {
                     if (backStack.size > 1) {