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 292bf2e32..860c4d590 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 @@ -89,15 +89,16 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr * This method should be removed when fixed upstream. * Issue link: https://issuetracker.google.com/issues/37657375 */ - fun MenuItem.fixExpand() { + fun MenuItem.fixExpand(onExpand: ((MenuItem) -> Boolean)? = null, onCollapse: ((MenuItem) -> Boolean)? = null) { setOnActionExpandListener(object : MenuItem.OnActionExpandListener { override fun onMenuItemActionExpand(item: MenuItem): Boolean { - return true + return onExpand?.invoke(item) ?: true } override fun onMenuItemActionCollapse(item: MenuItem): Boolean { activity?.invalidateOptionsMenu() - return true + + return onCollapse?.invoke(item) ?: true } }) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 3ea5eb68f..f73bb0938 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -36,7 +36,6 @@ import kotlinx.android.synthetic.main.main_activity.* import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers -import rx.subscriptions.Subscriptions import timber.log.Timber import uy.kohesive.injekt.injectLazy import java.util.concurrent.TimeUnit @@ -228,6 +227,7 @@ open class BrowseCatalogueController(bundle: Bundle) : val searchEventsObservable = searchView.queryTextChangeEvents() .skip(1) + .filter { router.backstack.lastOrNull()?.controller() == this@BrowseCatalogueController } .share() val writingObservable = searchEventsObservable .filter { !it.isSubmitted } @@ -238,11 +238,12 @@ open class BrowseCatalogueController(bundle: Bundle) : searchViewSubscription?.unsubscribe() searchViewSubscription = Observable.merge(writingObservable, submitObservable) .map { it.queryText().toString() } - .distinctUntilChanged() .subscribeUntilDestroy { searchWithQuery(it) } - untilDestroySubscriptions.add( - Subscriptions.create { if (isActionViewExpanded) collapseActionView() }) + fixExpand(onCollapse = { + searchWithQuery("") + true + }) } // Setup filters button @@ -310,11 +311,6 @@ open class BrowseCatalogueController(bundle: Bundle) : if (presenter.query == newQuery) return - // FIXME dirty fix to restore the toolbar buttons after closing search mode. - if (newQuery == "") { - activity?.invalidateOptionsMenu() - } - showProgressBar() adapter?.clear()