优化正文搜索

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.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.*
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
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.delegate.PageDelegate
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.login.SourceLogin
import io.legado.app.ui.replacerule.ReplaceRuleActivity
@ -496,6 +494,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
)
return true
}
R.id.menu_search_content -> {
openSearchActivity(selectedText)
return true
}
}
return false
}
@ -680,12 +682,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
/**
* 打开搜索界面
*/
//todo: change request code
override fun openSearchList() {
override fun openSearchActivity(searchWord: String?) {
ReadBook.book?.let {
startActivityForResult<SearchListActivity>(
requestCodeSearchResult,
Pair("bookUrl", it.bookUrl)
Pair("bookUrl", it.bookUrl),
Pair("searchWord", searchWord)
)
}
}

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

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

@ -9,7 +9,6 @@ import io.legado.app.data.entities.Book
class SearchListViewModel(application: Application) : BaseViewModel(application) {
var bookUrl: String = ""
var book: Book? = null
var searchCallBack: SearchListCallBack? = null
var lastQuery: String = ""
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:title="@string/read_aloud" />
<item
android:id="@+id/menu_search_content"
android:title="@string/search_content" />
<item
android:id="@+id/menu_browser"
android:title="@string/browser" />

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

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

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

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