From 0fabe4bd013a1980b0fa3e70306e851acd1b5bc3 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 25 Sep 2022 19:53:34 +0700 Subject: [PATCH] GlobalSearchController: Auto focus search view when initial query is empty (#8073) --- .../source/globalsearch/GlobalSearchController.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt index 46a243b1a0..b892f30b6e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt @@ -95,6 +95,20 @@ open class GlobalSearchController( ) optionsMenuSearchItem = menu.findItem(R.id.action_search) + + // Focus search on launch from browse screen + if (initialQuery.isNullOrEmpty()) { + optionsMenuSearchItem?.expandActionView() + } + } + + override fun onSearchMenuItemActionCollapse(item: MenuItem?) { + super.onSearchMenuItemActionCollapse(item) + // Close this screen if query is empty + // i.e. launch from browse screen and clicking the back button icon without making any search + if (presenter.query.isEmpty()) { + router.popCurrentController() + } } override fun onSearchMenuItemActionExpand(item: MenuItem?) {