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. 4
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt
  5. 1
      app/src/main/res/values-zh-rHK/strings.xml
  6. 1
      app/src/main/res/values-zh-rTW/strings.xml
  7. 1
      app/src/main/res/values-zh/strings.xml
  8. 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() {
ReadBook.book?.let {
startActivityForResult<SearchListActivity>(

@ -99,9 +99,11 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
}
@SuppressLint("SetTextI18n")
override fun startContentSearch(newText: String?) {
if (!newText.isNullOrBlank()) {
override fun startContentSearch(newText: String) {
// 按章节搜索内容
if (!newText.isBlank()) {
adapter.clearItems()
searchResultCounts = 0
viewModel.lastQuery = newText
App.db.bookChapterDao().getChapterList(viewModel.bookUrl).map{
launch(IO) {
@ -166,7 +168,7 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
*/
positions = searchPosition(bookContent, query)
positions?.map{
val construct = constructText(bookContent, it)
val construct = constructText(bookContent, it, query)
val result = SearchResult(index = 0,
text = construct[1] as String,
chapterTitle = chapter.title,
@ -197,14 +199,14 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
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: length和设置结合,自由调整周边文字长度
val length = 20
var po1 = position - length
var po2 = position + length
var po2 = position + query.length + length
if (po1 <0) {
po1 = 0
}
@ -212,7 +214,7 @@ class SearchListFragment : VMBaseFragment<SearchListViewModel>(R.layout.fragment
po2 = content.length
}
val newPosition = position - po1
val newText = "..." + content.substring(po1, po2)
val newText = content.substring(po1, po2)
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)
}
interface SearchListCallBack {
fun startContentSearch(newText: String?)
fun startContentSearch(newText: String)
}
}

@ -14,9 +14,9 @@ data class SearchResult(
get(){
val sub1 = text.substring(0, newPosition)
val sub2 = text.substring(newPosition + query.length, text.length)
return "<font color=#000000>$sub1</font> " +
return "<font color=#000000>$sub1</font>" +
"<font color=#ff0000>$query</font>" +
"<font color=#000000>$sub2</font> " +
"<font color=#000000>$sub2</font>" +
"<font color=#0000ff>($chapterTitle)</font>"
}

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

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

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

@ -763,6 +763,6 @@
<string name="theme_list_summary">Save, Import, Share theme</string>
<string name="share_selected_source">Share selected sources</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>
Loading…
Cancel
Save