From 21c40b08d608eedcaf495c27b418d86aea1301c1 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sun, 30 Jan 2022 08:21:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=85=A8=E6=96=87=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=EF=BC=9A=E6=90=9C=E7=B4=A2=E5=AE=8C=E6=88=90=E5=90=8E=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=90=9C=E7=B4=A2=E6=98=BE=E7=A4=BA=EF=BC=8C=E6=9C=AA?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=88=B0=E5=86=85=E5=AE=B9=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../searchContent/SearchContentActivity.kt | 8 +++++-- .../searchContent/SearchContentAdapter.kt | 2 +- .../app/ui/book/searchContent/SearchResult.kt | 22 +++++++++++-------- app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 27 insertions(+), 12 deletions(-) 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/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 b2747bca2..a34f56fe3 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 42a11b401..699720d6a 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 79f653394..590791e87 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 b3759c663..d9c3fbf60 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 5f4e69d82..fa42f2292 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 5df8c8f4a..d8d741d7b 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 语速减 语速加 打开系统文件夹选择器出错,自动打开应用文件夹选择器 From b68cc7b4d9890b1628a60862f80ce833d3ad97c5 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sun, 30 Jan 2022 10:56:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/searchContent/SearchContentViewModel.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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)