From 83756d26711bb99c4fc5ac1f668dc6da8785e09c Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 19 Oct 2019 10:57:51 +0800 Subject: [PATCH] up --- .../app/ui/book/search/SearchActivity.kt | 27 ++++++++++++++++--- .../menu/{search_book.xml => book_search.xml} | 8 +++++- 2 files changed, 30 insertions(+), 5 deletions(-) rename app/src/main/res/menu/{search_book.xml => book_search.xml} (63%) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 03b6755b3..da00dd4ef 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -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(R.layout.activity_book_se private var searchBookData: LiveData>? = null private var historyData: LiveData>? = null private var bookData: LiveData>? = null + private var precisionSearchMenuItem: MenuItem? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() @@ -53,6 +54,24 @@ class SearchActivity : VMBaseActivity(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() + } + return super.onCompatOptionsItemSelected(item) + } + private fun initSearchView() { ATH.setTint(search_view, primaryTextColor) search_view.onActionViewExpanded() diff --git a/app/src/main/res/menu/search_book.xml b/app/src/main/res/menu/book_search.xml similarity index 63% rename from app/src/main/res/menu/search_book.xml rename to app/src/main/res/menu/book_search.xml index a55a3ed35..33e0b51f5 100644 --- a/app/src/main/res/menu/search_book.xml +++ b/app/src/main/res/menu/book_search.xml @@ -4,7 +4,13 @@ tools:context=".view.activity.MainActivity"> + +