fix icon
fix constructedText
searchResultCounts update for new search
pull/374/head
Jason Yao 4 years ago
parent cddbc8f05b
commit f923317146
  1. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt
  4. 1
      app/src/main/res/values-zh-rHK/strings.xml
  5. 1
      app/src/main/res/values-zh-rTW/strings.xml
  6. 1
      app/src/main/res/values-zh/strings.xml
  7. 2
      app/src/main/res/values/strings.xml

@ -671,6 +671,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
/** /**
* 打开搜索界面 * 打开搜索界面
*/ */
//todo: change request code
override fun openSearchList() { override fun openSearchList() {
ReadBook.book?.let { ReadBook.book?.let {
startActivityForResult<SearchListActivity>( startActivityForResult<SearchListActivity>(

@ -99,9 +99,11 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun startContentSearch(newText: String?) { override fun startContentSearch(newText: String) {
if (!newText.isNullOrBlank()) { // 按章节搜索内容
if (!newText.isBlank()) {
adapter.clearItems() adapter.clearItems()
searchResultCounts = 0
viewModel.lastQuery = newText viewModel.lastQuery = newText
App.db.bookChapterDao().getChapterList(viewModel.bookUrl).map{ App.db.bookChapterDao().getChapterList(viewModel.bookUrl).map{
launch(IO) { launch(IO) {
@ -166,7 +168,7 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
*/ */
positions = searchPosition(bookContent, query) positions = searchPosition(bookContent, query)
positions?.map{ positions?.map{
val construct = constructText(bookContent, it) val construct = constructText(bookContent, it, query)
val result = SearchResult(index = 0, val result = SearchResult(index = 0,
text = construct[1] as String, text = construct[1] as String,
chapterTitle = chapter.title, chapterTitle = chapter.title,
@ -197,14 +199,14 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
return position return position
} }
private fun constructText(content: String, position: Int): Array<Any>{ private fun constructText(content: String, position: Int, query: String): Array<Any>{
// 构建关键词周边文字,在搜索结果里显示 // 构建关键词周边文字,在搜索结果里显示
// todo: 判断段落,只在关键词所在段落内分割 // todo: 判断段落,只在关键词所在段落内分割
// todo: 利用标点符号分割完整的句 // todo: 利用标点符号分割完整的句
// todo: length和设置结合,自由调整周边文字长度 // todo: length和设置结合,自由调整周边文字长度
val length = 20 val length = 20
var po1 = position - length var po1 = position - length
var po2 = position + length var po2 = position + query.length + length
if (po1 <0) { if (po1 <0) {
po1 = 0 po1 = 0
} }
@ -212,7 +214,7 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
po2 = content.length po2 = content.length
} }
val newPosition = position - po1 val newPosition = position - po1
val newText = "..." + content.substring(po1, po2) val newText = content.substring(po1, po2)
return arrayOf(newPosition, newText) return arrayOf(newPosition, newText)
} }

@ -21,13 +21,13 @@ class SearchListViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun startContentSearch(newText: String?) { fun startContentSearch(newText: String) {
searchCallBack?.startContentSearch(newText) searchCallBack?.startContentSearch(newText)
} }
interface SearchListCallBack { interface SearchListCallBack {
fun startContentSearch(newText: String?) fun startContentSearch(newText: String)
} }
} }

@ -761,5 +761,6 @@
<string name="select_theme">切換默認主題</string> <string name="select_theme">切換默認主題</string>
<string name="share_selected_source">分享選中書源</string> <string name="share_selected_source">分享選中書源</string>
<string name="sort_by_lastUppdateTime">時間排序</string> <string name="sort_by_lastUppdateTime">時間排序</string>
<string name="search_content">搜索</string>
</resources> </resources>

@ -761,6 +761,7 @@
<string name="select_theme">切換默認主題</string> <string name="select_theme">切換默認主題</string>
<string name="share_selected_source">分享選中書源</string> <string name="share_selected_source">分享選中書源</string>
<string name="sort_by_lastUppdateTime">時間排序</string> <string name="sort_by_lastUppdateTime">時間排序</string>
<string name="search_content">搜索</string>
</resources> </resources>

@ -761,5 +761,6 @@
<string name="theme_list_summary">使用保存主题,导入,分享主题</string> <string name="theme_list_summary">使用保存主题,导入,分享主题</string>
<string name="select_theme">切换默认主题</string> <string name="select_theme">切换默认主题</string>
<string name="sort_by_lastUppdateTime">时间排序</string> <string name="sort_by_lastUppdateTime">时间排序</string>
<string name="search_content">搜索</string>
</resources> </resources>

@ -763,6 +763,6 @@
<string name="theme_list_summary">Save, Import, Share theme</string> <string name="theme_list_summary">Save, Import, Share theme</string>
<string name="share_selected_source">Share selected sources</string> <string name="share_selected_source">Share selected sources</string>
<string name="sort_by_lastUppdateTime">Sort by update time</string> <string name="sort_by_lastUppdateTime">Sort by update time</string>
<string name="search_content">Search content</string> <string name="search_content">Search</string>
</resources> </resources>
Loading…
Cancel
Save