From b9399fac19ce1f90f7dcf8086bf75b3310edcd58 Mon Sep 17 00:00:00 2001 From: Harrison Oglesby Date: Thu, 25 Jan 2024 15:17:45 -0800 Subject: [PATCH] Bug 1864760 - Added actions to Toolbar and MenuButton to hide and show the menu button --- .../browser/toolbar/BrowserToolbar.kt | 14 +++++++++++ .../browser/toolbar/display/DisplayToolbar.kt | 14 +++++++++++ .../browser/toolbar/display/MenuButton.kt | 9 +++++++ .../browser/toolbar/BrowserToolbarTest.kt | 24 +++++++++++++++++++ .../components/concept/toolbar/Toolbar.kt | 10 ++++++++ .../CustomTabSessionTitleObserverTest.kt | 2 ++ .../toolbar/ToolbarAutocompleteFeatureTest.kt | 8 +++++++ .../feature/toolbar/ToolbarInteractorTest.kt | 8 +++++++ docs/changelog.md | 4 ++++ 9 files changed, 93 insertions(+) diff --git a/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt b/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt index 404c6f00e11b..488fdf628854 100644 --- a/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt +++ b/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt @@ -335,6 +335,20 @@ class BrowserToolbar @JvmOverloads constructor( edit.removeEditActionEnd(action) } + /** + * Hides the menu button in display mode. + */ + override fun hideMenuButton() { + display.hideMenuButton() + } + + /** + * Shows the menu button in display mode. + */ + override fun showMenuButton() { + display.showMenuButton() + } + /** * Switches to URL editing mode. * diff --git a/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt b/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt index 19a83d862666..a4f206fe4318 100644 --- a/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt +++ b/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt @@ -648,6 +648,20 @@ class DisplayToolbar internal constructor( internal fun removeNavigationAction(action: Toolbar.Action) { views.navigationActions.removeAction(action) } + + /** + * Hides the menu button in display mode. + */ + internal fun hideMenuButton() { + views.menu.setShouldBeHidden(true) + } + + /** + * Shows the menu button in display mode. + */ + internal fun showMenuButton() { + views.menu.setShouldBeHidden(false) + } } /** diff --git a/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/MenuButton.kt b/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/MenuButton.kt index 2a0990830962..621e20032b33 100644 --- a/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/MenuButton.kt +++ b/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/MenuButton.kt @@ -92,6 +92,15 @@ internal class MenuButton( fun setColorFilter(@ColorInt color: Int) = impl.setColorFilter(color) + /** + * Hides the menu button. + * + * @param shouldBeHidden A [Boolean] that determines the visibility of the menu button. + */ + fun setShouldBeHidden(shouldBeHidden: Boolean) { + impl.isVisible = !shouldBeHidden && shouldBeVisible() + } + @VisibleForTesting internal fun shouldBeVisible() = impl.menuBuilder != null || impl.menuController != null } diff --git a/android-components/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt b/android-components/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt index 735e1cc66f9b..33b7352a1728 100644 --- a/android-components/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt +++ b/android-components/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt @@ -542,6 +542,30 @@ class BrowserToolbarTest { verify(edit).removeEditActionEnd(action) } + @Test + fun `WHEN hideMenuButton is sent to BrowserToolbar THEN it will be forwarded to the DisplayToolbar`() { + val toolbar = BrowserToolbar(testContext) + + val display: DisplayToolbar = mock() + toolbar.display = display + + toolbar.hideMenuButton() + + verify(display).hideMenuButton() + } + + @Test + fun `WHEN showMenuButton is sent to BrowserToolbar THEN it will be forwarded to the DisplayToolbar`() { + val toolbar = BrowserToolbar(testContext) + + val display: DisplayToolbar = mock() + toolbar.display = display + + toolbar.showMenuButton() + + verify(display).showMenuButton() + } + @Test fun `cast to view`() { // Given diff --git a/android-components/components/concept/toolbar/src/main/java/mozilla/components/concept/toolbar/Toolbar.kt b/android-components/components/concept/toolbar/src/main/java/mozilla/components/concept/toolbar/Toolbar.kt index 740d71c84031..16c0e7c6655f 100644 --- a/android-components/components/concept/toolbar/src/main/java/mozilla/components/concept/toolbar/Toolbar.kt +++ b/android-components/components/concept/toolbar/src/main/java/mozilla/components/concept/toolbar/Toolbar.kt @@ -173,6 +173,16 @@ interface Toolbar { */ fun removeEditActionEnd(action: Action) + /** + * Hides the menu button in display mode. + */ + fun hideMenuButton() + + /** + * Shows the menu button in display mode. + */ + fun showMenuButton() + /** * Casts this toolbar to an Android View object. */ diff --git a/android-components/components/feature/customtabs/src/test/java/mozilla/components/feature/customtabs/feature/CustomTabSessionTitleObserverTest.kt b/android-components/components/feature/customtabs/src/test/java/mozilla/components/feature/customtabs/feature/CustomTabSessionTitleObserverTest.kt index 6551d181c64c..de293b5a7de9 100644 --- a/android-components/components/feature/customtabs/src/test/java/mozilla/components/feature/customtabs/feature/CustomTabSessionTitleObserverTest.kt +++ b/android-components/components/feature/customtabs/src/test/java/mozilla/components/feature/customtabs/feature/CustomTabSessionTitleObserverTest.kt @@ -88,6 +88,8 @@ class CustomTabSessionTitleObserverTest { override fun addEditActionStart(action: Toolbar.Action) = Unit override fun addEditActionEnd(action: Toolbar.Action) = Unit override fun removeEditActionEnd(action: Toolbar.Action) = Unit + override fun hideMenuButton() = Unit + override fun showMenuButton() = Unit override fun setOnEditListener(listener: Toolbar.OnEditListener) = Unit override fun displayMode() = Unit override fun editMode(cursorPlacement: Toolbar.CursorPlacement) = Unit diff --git a/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarAutocompleteFeatureTest.kt b/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarAutocompleteFeatureTest.kt index dda24d1fb5ab..6f493c232a45 100644 --- a/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarAutocompleteFeatureTest.kt +++ b/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarAutocompleteFeatureTest.kt @@ -115,6 +115,14 @@ class ToolbarAutocompleteFeatureTest { fail() } + override fun hideMenuButton() { + fail() + } + + override fun showMenuButton() { + fail() + } + override fun invalidateActions() { fail() } diff --git a/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarInteractorTest.kt b/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarInteractorTest.kt index d726015a825f..e84c9ad32b66 100644 --- a/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarInteractorTest.kt +++ b/android-components/components/feature/toolbar/src/test/java/mozilla/components/feature/toolbar/ToolbarInteractorTest.kt @@ -98,6 +98,14 @@ class ToolbarInteractorTest { fail() } + override fun hideMenuButton() { + fail() + } + + override fun showMenuButton() { + fail() + } + override fun invalidateActions() { fail() } diff --git a/docs/changelog.md b/docs/changelog.md index c165b4c1be8f..0f52b2882f33 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -16,6 +16,10 @@ permalink: /changelog/ * **all components** * All new usages of the `concept-fetch` component to make fetch requests now have conservative-mode off by default. Current features will continue to use conservative mode until individually updated. + +* **browser-toolbar** + * Add `showMenuButton` and `hideMenuButton` API to `BrowserToolbar` and `DisplayToolbar` to allow hiding and showing of the menu button in + the `BrowserToolbar` [Bug 1864760](https://bugzilla.mozilla.org/show_bug.cgi?id=1864760) # 123.0 * [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v122..releases_v123)