Merge pull request #1570 from Xwite/master

fix:搜索完成后关闭搜索显示;未搜索到内容提示用户
pull/1578/head
kunfei 3 years ago committed by GitHub
commit edf9b8bc94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt
  4. 22
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt
  5. 1
      app/src/main/res/values-es-rES/strings.xml
  6. 1
      app/src/main/res/values-ja-rJP/strings.xml
  7. 1
      app/src/main/res/values-pt-rBR/strings.xml
  8. 1
      app/src/main/res/values-zh-rHK/strings.xml
  9. 1
      app/src/main/res/values-zh-rTW/strings.xml
  10. 1
      app/src/main/res/values-zh/strings.xml
  11. 1
      app/src/main/res/values/strings.xml

@ -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
}
}

@ -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)
}
}
}

@ -75,10 +75,13 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
private fun searchPosition(pattern: String): List<Int> {
val position: MutableList<Int> = 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)

@ -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) = "<font color=#${textColor}>$this</font>"

@ -907,6 +907,7 @@
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</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_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>

@ -910,6 +910,7 @@
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</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_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>

@ -910,6 +910,7 @@
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</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_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>

@ -901,6 +901,7 @@
<string name="use_browser_open">是否使用外部瀏覽器打開?</string>
<string name="see">查看</string>
<string name="search_content_size">搜索結果</string>
<string name="search_content_empty">搜索結果为空</string>
<string name="open">打開</string>
<string name="del_login_header">刪除登錄頭</string>
<string name="show_login_header">查看登錄頭</string>

@ -913,6 +913,7 @@
<string name="open_sys_dir_picker_error">打開系統資料夾選擇器出錯,自動打開應用程式資料夾選擇器</string>
<string name="expand_text_menu">展開文字選擇選單</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_s">從其它應用程式打開的書籍儲存位置</string>
<string name="select_book_folder">选择保存书籍的文件夹</string>

@ -780,6 +780,7 @@
<string name="sort_by_lastUpdateTime">更新时间排序</string>
<string name="search_content">全文搜索</string>
<string name="search_content_size">搜索结果</string>
<string name="search_content_empty">搜索结果为空</string>
<string name="rss_source_empty">关注公众号[开源阅读]获取订阅源!</string>
<string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string>
<string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string>

@ -911,6 +911,7 @@
<string name="font_scale">font scale</string>
<string name="font_scale_summary">font scale:%.1f</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_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>

Loading…
Cancel
Save