From 9b69f9f5dbc091b214d9b390bfa04d8f502cd370 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Thu, 23 May 2019 13:46:23 -0400 Subject: [PATCH] Fixes #654 - Update refresh/stop toolbar buttons (#2702) (Also back and forward) --- CHANGELOG.md | 1 + .../fenix/components/toolbar/MenuPresenter.kt | 31 +++++++++++++++++++ .../components/toolbar/ToolbarIntegration.kt | 3 ++ buildSrc/src/main/java/Dependencies.kt | 1 + 4 files changed, 36 insertions(+) create mode 100644 app/src/main/java/org/mozilla/fenix/components/toolbar/MenuPresenter.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c7fc7f5f7..0e5c6e113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,5 +56,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - #1599 - Fixed a crash creating a bookmark for a custom tab - #1414 - Fixed site permissions settings getting reset in Android 6. - #1994 - Made app state persist better when rotating the screen +- #654 - Updated Refresh button to turn into Stop button while menu is open. - [AC #2725](https://github.com/mozilla-mobile/android-components/issues/2725) Updated tracking protectionPolicy to [recommend](https://github.com/mozilla-mobile/android-components/blob/master/components/concept/engine/src/main/java/mozilla/components/concept/engine/EngineSession.kt#L156) ### Removed 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 new file mode 100644 index 000000000..3e7c953dd --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/MenuPresenter.kt @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.components.toolbar + +import mozilla.components.browser.session.SelectionAwareSessionObserver +import mozilla.components.browser.session.Session +import mozilla.components.browser.session.SessionManager +import mozilla.components.browser.toolbar.BrowserToolbar + +class MenuPresenter( + private val menuToolbar: BrowserToolbar, + sessionManager: SessionManager, + private val sessionId: String? = null +) : SelectionAwareSessionObserver(sessionManager) { + + fun start() { + observeIdOrSelected(sessionId) + } + + /** Redraw the refresh/stop button */ + override fun onLoadingStateChanged(session: Session, loading: Boolean) { + menuToolbar.invalidateActions() + } + + /** Redraw the back and forward buttons */ + override fun onNavigationStateChanged(session: Session, canGoBack: Boolean, canGoForward: Boolean) { + menuToolbar.invalidateActions() + } +} diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt index 72b36b33d..03f1f3e2b 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt @@ -77,12 +77,15 @@ class ToolbarIntegration( ToolbarFeature.UrlRenderConfiguration(PublicSuffixList(context), DefaultThemeManager.resolveAttribute(R.attr.primaryText, context), renderStyle = renderStyle) ) + private var menuPresenter = MenuPresenter(toolbar, context.components.core.sessionManager, sessionId) override fun start() { + menuPresenter.start() toolbarPresenter.start() } override fun stop() { + menuPresenter.stop() toolbarPresenter.stop() } } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 1ab8576ab..a78c1b5ba 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -36,6 +36,7 @@ private object Versions { // be kept in sync with the version used by android-components above. const val mozilla_appservices = "0.28.1" + const val autodispose = "1.1.0" const val adjust = "4.11.4" const val installreferrer = "1.0"