pull/37/head
kunfei 5 years ago
parent 3b007ea8ac
commit 83756d2671
  1. 27
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  2. 8
      app/src/main/res/menu/book_search.xml

@ -1,6 +1,8 @@
package io.legado.app.ui.book.search
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
@ -17,10 +19,8 @@ import io.legado.app.data.entities.SearchShow
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone
import io.legado.app.utils.invisible
import io.legado.app.utils.visible
import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_search.*
import kotlinx.android.synthetic.main.view_search.*
import kotlinx.coroutines.Dispatchers.IO
@ -43,6 +43,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private var searchBookData: LiveData<PagedList<SearchShow>>? = null
private var historyData: LiveData<List<SearchKeyword>>? = null
private var bookData: LiveData<List<Book>>? = null
private var precisionSearchMenuItem: MenuItem? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
@ -53,6 +54,24 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
upHistory()
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_search, menu)
precisionSearchMenuItem = menu.findItem(R.id.menu_precision_search)
precisionSearchMenuItem?.isChecked = getPrefBoolean("precisionSearch")
return super.onCompatCreateOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_precision_search -> {
putPrefBoolean("precisionSearch", !getPrefBoolean("precisionSearch"))
precisionSearchMenuItem?.isChecked = getPrefBoolean("precisionSearch")
}
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
}
return super.onCompatOptionsItemSelected(item)
}
private fun initSearchView() {
ATH.setTint(search_view, primaryTextColor)
search_view.onActionViewExpanded()

@ -4,7 +4,13 @@
tools:context=".view.activity.MainActivity">
<item
android:id="@+id/action_book_source_manage"
android:id="@+id/menu_precision_search"
android:title="@string/book_source_manage"
android:checkable="true"
app:showAsAction="never" />
<item
android:id="@+id/menu_source_manage"
android:title="@string/book_source_manage"
app:showAsAction="never" />
Loading…
Cancel
Save