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

fix: 阅读搜素和菜单部分问题

HapeLee 3 месяцев назад
Родитель
Сommit
ccfc62ee34

+ 4 - 1
app/src/main/java/io/legado/app/domain/usecase/ExploreBooksUseCase.kt

@@ -61,7 +61,10 @@ class ExploreBooksUseCase(
     ): ExploreRequest {
         val base = gateway.getBookSource(sourceUrl)
             ?: throw SourceNotFound(sourceUrl)
-        val source = args?.let { base.copy().also { s -> s.setTemporaryVariable(it) } } ?: base
+        val source = args
+            ?.takeIf(String::isNotBlank)
+            ?.let { base.copy().also { s -> s.setTemporaryVariable(it) } }
+            ?: base
         val url = moduleUrl
             ?: (if (key != null) source.searchUrl else null)
             ?: source.exploreUrl

+ 4 - 4
app/src/main/java/io/legado/app/ui/book/read/ReadBookMenuBar.kt

@@ -2891,10 +2891,10 @@ private fun loadToolButtons(
             onIntent(ReadBookIntent.NextChapter)
         },
         infoMap.getValue("replace").toButton {
-            onIntent(ReadBookIntent.ChangeReplaceRule(true))
+            onIntent(ReadBookIntent.MenuSettingReplace)
         },
         infoMap.getValue("replace_badge").toButton {
-            onIntent(ReadBookIntent.ChangeReplaceRule(true))
+            onIntent(ReadBookIntent.MenuSettingReplace)
         },
         infoMap.getValue("auto_page").toButton(isActive = state.isAutoPage) {
             if (state.isAutoPage) {
@@ -3256,8 +3256,8 @@ private fun loadFloatingIcons(
         "theme" to { onIntent(ReadBookIntent.ToggleDayNight) },
         "prev_chapter" to { onIntent(ReadBookIntent.PrevChapter) },
         "next_chapter" to { onIntent(ReadBookIntent.NextChapter) },
-        "replace" to { onIntent(ReadBookIntent.ChangeReplaceRule(true)) },
-        "replace_badge" to { onIntent(ReadBookIntent.ChangeReplaceRule(true)) },
+        "replace" to { onIntent(ReadBookIntent.MenuSettingReplace) },
+        "replace_badge" to { onIntent(ReadBookIntent.MenuSettingReplace) },
         "auto_page" to {
             if (state.isAutoPage) {
                 onIntent(ReadBookIntent.OpenReadMenuRoute(ReadBookMenuRoute.AutoRead))

+ 20 - 7
app/src/main/java/io/legado/app/ui/book/read/ReadBookRouteScreen.kt

@@ -441,13 +441,26 @@ fun ReadBookRouteScreen(
                     SearchContentResult.resetReplayCache()
                     return@collect
                 }
-                viewModel.onIntent(
-                    ReadBookIntent.SetSearchResults(result.searchResults, result.index, result.query)
-                )
-                result.searchResults.getOrNull(result.index)?.let { searchResult ->
-                    viewModel.onIntent(
-                        ReadBookIntent.NavigateToSearchResult(searchResult, result.index)
-                    )
+                when (result) {
+                    is SearchContentResult.Clear -> {
+                        viewModel.onIntent(ReadBookIntent.SetSearchResults(emptyList(), 0, ""))
+                        viewModel.onIntent(ReadBookIntent.ExitSearch)
+                    }
+
+                    is SearchContentResult.Result -> {
+                        viewModel.onIntent(
+                            ReadBookIntent.SetSearchResults(
+                                result.searchResults,
+                                result.index,
+                                result.query
+                            )
+                        )
+                        result.searchResults.getOrNull(result.index)?.let { searchResult ->
+                            viewModel.onIntent(
+                                ReadBookIntent.NavigateToSearchResult(searchResult, result.index)
+                            )
+                        }
+                    }
                 }
                 SearchContentResult.resetReplayCache()
             }

+ 9 - 5
app/src/main/java/io/legado/app/ui/book/read/sheet/EffectiveReplacesSheet.kt

@@ -149,14 +149,18 @@ fun EffectiveReplacesSheet(
                                     }
                                 }
                             }
-                            if (rule.id != RE_SEGMENT_ID) MediumTonalButton(
+                            MediumTonalButton(
                                 onClick = {
                                     disabledIds = disabledIds + rule.id
                                     isEdited = true
-                                    if (rule.id == CHINESE_CONVERT_ID) {
-                                        ReadConfig.chineseConverterType = 0
-                                    } else {
-                                        scope.launch {
+                                    when (rule.id) {
+                                        RE_SEGMENT_ID -> {
+                                            ReadBook.book?.setReSegment(false)
+                                            ReadBook.loadContent(false)
+                                        }
+
+                                        CHINESE_CONVERT_ID -> ReadConfig.chineseConverterType = 0
+                                        else -> scope.launch {
                                             rule.isEnabled = false
                                             appDb.replaceRuleDao.insert(rule)
                                         }

+ 13 - 3
app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentResult.kt

@@ -13,20 +13,30 @@ import kotlinx.coroutines.flow.asSharedFlow
  */
 object SearchContentResult {
 
+    sealed interface Event {
+        val bookUrl: String
+    }
+
     data class Result(
-        val bookUrl: String,
+        override val bookUrl: String,
         val searchResults: List<SearchResult>,
         val index: Int,
         val query: String,
-    )
+    ) : Event
+
+    data class Clear(override val bookUrl: String) : Event
 
-    private val _results = MutableSharedFlow<Result>(replay = 1)
+    private val _results = MutableSharedFlow<Event>(replay = 1)
     val results = _results.asSharedFlow()
 
     fun emitResult(result: Result) {
         _results.tryEmit(result)
     }
 
+    fun clearResults(bookUrl: String) {
+        _results.tryEmit(Clear(bookUrl))
+    }
+
     @OptIn(ExperimentalCoroutinesApi::class)
     fun resetReplayCache() {
         _results.resetReplayCache()

+ 3 - 1
app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt

@@ -192,7 +192,9 @@ class SearchContentViewModel(
 
     fun leaveSearch() {
         searchJob?.cancel()
-        searchContentRepository.clearSession(bookUrl)
+        if (_searchQuery.value.isBlank()) {
+            SearchContentResult.clearResults(bookUrl)
+        }
         _searchQuery.value = ""
         _uiState.update {
             it.copy(

+ 30 - 61
app/src/main/java/io/legado/app/ui/main/home/HomeScreen.kt

@@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.aspectRatio
 import androidx.compose.foundation.layout.fillMaxSize
 import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.heightIn
 import androidx.compose.foundation.layout.offset
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.size
@@ -32,6 +33,7 @@ import androidx.compose.foundation.pager.rememberPagerState
 import androidx.compose.foundation.rememberScrollState
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.foundation.text.selection.SelectionContainer
 import androidx.compose.foundation.verticalScroll
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.filled.AccessTime
@@ -54,7 +56,6 @@ import androidx.compose.runtime.derivedStateOf
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberCoroutineScope
 import androidx.compose.runtime.setValue
 import androidx.compose.runtime.snapshotFlow
 import androidx.compose.ui.Alignment
@@ -110,7 +111,6 @@ import io.legado.app.ui.widget.components.card.TextCard
 import io.legado.app.ui.widget.components.icon.AppIcon
 import io.legado.app.ui.widget.components.icon.AppIcons
 import io.legado.app.ui.widget.components.image.cover.BookshelfCover
-import io.legado.app.ui.widget.components.list.TopFloatingStickyItem
 import io.legado.app.ui.widget.components.menuItem.MenuItemIcon
 import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenu
 import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenuItem
@@ -121,11 +121,11 @@ import io.legado.app.ui.widget.components.topbar.GlassMediumFlexibleTopAppBar
 import io.legado.app.ui.widget.components.topbar.GlassTopAppBarDefaults
 import io.legado.app.ui.widget.components.topbar.TopBarActionButton
 import io.legado.app.utils.isContentScheme
+import io.legado.app.utils.sendToClip
 import io.legado.app.utils.takePersistablePermissionSafely
 import io.legado.app.utils.toastOnUi
 import kotlinx.coroutines.flow.collectLatest
 import kotlinx.coroutines.flow.distinctUntilChanged
-import kotlinx.coroutines.launch
 import org.koin.androidx.compose.koinViewModel
 import java.text.DateFormat
 import java.util.Date
@@ -391,7 +391,7 @@ fun HomeScreen(
     animatedVisibilityScope: AnimatedVisibilityScope? = null,
 ) {
     val scrollBehavior = GlassTopAppBarDefaults.defaultScrollBehavior()
-    val scope = rememberCoroutineScope()
+    val context = LocalContext.current
 
     val selectedSets = remember(homepageState.manageState.sets) {
         homepageState.manageState.sets.filter { it.isSelected }
@@ -401,7 +401,7 @@ fun HomeScreen(
     })
 
     var showPageMenu by remember { mutableStateOf(false) }
-    var showSourceMenu by remember { mutableStateOf(false) }
+    var errorMessage by remember { mutableStateOf<String?>(null) }
 
     val currentPageSourceName by remember(selectedSets, pagerState) {
         derivedStateOf { selectedSets.getOrNull(pagerState.currentPage)?.sourceName }
@@ -430,6 +430,7 @@ fun HomeScreen(
         topBar = {
             GlassMediumFlexibleTopAppBar(
                 title = stringResource(R.string.home),
+                subtitle = currentPageSourceName,
                 scrollBehavior = scrollBehavior,
                 actions = {
                     TopBarActionButton(
@@ -501,12 +502,6 @@ fun HomeScreen(
                 }
                 val viewportHeight = maxHeight
                 val hasDashboard = state.visibleSections.isNotEmpty()
-                val isSourceSwitcherVisible by remember(hasDashboard, selectedSets) {
-                    derivedStateOf {
-                        selectedSets.size > 1 &&
-                                (!hasDashboard || dashboardScrollState.value > 0 || showSourceMenu)
-                    }
-                }
 
                 Column(
                     modifier = Modifier
@@ -572,62 +567,13 @@ fun HomeScreen(
                                     sharedTransitionScope = sharedTransitionScope,
                                     animatedVisibilityScope = animatedVisibilityScope,
                                     onBookLongClick = onHomepageBookLongClick,
-                                    onErrorClick = {},
+                                    onErrorClick = { errorMessage = it },
                                 )
                             }
                         }
                     }
                 }
 
-                TopFloatingStickyItem(
-                    item = if (isSourceSwitcherVisible) currentPageSourceName else null,
-                    modifier = Modifier
-                        .align(Alignment.TopCenter)
-                        .padding(top = paddingValues.calculateTopPadding() + 8.dp),
-                ) { name ->
-                    Box {
-                        GlassCard(
-                            modifier = Modifier
-                                .padding(horizontal = 12.dp)
-                                .clickable(
-                                    role = Role.Button,
-                                    onClick = { showSourceMenu = true },
-                                ),
-                            cornerRadius = 32.dp
-                        ) {
-                            Row(
-                                modifier = Modifier.padding(
-                                    horizontal = 16.dp,
-                                    vertical = 12.dp,
-                                ),
-                                verticalAlignment = Alignment.CenterVertically,
-                                horizontalArrangement = Arrangement.spacedBy(6.dp),
-                            ) {
-                                AppText(
-                                    text = name,
-                                    style = LegadoTheme.typography.labelMedium,
-                                )
-                            }
-                        }
-                        RoundDropdownMenu(
-                            expanded = showSourceMenu,
-                            onDismissRequest = { showSourceMenu = false },
-                        ) { dismiss ->
-                            selectedSets.forEachIndexed { index, source ->
-                                RoundDropdownMenuItem(
-                                    text = source.sourceName,
-                                    isSelected = index == pagerState.currentPage,
-                                    onClick = {
-                                        dismiss()
-                                        scope.launch {
-                                            pagerState.animateScrollToPage(index)
-                                        }
-                                    },
-                                )
-                            }
-                        }
-                    }
-                }
             }
         }
 
@@ -647,6 +593,29 @@ fun HomeScreen(
             visibleSections = state.visibleSections,
             onIntent = onIntent,
         )
+        AppAlertDialog(
+            data = errorMessage,
+            onDismissRequest = { errorMessage = null },
+            title = stringResource(R.string.error_details),
+            confirmText = stringResource(R.string.copy_text),
+            onConfirm = { message ->
+                context.sendToClip(message)
+                errorMessage = null
+            },
+            dismissText = stringResource(R.string.close),
+            onDismiss = { errorMessage = null },
+            content = { message ->
+                SelectionContainer {
+                    AppText(
+                        text = message,
+                        style = LegadoTheme.typography.bodyMedium,
+                        modifier = Modifier
+                            .heightIn(max = 400.dp)
+                            .verticalScroll(rememberScrollState()),
+                    )
+                }
+            },
+        )
     }
 }
 

+ 8 - 0
app/src/main/res/values-zh-rCN/arrays.xml

@@ -212,6 +212,14 @@
         <item>不显示</item>
     </string-array>
 
+    <string-array name="click_image_way_title">
+        <item>新版行为</item>
+        <item>预览图片</item>
+        <item>经典</item>
+        <item>禁用点击</item>
+        <item>双击</item>
+    </string-array>
+
     <string-array name="title_bar_mode">
         <item>在应用栏上显示</item>
         <item>在独立行上显示</item>

+ 7 - 0
app/src/main/res/values-zh-rHK/arrays.xml

@@ -1,5 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
+    <string-array name="click_image_way_title">
+        <item>新版行為</item>
+        <item>預覽圖片</item>
+        <item>經典</item>
+        <item>停用點擊</item>
+        <item>雙擊</item>
+    </string-array>
 
     <string-array name="book_type">
         <item>文本</item>

+ 7 - 0
app/src/main/res/values-zh-rTW/arrays.xml

@@ -1,5 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
+    <string-array name="click_image_way_title">
+        <item>新版行為</item>
+        <item>預覽圖片</item>
+        <item>經典</item>
+        <item>停用點擊</item>
+        <item>雙擊</item>
+    </string-array>
     <string-array name="book_type">
         <item>文字</item>
         <item>音訊</item>