From 155c1195131804a3f567b4f638111c6bf3e6b1b1 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Mon, 7 Jun 2021 11:52:19 -0400 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/19876 - Part 2: Add a Home screen button to the browser toolbar --- .../org/mozilla/fenix/browser/BrowserFragment.kt | 8 ++++++++ .../components/toolbar/BrowserToolbarController.kt | 12 ++++++++++++ .../toolbar/interactor/BrowserToolbarInteractor.kt | 9 +++++++++ app/src/main/res/values/strings.xml | 4 ++++ .../toolbar/DefaultBrowserToolbarControllerTest.kt | 8 ++++++++ .../toolbar/DefaultBrowserToolbarInteractorTest.kt | 7 +++++++ 6 files changed, 48 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 8e4d6c8a89..493d0cf15c 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -76,6 +76,14 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { ) } + val homeAction = BrowserToolbar.Button( + imageDrawable = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_home)!!, + contentDescription = requireContext().getString(R.string.browser_toolbar_home), + listener = browserToolbarInteractor::onHomeButtonClicked + ) + + browserToolbarView.view.addNavigationAction(homeAction) + val readerModeAction = BrowserToolbar.ToggleButton( image = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_readermode)!!, diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt index fa303fc23e..fe9bb631dc 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt @@ -23,6 +23,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.browser.readermode.ReaderModeController import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.MetricController +import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph import org.mozilla.fenix.ext.nav @@ -40,6 +41,11 @@ interface BrowserToolbarController { fun handleTabCounterClick() fun handleTabCounterItemInteraction(item: TabCounterMenu.Item) fun handleReaderModePressed(enabled: Boolean) + + /** + * @see [BrowserToolbarInteractor.onHomeButtonClicked] + */ + fun handleHomeButtonClick() } class DefaultBrowserToolbarController( @@ -157,6 +163,12 @@ class DefaultBrowserToolbarController( } } + override fun handleHomeButtonClick() { + navController.navigateBlockingForAsyncNavGraph( + BrowserFragmentDirections.actionGlobalHome() + ) + } + companion object { internal const val TELEMETRY_BROWSER_IDENTIFIER = "browserMenu" } diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/interactor/BrowserToolbarInteractor.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/interactor/BrowserToolbarInteractor.kt index 20881e20fe..0b636726e9 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/interactor/BrowserToolbarInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/interactor/BrowserToolbarInteractor.kt @@ -22,6 +22,11 @@ interface BrowserToolbarInteractor { fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item) fun onScrolled(offset: Int) fun onReaderModePressed(enabled: Boolean) + + /** + * Navigates to the Home screen. Called when a user taps on the Home button. + */ + fun onHomeButtonClicked() } /** @@ -68,4 +73,8 @@ class DefaultBrowserToolbarInteractor( override fun onReaderModePressed(enabled: Boolean) { browserToolbarController.handleReaderModePressed(enabled) } + + override fun onHomeButtonClicked() { + browserToolbarController.handleHomeButtonClick() + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d1c37ce6a3..c29f65614c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -173,6 +173,10 @@ Edit + + + Home screen + Unable to connect. Unrecognizable URL scheme. diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt index 546ae4fea6..9781006f83 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt @@ -312,6 +312,14 @@ class DefaultBrowserToolbarControllerTest { verify(exactly = 0) { engineView.setVerticalClipping(10) } } + @Test + fun handleHomeButtonClick() { + val controller = createController() + controller.handleHomeButtonClick() + + verify { navController.navigate(BrowserFragmentDirections.actionGlobalHome()) } + } + private fun createController( activity: HomeActivity = this.activity, customTabSessionId: String? = null diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarInteractorTest.kt index 7d87bf5929..0106088f37 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarInteractorTest.kt @@ -68,4 +68,11 @@ class DefaultBrowserToolbarInteractorTest { verify { browserToolbarMenuController.handleToolbarItemInteraction(item) } } + + @Test + fun onHomeButtonClicked() { + interactor.onHomeButtonClicked() + + verify { browserToolbarController.handleHomeButtonClick() } + } }