mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
全文搜索:搜索完成后关闭搜索显示,未搜索到内容提示用户
This commit is contained in:
parent
a6452940a4
commit
21c40b08d6
@ -148,16 +148,20 @@ class SearchContentActivity :
|
|||||||
searchResults = viewModel.searchChapter(query, bookChapter)
|
searchResults = viewModel.searchChapter(query, bookChapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
binding.tvCurrentSearchInfo.text = this@SearchContentActivity.getString(R.string.search_content_size) +": ${viewModel.searchResultCounts}"
|
||||||
if (searchResults.isNotEmpty()) {
|
if (searchResults.isNotEmpty()) {
|
||||||
viewModel.searchResultList.addAll(searchResults)
|
viewModel.searchResultList.addAll(searchResults)
|
||||||
binding.refreshProgressBar.isAutoLoading = false
|
binding.refreshProgressBar.isAutoLoading = false
|
||||||
binding.tvCurrentSearchInfo.text = this@SearchContentActivity.getString(R.string.search_content_size) +": ${viewModel.searchResultCounts}"
|
|
||||||
adapter.addItems(searchResults)
|
adapter.addItems(searchResults)
|
||||||
searchResults = listOf()
|
searchResults = listOf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
binding.refreshProgressBar.isAutoLoading = false
|
binding.refreshProgressBar.isAutoLoading = false
|
||||||
|
if (viewModel.searchResultCounts == 0) {
|
||||||
|
val noSearchResult = SearchResult(resultText = getString(R.string.search_content_empty))
|
||||||
|
adapter.addItem(noSearchResult)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class SearchContentAdapter(context: Context, val callback: Callback) :
|
|||||||
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchListBinding) {
|
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchListBinding) {
|
||||||
holder.itemView.setOnClickListener {
|
holder.itemView.setOnClickListener {
|
||||||
getItem(holder.layoutPosition)?.let {
|
getItem(holder.layoutPosition)?.let {
|
||||||
callback.openSearchResult(it)
|
if (!it.query.isBlank()) callback.openSearchResult(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ data class SearchResult(
|
|||||||
val resultCountWithinChapter: Int = 0,
|
val resultCountWithinChapter: Int = 0,
|
||||||
val resultText: String = "",
|
val resultText: String = "",
|
||||||
val chapterTitle: String = "",
|
val chapterTitle: String = "",
|
||||||
val query: String,
|
val query: String = "",
|
||||||
val pageSize: Int = 0,
|
val pageSize: Int = 0,
|
||||||
val chapterIndex: Int = 0,
|
val chapterIndex: Int = 0,
|
||||||
val pageIndex: Int = 0,
|
val pageIndex: Int = 0,
|
||||||
@ -17,6 +17,7 @@ data class SearchResult(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
fun getHtmlCompat(textColor: String, accentColor: String): Spanned {
|
fun getHtmlCompat(textColor: String, accentColor: String): Spanned {
|
||||||
|
if (!query.isBlank()) {
|
||||||
val queryIndexInSurrounding = resultText.indexOf(query)
|
val queryIndexInSurrounding = resultText.indexOf(query)
|
||||||
val leftString = resultText.substring(0, queryIndexInSurrounding)
|
val leftString = resultText.substring(0, queryIndexInSurrounding)
|
||||||
val rightString = resultText.substring(queryIndexInSurrounding + query.length, resultText.length)
|
val rightString = resultText.substring(queryIndexInSurrounding + query.length, resultText.length)
|
||||||
@ -25,6 +26,9 @@ data class SearchResult(
|
|||||||
rightString.colorTextForHtml(textColor) +
|
rightString.colorTextForHtml(textColor) +
|
||||||
chapterTitle.colorTextForHtml(accentColor)
|
chapterTitle.colorTextForHtml(accentColor)
|
||||||
return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
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) = "<font color=#${textColor}>$this</font>"
|
private fun String.colorTextForHtml(textColor: String) = "<font color=#${textColor}>$this</font>"
|
||||||
|
@ -907,6 +907,7 @@
|
|||||||
<string name="font_scale">字体大小</string>
|
<string name="font_scale">字体大小</string>
|
||||||
<string name="font_scale_summary">当前字体大小:%.1f</string>
|
<string name="font_scale_summary">当前字体大小:%.1f</string>
|
||||||
<string name="search_content_size">search result</string>
|
<string name="search_content_size">search result</string>
|
||||||
|
<string name="search_content_empty">search result is empty</string>
|
||||||
<string name="tts_speech_reduce">语速减</string>
|
<string name="tts_speech_reduce">语速减</string>
|
||||||
<string name="tts_speech_add">语速加</string>
|
<string name="tts_speech_add">语速加</string>
|
||||||
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
||||||
|
@ -910,6 +910,7 @@
|
|||||||
<string name="font_scale">字体大小</string>
|
<string name="font_scale">字体大小</string>
|
||||||
<string name="font_scale_summary">当前字体大小:%.1f</string>
|
<string name="font_scale_summary">当前字体大小:%.1f</string>
|
||||||
<string name="search_content_size">search result</string>
|
<string name="search_content_size">search result</string>
|
||||||
|
<string name="search_content_empty">search result is empty</string>
|
||||||
<string name="tts_speech_reduce">语速减</string>
|
<string name="tts_speech_reduce">语速减</string>
|
||||||
<string name="tts_speech_add">语速加</string>
|
<string name="tts_speech_add">语速加</string>
|
||||||
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
||||||
|
@ -910,6 +910,7 @@
|
|||||||
<string name="font_scale">字体大小</string>
|
<string name="font_scale">字体大小</string>
|
||||||
<string name="font_scale_summary">当前字体大小:%.1f</string>
|
<string name="font_scale_summary">当前字体大小:%.1f</string>
|
||||||
<string name="search_content_size">search result</string>
|
<string name="search_content_size">search result</string>
|
||||||
|
<string name="search_content_empty">search result is empty</string>
|
||||||
<string name="tts_speech_reduce">语速减</string>
|
<string name="tts_speech_reduce">语速减</string>
|
||||||
<string name="tts_speech_add">语速加</string>
|
<string name="tts_speech_add">语速加</string>
|
||||||
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
||||||
|
@ -901,6 +901,7 @@
|
|||||||
<string name="use_browser_open">是否使用外部瀏覽器打開?</string>
|
<string name="use_browser_open">是否使用外部瀏覽器打開?</string>
|
||||||
<string name="see">查看</string>
|
<string name="see">查看</string>
|
||||||
<string name="search_content_size">搜索結果</string>
|
<string name="search_content_size">搜索結果</string>
|
||||||
|
<string name="search_content_empty">搜索結果为空</string>
|
||||||
<string name="open">打開</string>
|
<string name="open">打開</string>
|
||||||
<string name="del_login_header">刪除登錄頭</string>
|
<string name="del_login_header">刪除登錄頭</string>
|
||||||
<string name="show_login_header">查看登錄頭</string>
|
<string name="show_login_header">查看登錄頭</string>
|
||||||
|
@ -913,6 +913,7 @@
|
|||||||
<string name="open_sys_dir_picker_error">打開系統資料夾選擇器出錯,自動打開應用程式資料夾選擇器</string>
|
<string name="open_sys_dir_picker_error">打開系統資料夾選擇器出錯,自動打開應用程式資料夾選擇器</string>
|
||||||
<string name="expand_text_menu">展開文字選擇選單</string>
|
<string name="expand_text_menu">展開文字選擇選單</string>
|
||||||
<string name="search_content_size">搜尋結果</string>
|
<string name="search_content_size">搜尋結果</string>
|
||||||
|
<string name="search_content_empty">搜尋結果为空</string>
|
||||||
<string name="book_tree_uri_t">書籍儲存位置</string>
|
<string name="book_tree_uri_t">書籍儲存位置</string>
|
||||||
<string name="book_tree_uri_s">從其它應用程式打開的書籍儲存位置</string>
|
<string name="book_tree_uri_s">從其它應用程式打開的書籍儲存位置</string>
|
||||||
<string name="bg_alpha">背景透明度</string>
|
<string name="bg_alpha">背景透明度</string>
|
||||||
|
@ -780,6 +780,7 @@
|
|||||||
<string name="sort_by_lastUpdateTime">更新时间排序</string>
|
<string name="sort_by_lastUpdateTime">更新时间排序</string>
|
||||||
<string name="search_content">全文搜索</string>
|
<string name="search_content">全文搜索</string>
|
||||||
<string name="search_content_size">搜索结果</string>
|
<string name="search_content_size">搜索结果</string>
|
||||||
|
<string name="search_content_empty">搜索结果为空</string>
|
||||||
<string name="rss_source_empty">关注公众号[开源阅读]获取订阅源!</string>
|
<string name="rss_source_empty">关注公众号[开源阅读]获取订阅源!</string>
|
||||||
<string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string>
|
<string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string>
|
||||||
<string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string>
|
<string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string>
|
||||||
|
@ -911,6 +911,7 @@
|
|||||||
<string name="font_scale">font scale</string>
|
<string name="font_scale">font scale</string>
|
||||||
<string name="font_scale_summary">font scale:%.1f</string>
|
<string name="font_scale_summary">font scale:%.1f</string>
|
||||||
<string name="search_content_size">search result</string>
|
<string name="search_content_size">search result</string>
|
||||||
|
<string name="search_content_empty">search result is empty</string>
|
||||||
<string name="tts_speech_reduce">语速减</string>
|
<string name="tts_speech_reduce">语速减</string>
|
||||||
<string name="tts_speech_add">语速加</string>
|
<string name="tts_speech_add">语速加</string>
|
||||||
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user