diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 19a01a8ec..bc6198e83 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -671,6 +671,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 打开搜索界面 */ + //todo: change request code override fun openSearchList() { ReadBook.book?.let { startActivityForResult( diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt index 792bbdb7f..795ef6505 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListFragment.kt @@ -99,9 +99,11 @@ class SearchListFragment : VMBaseFragment(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(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(R.layout.fragment return position } - private fun constructText(content: String, position: Int): Array{ + private fun constructText(content: String, position: Int, query: String): Array{ // 构建关键词周边文字,在搜索结果里显示 // 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(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) } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt index 81c223d30..060d74067 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt @@ -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) } } \ No newline at end of file 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 b60aaebc4..7682a9b5d 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 @@ -14,9 +14,9 @@ data class SearchResult( get(){ val sub1 = text.substring(0, newPosition) val sub2 = text.substring(newPosition + query.length, text.length) - return "$sub1 " + + return "$sub1" + "$query" + - "$sub2 " + + "$sub2" + "($chapterTitle)" } diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index ea85c0c29..c585ffb97 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -761,5 +761,6 @@ 切換默認主題 分享選中書源 時間排序 + 搜索 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c14a9a485..006b4ff45 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -761,6 +761,7 @@ 切換默認主題 分享選中書源 時間排序 + 搜索 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 036bcd6f9..78487a2be 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -761,5 +761,6 @@ 使用保存主题,导入,分享主题 切换默认主题 时间排序 + 搜索 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 84a7c6c58..893230b30 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -763,6 +763,6 @@ Save, Import, Share theme Share selected sources Sort by update time - Search content + Search \ No newline at end of file