From 982dc4410f1b46401569b2377eed09374322607a Mon Sep 17 00:00:00 2001 From: Steven Knipe Date: Thu, 12 Aug 2021 09:24:07 -0400 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/4134 Add Forward Back Reload to Toolbar on Tablets --- .../mozilla/fenix/browser/BrowserFragment.kt | 94 +++++++++++++++++-- app/src/main/res/values-sw600dp/bools.xml | 7 ++ app/src/main/res/values/bools.xml | 1 + 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/values-sw600dp/bools.xml 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 d0e985cfc4..12dc527f1f 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -33,6 +33,7 @@ import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.TabCollectionStorage +import org.mozilla.fenix.components.toolbar.ToolbarMenu import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.nav @@ -82,10 +83,10 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { if (FeatureFlags.showHomeButtonFeature) { val homeAction = BrowserToolbar.Button( imageDrawable = AppCompatResources.getDrawable( - requireContext(), + context, R.drawable.mozac_ic_home )!!, - contentDescription = requireContext().getString(R.string.browser_toolbar_home), + contentDescription = context.getString(R.string.browser_toolbar_home), iconTintColorResource = ThemeManager.resolveAttribute(R.attr.primaryText, context), listener = browserToolbarInteractor::onHomeButtonClicked ) @@ -93,19 +94,100 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { browserToolbarView.view.addNavigationAction(homeAction) } + if (resources.getBoolean(R.bool.tablet)) { + val enableTint = ThemeManager.resolveAttribute(R.attr.primaryText, context) + val disableTint = ThemeManager.resolveAttribute(R.attr.disabled, context) + val backAction = BrowserToolbar.TwoStateButton( + primaryImage = AppCompatResources.getDrawable( + context, + R.drawable.mozac_ic_back + )!!, + primaryContentDescription = context.getString(R.string.browser_menu_back), + primaryImageTintResource = enableTint, + isInPrimaryState = { getCurrentTab()?.content?.canGoBack ?: false }, + secondaryImageTintResource = disableTint, + disableInSecondaryState = true, + longClickListener = { + browserToolbarInteractor.onBrowserToolbarMenuItemTapped( + ToolbarMenu.Item.Back(viewHistory = true) + ) + }, + listener = { + browserToolbarInteractor.onBrowserToolbarMenuItemTapped( + ToolbarMenu.Item.Back(viewHistory = false) + ) + } + ) + browserToolbarView.view.addNavigationAction(backAction) + val forwardAction = BrowserToolbar.TwoStateButton( + primaryImage = AppCompatResources.getDrawable( + context, + R.drawable.mozac_ic_forward + )!!, + primaryContentDescription = context.getString(R.string.browser_menu_forward), + primaryImageTintResource = enableTint, + isInPrimaryState = { getCurrentTab()?.content?.canGoForward ?: false }, + secondaryImageTintResource = disableTint, + disableInSecondaryState = true, + longClickListener = { + browserToolbarInteractor.onBrowserToolbarMenuItemTapped( + ToolbarMenu.Item.Forward(viewHistory = true) + ) + }, + listener = { + browserToolbarInteractor.onBrowserToolbarMenuItemTapped( + ToolbarMenu.Item.Forward(viewHistory = false) + ) + } + ) + browserToolbarView.view.addNavigationAction(forwardAction) + val refreshAction = BrowserToolbar.TwoStateButton( + primaryImage = AppCompatResources.getDrawable( + context, + R.drawable.mozac_ic_refresh + )!!, + primaryContentDescription = context.getString(R.string.browser_menu_refresh), + primaryImageTintResource = enableTint, + isInPrimaryState = { + getCurrentTab()?.content?.loading == false + }, + secondaryImage = AppCompatResources.getDrawable( + context, + R.drawable.mozac_ic_stop + )!!, + secondaryContentDescription = context.getString(R.string.browser_menu_stop), + disableInSecondaryState = false, + longClickListener = { + browserToolbarInteractor.onBrowserToolbarMenuItemTapped( + ToolbarMenu.Item.Reload(bypassCache = true) + ) + }, + listener = { + if (getCurrentTab()?.content?.loading == true) { + browserToolbarInteractor.onBrowserToolbarMenuItemTapped(ToolbarMenu.Item.Stop) + } else { + browserToolbarInteractor.onBrowserToolbarMenuItemTapped( + ToolbarMenu.Item.Reload(bypassCache = false) + ) + } + } + ) + browserToolbarView.view.addNavigationAction(refreshAction) + } + val readerModeAction = BrowserToolbar.ToggleButton( image = AppCompatResources.getDrawable( - requireContext(), + context, R.drawable.ic_readermode )!!, imageSelected = AppCompatResources.getDrawable( - requireContext(), + context, R.drawable.ic_readermode_selected )!!, - contentDescription = requireContext().getString(R.string.browser_menu_read), - contentDescriptionSelected = requireContext().getString(R.string.browser_menu_read_close), + contentDescription = context.getString(R.string.browser_menu_read), + contentDescriptionSelected = context.getString(R.string.browser_menu_read_close), visible = { readerModeAvailable }, diff --git a/app/src/main/res/values-sw600dp/bools.xml b/app/src/main/res/values-sw600dp/bools.xml new file mode 100644 index 0000000000..6d2bf3e16d --- /dev/null +++ b/app/src/main/res/values-sw600dp/bools.xml @@ -0,0 +1,7 @@ + + + + true + \ No newline at end of file diff --git a/app/src/main/res/values/bools.xml b/app/src/main/res/values/bools.xml index 91d4bf5728..aae7a9c9b2 100644 --- a/app/src/main/res/values/bools.xml +++ b/app/src/main/res/values/bools.xml @@ -6,4 +6,5 @@ true false true + false