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
语速减
语速加
打开系统文件夹选择器出错,自动打开应用文件夹选择器