From 56e77609ba1634bd8bf9ff41316fc176d90d911a Mon Sep 17 00:00:00 2001 From: Harrison Oglesby Date: Mon, 29 Jan 2024 16:19:37 -0800 Subject: [PATCH] Bug 1864760 - Hide Menu, Home, and Tab counter button from BrowserFragment Toolbar. --- .../mozilla/fenix/browser/BrowserFragment.kt | 47 +++++++------- .../org/mozilla/fenix/browser/TabPreview.kt | 6 ++ .../components/toolbar/BrowserToolbarView.kt | 4 ++ .../components/toolbar/ToolbarIntegration.kt | 65 ++++++++++--------- .../toolbar/DefaultToolbarIntegrationTest.kt | 1 + 5 files changed, 71 insertions(+), 52 deletions(-) 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 98ec14668..e799cfcc3 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -113,29 +113,32 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { } val isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate - val leadingAction = if (isPrivate && context.settings().feltPrivateBrowsingEnabled) { - BrowserToolbar.Button( - imageDrawable = AppCompatResources.getDrawable( - context, - R.drawable.mozac_ic_data_clearance_24, - )!!, - contentDescription = context.getString(R.string.browser_toolbar_erase), - iconTintColorResource = ThemeManager.resolveAttribute(R.attr.textPrimary, context), - listener = browserToolbarInteractor::onEraseButtonClicked, - ) - } else { - BrowserToolbar.Button( - imageDrawable = AppCompatResources.getDrawable( - context, - R.drawable.mozac_ic_home_24, - )!!, - contentDescription = context.getString(R.string.browser_toolbar_home), - iconTintColorResource = ThemeManager.resolveAttribute(R.attr.textPrimary, context), - listener = browserToolbarInteractor::onHomeButtonClicked, - ) - } - browserToolbarView.view.addNavigationAction(leadingAction) + if (!IncompleteRedesignToolbarFeature(context.settings()).isEnabled) { + val leadingAction = if (isPrivate && context.settings().feltPrivateBrowsingEnabled) { + BrowserToolbar.Button( + imageDrawable = AppCompatResources.getDrawable( + context, + R.drawable.mozac_ic_data_clearance_24, + )!!, + contentDescription = context.getString(R.string.browser_toolbar_erase), + iconTintColorResource = ThemeManager.resolveAttribute(R.attr.textPrimary, context), + listener = browserToolbarInteractor::onEraseButtonClicked, + ) + } else { + BrowserToolbar.Button( + imageDrawable = AppCompatResources.getDrawable( + context, + R.drawable.mozac_ic_home_24, + )!!, + contentDescription = context.getString(R.string.browser_toolbar_home), + iconTintColorResource = ThemeManager.resolveAttribute(R.attr.textPrimary, context), + listener = browserToolbarInteractor::onHomeButtonClicked, + ) + } + + browserToolbarView.view.addNavigationAction(leadingAction) + } updateToolbarActions(isTablet = resources.getBoolean(R.bool.tablet)) diff --git a/app/src/main/java/org/mozilla/fenix/browser/TabPreview.kt b/app/src/main/java/org/mozilla/fenix/browser/TabPreview.kt index d04089dd6..43145c296 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/TabPreview.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/TabPreview.kt @@ -12,12 +12,14 @@ import android.view.View import android.widget.FrameLayout import androidx.appcompat.content.res.AppCompatResources import androidx.core.view.doOnNextLayout +import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import mozilla.components.browser.state.selector.getNormalOrPrivateTabs import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.thumbnails.loader.ThumbnailLoader import mozilla.components.concept.base.images.ImageLoadRequest import org.mozilla.fenix.R +import org.mozilla.fenix.components.toolbar.IncompleteRedesignToolbarFeature import org.mozilla.fenix.components.toolbar.ToolbarPosition import org.mozilla.fenix.databinding.TabPreviewBinding import org.mozilla.fenix.ext.components @@ -46,6 +48,10 @@ class TabPreview @JvmOverloads constructor( ) } + val isNavBarEnabled = IncompleteRedesignToolbarFeature(context.settings()).isEnabled + binding.tabButton.isVisible = !isNavBarEnabled + binding.menuButton.isVisible = !isNavBarEnabled + // Change view properties to avoid confusing the UI tests binding.tabButton.findViewById(R.id.counter_box).id = View.NO_ID binding.tabButton.findViewById(R.id.counter_text).id = View.NO_ID diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt index 3052c18dd..12f5dde98 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt @@ -28,6 +28,7 @@ import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration import org.mozilla.fenix.customtabs.CustomTabToolbarMenu import org.mozilla.fenix.ext.bookmarkStorage import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.ToolbarPopupWindow @@ -170,6 +171,8 @@ class BrowserToolbarView( isPrivate = customTabSession.content.private, ) } else { + val isNavBarEnabled = IncompleteRedesignToolbarFeature(context.settings()).isEnabled + DefaultToolbarIntegration( this, view, @@ -177,6 +180,7 @@ class BrowserToolbarView( lifecycleOwner, sessionId = null, isPrivate = components.core.store.state.selectedTab?.content?.private ?: false, + isNavBarEnabled = isNavBarEnabled, interactor = interactor, ) } 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 94a927d2a..0757a1474 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 @@ -83,6 +83,7 @@ class DefaultToolbarIntegration( lifecycleOwner: LifecycleOwner, sessionId: String? = null, isPrivate: Boolean, + isNavBarEnabled: Boolean = false, interactor: BrowserToolbarInteractor, ) : ToolbarIntegration( context = context, @@ -115,40 +116,44 @@ class DefaultToolbarIntegration( DisplayToolbar.Indicators.HIGHLIGHT, ) - val tabCounterMenu = FenixTabCounterMenu( - context = context, - onItemTapped = { - interactor.onTabCounterMenuItemTapped(it) - }, - iconColor = if (isPrivate) { - ContextCompat.getColor(context, R.color.fx_mobile_private_text_color_primary) + if (isNavBarEnabled) { + toolbar.hideMenuButton() + } else { + val tabCounterMenu = FenixTabCounterMenu( + context = context, + onItemTapped = { + interactor.onTabCounterMenuItemTapped(it) + }, + iconColor = if (isPrivate) { + ContextCompat.getColor(context, R.color.fx_mobile_private_text_color_primary) + } else { + null + }, + ).also { + it.updateMenu(context.settings().toolbarPosition) + } + + val tabsAction = TabCounterToolbarButton( + lifecycleOwner = lifecycleOwner, + showTabs = { + toolbar.hideKeyboard() + interactor.onTabCounterClicked() + }, + store = store, + menu = tabCounterMenu, + showMaskInPrivateMode = context.settings().feltPrivateBrowsingEnabled, + ) + + val tabCount = if (isPrivate) { + store.state.privateTabs.size } else { - null - }, - ).also { - it.updateMenu(context.settings().toolbarPosition) - } + store.state.normalTabs.size + } - val tabsAction = TabCounterToolbarButton( - lifecycleOwner = lifecycleOwner, - showTabs = { - toolbar.hideKeyboard() - interactor.onTabCounterClicked() - }, - store = store, - menu = tabCounterMenu, - showMaskInPrivateMode = context.settings().feltPrivateBrowsingEnabled, - ) + tabsAction.updateCount(tabCount) - val tabCount = if (isPrivate) { - store.state.privateTabs.size - } else { - store.state.normalTabs.size + toolbar.addBrowserAction(tabsAction) } - - tabsAction.updateCount(tabCount) - - toolbar.addBrowserAction(tabsAction) } override fun start() { diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt index 298cf64ae..9d03850d7 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt @@ -42,6 +42,7 @@ class DefaultToolbarIntegrationTest { sessionId = null, isPrivate = false, interactor = mockk(), + isNavBarEnabled = false, ) }