优化全文搜索

pull/406/head
gedoor 4 years ago
parent d6532eb87e
commit 0f6b7dc587
  1. 2
      app/src/main/AndroidManifest.xml
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 17
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt
  6. 41
      app/src/main/res/layout/activity_book_search.xml
  7. 8
      app/src/main/res/layout/activity_search_content.xml

@ -224,7 +224,7 @@
android:launchMode="singleTop"
android:screenOrientation="behind" />
<activity
android:name=".ui.book.searchContent.SearchListActivity"
android:name=".ui.book.searchContent.SearchContentActivity"
android:launchMode="singleTop"
android:screenOrientation="behind" />
<!-- RSS条目 -->

@ -47,7 +47,7 @@ import io.legado.app.ui.book.read.page.ContentTextView
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.SearchContentActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.login.SourceLogin
import io.legado.app.ui.replacerule.ReplaceRuleActivity
@ -685,7 +685,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
*/
override fun openSearchActivity(searchWord: String?) {
ReadBook.book?.let {
startActivityForResult<SearchListActivity>(
startActivityForResult<SearchContentActivity>(
requestCodeSearchResult,
Pair("bookUrl", it.bookUrl),
Pair("searchWord", searchWord ?: viewModel.searchContentQuery)

@ -22,19 +22,20 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent
import kotlinx.android.synthetic.main.activity_search_list.*
import kotlinx.android.synthetic.main.activity_search_content.*
import kotlinx.android.synthetic.main.view_search.*
import kotlinx.coroutines.*
import org.jetbrains.anko.sdk27.listeners.onClick
class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity_search_list),
SearchListAdapter.Callback {
class SearchContentActivity :
VMBaseActivity<SearchContentViewModel>(R.layout.activity_search_content),
SearchContentAdapter.Callback {
override val viewModel: SearchListViewModel
get() = getViewModel(SearchListViewModel::class.java)
override val viewModel: SearchContentViewModel
get() = getViewModel(SearchContentViewModel::class.java)
lateinit var adapter: SearchListAdapter
lateinit var adapter: SearchContentAdapter
private lateinit var mLayoutManager: UpLinearLayoutManager
private var searchResultCounts = 0
private var durChapterIndex = 0
@ -78,7 +79,7 @@ class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity
}
private fun initRecyclerView() {
adapter = SearchListAdapter(this, this)
adapter = SearchContentAdapter(this, this)
mLayoutManager = UpLinearLayoutManager(this)
recycler_view.layoutManager = mLayoutManager
recycler_view.addItemDecoration(VerticalDivider(this))
@ -134,6 +135,7 @@ class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity
if (!newText.isBlank()) {
adapter.clearItems()
searchResultList.clear()
refresh_progress_bar.isAutoLoading = true
searchResultCounts = 0
viewModel.lastQuery = newText
var searchResults = listOf<SearchResult>()
@ -149,6 +151,7 @@ class SearchListActivity : VMBaseActivity<SearchListViewModel>(R.layout.activity
job.await()
if (searchResults.isNotEmpty()) {
searchResultList.addAll(searchResults)
refresh_progress_bar.isAutoLoading = false
tv_current_search_info.text = "搜索结果:$searchResultCounts"
adapter.addItems(searchResults)
searchResults = listOf()

@ -10,7 +10,7 @@ import io.legado.app.utils.hexString
import kotlinx.android.synthetic.main.item_search_list.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class SearchListAdapter(context: Context, val callback: Callback) :
class SearchContentAdapter(context: Context, val callback: Callback) :
SimpleRecyclerAdapter<SearchResult>(context, R.layout.item_search_list) {
val cacheFileNames = hashSetOf<String>()

@ -6,7 +6,7 @@ import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
class SearchListViewModel(application: Application) : BaseViewModel(application) {
class SearchContentViewModel(application: Application) : BaseViewModel(application) {
var bookUrl: String = ""
var book: Book? = null
var lastQuery: String = ""

@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.book.search.SearchActivity">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentLayout="@layout/view_search"
app:contentInsetStartWithNavigation="0dp"
app:layout_constraintTop_toTopOf="parent"
app:title="搜索"/>
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetStartWithNavigation="0dp"
app:contentLayout="@layout/view_search"
app:layout_constraintTop_toTopOf="parent"
app:title="搜索" />
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/refresh_progress_bar"
@ -23,10 +22,10 @@
app:layout_constraintTop_toBottomOf="@id/title_bar" />
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/refresh_progress_bar">
<androidx.recyclerview.widget.RecyclerView
@ -41,12 +40,12 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/background"
android:orientation="vertical"
android:visibility="gone"
android:clickable="true"
android:focusable="true"
app:layout_constraintTop_toBottomOf="@id/title_bar"
app:layout_constraintBottom_toBottomOf="parent">
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_bar">
<TextView
android:id="@+id/tv_book_show"

@ -13,13 +13,19 @@
app:contentInsetRight="24dp"
app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/refresh_progress_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
app:layout_constraintTop_toBottomOf="@id/title_bar" />
<io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:overScrollMode="never"
app:layout_constraintBottom_toTopOf="@+id/ll_search_base_info"
app:layout_constraintTop_toBottomOf="@id/title_bar" />
app:layout_constraintTop_toBottomOf="@id/refresh_progress_bar" />
<LinearLayout
android:id="@+id/ll_search_base_info"
Loading…
Cancel
Save