From d3cbfbdb59c10f364e663c13dc13d85f0cd16fef Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 26 Jul 2017 11:29:03 +0200 Subject: [PATCH] Add workaround for disappearing menu items --- .../ui/base/controller/BaseController.kt | 21 +++++++++++++++++++ .../tachiyomi/ui/library/LibraryController.kt | 2 ++ 2 files changed, 23 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index f8cc74a308..9f55cd033b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -1,8 +1,10 @@ package eu.kanade.tachiyomi.ui.base.controller import android.os.Bundle +import android.support.v4.view.MenuItemCompat import android.support.v7.app.AppCompatActivity import android.view.LayoutInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup import com.bluelinelabs.conductor.ControllerChangeHandler @@ -44,4 +46,23 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr (activity as? AppCompatActivity)?.supportActionBar?.title = getTitle() } + /** + * Workaround for disappearing menu items when collapsing an expandable item like a SearchView. + * This method should be removed when fixed upstream. + * Issue link: https://issuetracker.google.com/issues/37657375 + */ + fun MenuItem.fixExpand() { + val expandListener = object : MenuItemCompat.OnActionExpandListener { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { + return true + } + + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { + activity?.invalidateOptionsMenu() + return true + } + } + MenuItemCompat.setOnActionExpandListener(this, expandListener) + } + } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index a04eea87ff..34b190d2dd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -346,6 +346,8 @@ class LibraryController( query = it.toString() searchRelay.call(query) } + + searchItem.fixExpand() } override fun onPrepareOptionsMenu(menu: Menu) {