优化正文搜索

pull/392/head 3.20.092019
gedoor 4 years ago
parent d092e82a5a
commit 60b5b536bf
  1. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  3. 11
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchListActivity.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchListViewModel.kt
  5. 4
      app/src/main/res/menu/content_select_action.xml
  6. 2
      app/src/main/res/values-zh-rHK/strings.xml
  7. 3
      app/src/main/res/values-zh-rTW/strings.xml
  8. 2
      app/src/main/res/values-zh/strings.xml
  9. 2
      app/src/main/res/values/strings.xml

@ -9,7 +9,6 @@ import android.graphics.drawable.ColorDrawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.util.Log
import android.view.* import android.view.*
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.core.view.get import androidx.core.view.get
@ -49,7 +48,6 @@ import io.legado.app.ui.book.read.page.PageView
import io.legado.app.ui.book.read.page.TextPageFactory import io.legado.app.ui.book.read.page.TextPageFactory
import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.read.page.delegate.PageDelegate
import io.legado.app.ui.book.searchContent.SearchListActivity import io.legado.app.ui.book.searchContent.SearchListActivity
import io.legado.app.ui.book.searchContent.SearchResult
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.login.SourceLogin import io.legado.app.ui.login.SourceLogin
import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity
@ -496,6 +494,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
) )
return true return true
} }
R.id.menu_search_content -> {
openSearchActivity(selectedText)
return true
}
} }
return false return false
} }
@ -680,12 +682,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
/** /**
* 打开搜索界面 * 打开搜索界面
*/ */
//todo: change request code override fun openSearchActivity(searchWord: String?) {
override fun openSearchList() {
ReadBook.book?.let { ReadBook.book?.let {
startActivityForResult<SearchListActivity>( startActivityForResult<SearchListActivity>(
requestCodeSearchResult, requestCodeSearchResult,
Pair("bookUrl", it.bookUrl) Pair("bookUrl", it.bookUrl),
Pair("searchWord", searchWord)
) )
} }
} }

@ -175,7 +175,7 @@ class ReadMenu : FrameLayout {
//搜索 //搜索
fabSearch.onClick { fabSearch.onClick {
runMenuOut { runMenuOut {
callBack?.openSearchList() callBack?.openSearchActivity(null)
} }
} }
@ -300,7 +300,7 @@ class ReadMenu : FrameLayout {
fun autoPage() fun autoPage()
fun openReplaceRule() fun openReplaceRule()
fun openChapterList() fun openChapterList()
fun openSearchList() fun openSearchActivity(searchWord: String?)
fun showReadStyle() fun showReadStyle()
fun showMoreSetting() fun showMoreSetting()
fun showReadAloudDialog() fun showReadAloudDialog()

@ -29,8 +29,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity_search_list), class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity_search_list),
SearchListAdapter.Callback, SearchListAdapter.Callback {
SearchListViewModel.SearchListCallBack {
override val viewModel: SearchListViewModel override val viewModel: SearchListViewModel
get() = getViewModel(SearchListViewModel::class.java) get() = getViewModel(SearchListViewModel::class.java)
@ -42,7 +41,6 @@ class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity
private var searchResultList: MutableList<SearchResult> = mutableListOf() private var searchResultList: MutableList<SearchResult> = mutableListOf()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.searchCallBack = this
val bbg = bottomBackground val bbg = bottomBackground
val btc = getPrimaryTextColor(ColorUtils.isColorLight(bbg)) val btc = getPrimaryTextColor(ColorUtils.isColorLight(bbg))
ll_search_base_info.setBackgroundColor(bbg) ll_search_base_info.setBackgroundColor(bbg)
@ -68,7 +66,7 @@ class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity
search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener { search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean { override fun onQueryTextSubmit(query: String): Boolean {
if (viewModel.lastQuery != query) { if (viewModel.lastQuery != query) {
viewModel.startContentSearch(query) startContentSearch(query)
} }
return false return false
} }
@ -103,6 +101,9 @@ class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity
viewModel.book?.let { viewModel.book?.let {
initCacheFileNames(it) initCacheFileNames(it)
durChapterIndex = it.durChapterIndex durChapterIndex = it.durChapterIndex
intent.getStringExtra("searchWord")?.let { searchWord ->
search_view.setQuery(searchWord, true)
}
} }
} }
} }
@ -128,7 +129,7 @@ class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun startContentSearch(newText: String) { fun startContentSearch(newText: String) {
// 按章节搜索内容 // 按章节搜索内容
if (!newText.isBlank()) { if (!newText.isBlank()) {
adapter.clearItems() adapter.clearItems()

@ -9,7 +9,6 @@ import io.legado.app.data.entities.Book
class SearchListViewModel(application: Application) : BaseViewModel(application) { class SearchListViewModel(application: Application) : BaseViewModel(application) {
var bookUrl: String = "" var bookUrl: String = ""
var book: Book? = null var book: Book? = null
var searchCallBack: SearchListCallBack? = null
var lastQuery: String = "" var lastQuery: String = ""
fun initBook(bookUrl: String, success: () -> Unit) { fun initBook(bookUrl: String, success: () -> Unit) {
@ -21,13 +20,4 @@ class SearchListViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun startContentSearch(newText: String) {
searchCallBack?.startContentSearch(newText)
}
interface SearchListCallBack {
fun startContentSearch(newText: String)
}
} }

@ -13,6 +13,10 @@
android:id="@+id/menu_aloud" android:id="@+id/menu_aloud"
android:title="@string/read_aloud" /> android:title="@string/read_aloud" />
<item
android:id="@+id/menu_search_content"
android:title="@string/search_content" />
<item <item
android:id="@+id/menu_browser" android:id="@+id/menu_browser"
android:title="@string/browser" /> android:title="@string/browser" />

@ -766,6 +766,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> <string name="search_content">全文搜索</string>
</resources> </resources>

@ -766,7 +766,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> <string name="search_content">全文搜索</string>
</resources> </resources>

@ -769,6 +769,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> <string name="search_content">全文搜索</string>
</resources> </resources>

@ -771,6 +771,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</string> <string name="search_content">Search content</string>
</resources> </resources>
Loading…
Cancel
Save