diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index b4ff2583b..3d379ac41 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -1,17 +1,23 @@ package io.legado.app.ui.chapterlist import android.os.Bundle +import android.view.Menu +import androidx.appcompat.widget.SearchView +import androidx.core.view.isGone import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_chapter_list.* import kotlinx.android.synthetic.main.view_title_bar.* class ChapterListActivity : BaseActivity(R.layout.activity_chapter_list) { + private var searchView: SearchView? = null + override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) tab_layout.visible() @@ -19,6 +25,28 @@ class ChapterListActivity : BaseActivity(R.layout.activity_chapter_list) { tab_layout.setupWithViewPager(view_pager) } + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.search_view, menu) + val search = menu.findItem(R.id.action_search) + searchView = search.actionView as SearchView + searchView?.maxWidth = resources.displayMetrics.widthPixels + searchView?.onActionViewCollapsed() + searchView?.setOnCloseListener { + tab_layout.visible() + false + } + searchView?.setOnSearchClickListener { tab_layout.gone() } + searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String): Boolean { + return false + } + + override fun onQueryTextChange(newText: String): Boolean { + return false + } + }) + return super.onCompatCreateOptionsMenu(menu) + } private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { @@ -41,4 +69,13 @@ class ChapterListActivity : BaseActivity(R.layout.activity_chapter_list) { } } + + override fun onBackPressed() { + if (tab_layout.isGone) { + searchView?.onActionViewCollapsed() + tab_layout.visible() + } else { + super.onBackPressed() + } + } } \ No newline at end of file diff --git a/app/src/main/res/menu/search_view.xml b/app/src/main/res/menu/search_view.xml new file mode 100644 index 000000000..ee23fae6b --- /dev/null +++ b/app/src/main/res/menu/search_view.xml @@ -0,0 +1,11 @@ + +
\ No newline at end of file