From 1ca5625edd38daf39f069b66b54d715274fc4254 Mon Sep 17 00:00:00 2001 From: Mihai Adrian <48995920+mcarare@users.noreply.github.com> Date: Tue, 5 May 2020 21:15:30 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/10408: Dismiss menu when navigating away. (https://github.com/mozilla-mobile/fenix/pull/10415) The menu is dismissed when toolbar view is detached from window. --- .../fenix/components/toolbar/MenuPresenter.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/MenuPresenter.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/MenuPresenter.kt index de6d1105ec..35d942a503 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/MenuPresenter.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/MenuPresenter.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix.components.toolbar +import android.view.View import mozilla.components.browser.session.SelectionAwareSessionObserver import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager @@ -14,10 +15,11 @@ class MenuPresenter( private val menuToolbar: BrowserToolbar, sessionManager: SessionManager, private val sessionId: String? = null -) : SelectionAwareSessionObserver(sessionManager) { +) : SelectionAwareSessionObserver(sessionManager), View.OnAttachStateChangeListener { fun start() { observeIdOrSelected(sessionId) + menuToolbar.addOnAttachStateChangeListener(this) } /** Redraw the refresh/stop button */ @@ -38,4 +40,12 @@ class MenuPresenter( fun invalidateActions() { menuToolbar.invalidateActions() } + + override fun onViewDetachedFromWindow(v: View?) { + menuToolbar.onStop() + } + + override fun onViewAttachedToWindow(v: View?) { + // no-op + } }