diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt index 14ce8ff98..0518737be 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt @@ -148,16 +148,20 @@ class SearchContentActivity : searchResults = viewModel.searchChapter(query, bookChapter) } } + binding.tvCurrentSearchInfo.text = this@SearchContentActivity.getString(R.string.search_content_size) +": ${viewModel.searchResultCounts}" if (searchResults.isNotEmpty()) { viewModel.searchResultList.addAll(searchResults) binding.refreshProgressBar.isAutoLoading = false - binding.tvCurrentSearchInfo.text = this@SearchContentActivity.getString(R.string.search_content_size) +": ${viewModel.searchResultCounts}" adapter.addItems(searchResults) searchResults = listOf() } } + binding.refreshProgressBar.isAutoLoading = false + if (viewModel.searchResultCounts == 0) { + val noSearchResult = SearchResult(resultText = getString(R.string.search_content_empty)) + adapter.addItem(noSearchResult) + } } - binding.refreshProgressBar.isAutoLoading = false } } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt index 426f50864..88d0a83b4 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt @@ -39,7 +39,7 @@ class SearchContentAdapter(context: Context, val callback: Callback) : override fun registerListener(holder: ItemViewHolder, binding: ItemSearchListBinding) { holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { - callback.openSearchResult(it) + if (!it.query.isBlank()) callback.openSearchResult(it) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt index b23a2131f..acbda4f27 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt @@ -75,10 +75,13 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati private fun searchPosition(pattern: String): List { val position: MutableList = mutableListOf() - if (mContent.indexOf(pattern) >= 0) { + var index = mContent.indexOf(pattern) + if (index >= 0) { //搜索到内容允许净化 - if (book?.getUseReplaceRule() ?: false) mContent = contentProcessor!!.replaceContent(mContent) - var index = mContent.indexOf(pattern) + if (book!!.getUseReplaceRule()) { + mContent = contentProcessor!!.replaceContent(mContent) + index = mContent.indexOf(pattern) + } while (index >= 0) { position.add(index) index = mContent.indexOf(pattern, index + 1) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt index a3b3631be..6123cbd94 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt @@ -8,7 +8,7 @@ data class SearchResult( val resultCountWithinChapter: Int = 0, val resultText: String = "", val chapterTitle: String = "", - val query: String, + val query: String = "", val pageSize: Int = 0, val chapterIndex: Int = 0, val pageIndex: Int = 0, @@ -17,14 +17,18 @@ data class SearchResult( ) { fun getHtmlCompat(textColor: String, accentColor: String): Spanned { - val queryIndexInSurrounding = resultText.indexOf(query) - val leftString = resultText.substring(0, queryIndexInSurrounding) - val rightString = resultText.substring(queryIndexInSurrounding + query.length, resultText.length) - val html = leftString.colorTextForHtml(textColor) + - query.colorTextForHtml(accentColor) + - rightString.colorTextForHtml(textColor) + - chapterTitle.colorTextForHtml(accentColor) - return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY) + if (!query.isBlank()) { + val queryIndexInSurrounding = resultText.indexOf(query) + val leftString = resultText.substring(0, queryIndexInSurrounding) + val rightString = resultText.substring(queryIndexInSurrounding + query.length, resultText.length) + val html = leftString.colorTextForHtml(textColor) + + query.colorTextForHtml(accentColor) + + rightString.colorTextForHtml(textColor) + + chapterTitle.colorTextForHtml(accentColor) + return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY) + } else { + return HtmlCompat.fromHtml(resultText.colorTextForHtml(textColor), HtmlCompat.FROM_HTML_MODE_LEGACY) + } } private fun String.colorTextForHtml(textColor: String) = "$this" diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 53f690b1b..f72c0c19b 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -907,6 +907,7 @@ 字体大小 当前字体大小:%.1f search result + search result is empty 语速减 语速加 打开系统文件夹选择器出错,自动打开应用文件夹选择器 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 66a04489d..57742602f 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -910,6 +910,7 @@ 字体大小 当前字体大小:%.1f search result + search result is empty 语速减 语速加 打开系统文件夹选择器出错,自动打开应用文件夹选择器 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index cefb2c80f..e6aa4e260 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -910,6 +910,7 @@ 字体大小 当前字体大小:%.1f search result + search result is empty 语速减 语速加 打开系统文件夹选择器出错,自动打开应用文件夹选择器 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 5530eaf69..07185c895 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -901,6 +901,7 @@ 是否使用外部瀏覽器打開? 查看 搜索結果 + 搜索結果为空 打開 刪除登錄頭 查看登錄頭 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 5b0771e41..309645a24 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -913,6 +913,7 @@ 打開系統資料夾選擇器出錯,自動打開應用程式資料夾選擇器 展開文字選擇選單 搜尋結果 + 搜尋結果为空 書籍儲存位置 從其它應用程式打開的書籍儲存位置 选择保存书籍的文件夹 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index d6ae50690..48d98305d 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -780,6 +780,7 @@ 更新时间排序 全文搜索 搜索结果 + 搜索结果为空 关注公众号[开源阅读]获取订阅源! 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! 将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 10a3f5a7d..e2af867cb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -911,6 +911,7 @@ font scale font scale:%.1f search result + search result is empty 语速减 语速加 打开系统文件夹选择器出错,自动打开应用文件夹选择器