From 13c9c39658e9f3b8ac29838e6153e394afb8919d Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Tue, 25 Feb 2020 16:20:58 -0800 Subject: [PATCH] For #4383: Add feature flag --- .../java/org/mozilla/fenix/FeatureFlags.kt | 5 ++ .../fenix/browser/BaseBrowserFragment.kt | 57 +++++++++++++++---- .../mozilla/fenix/browser/BrowserFragment.kt | 13 +++++ .../fenix/customtabs/CustomTabsIntegration.kt | 14 +++++ .../customtabs/ExternalAppBrowserFragment.kt | 6 +- .../fenix/search/toolbar/ToolbarView.kt | 4 +- .../java/org/mozilla/fenix/utils/Settings.kt | 1 - app/src/main/res/layout/fragment_browser.xml | 2 +- 8 files changed, 87 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 6ece8b47d..71fa82582 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -44,6 +44,11 @@ object FeatureFlags { */ const val asFeatureFxAPairingDisabled = false + /** + * Enables dynamic bottom toolbar + */ + val dynamicBottomToolbar = Config.channel.isNightlyOrDebug + /** * Enables the new language picker */ diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 1fd018008..7770212b7 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -389,17 +389,23 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session activity?.enterToImmersiveMode() browserToolbarView.view.visibility = View.GONE - // TODO We need to call force expand here to update verticalClipping #8697 - // Without this, fullscreen has a margin at the top. - engineView.setVerticalClipping(0) + if (FeatureFlags.dynamicBottomToolbar) { + engineView.setDynamicToolbarMaxHeight(0) + // TODO We need to call force expand here to update verticalClipping #8697 + // Without this, fullscreen has a margin at the top. + engineView.setVerticalClipping(0) + } } else { activity?.exitImmersiveModeIfNeeded() (activity as? HomeActivity)?.let { activity -> activity.themeManager.applyStatusBarTheme(activity) } browserToolbarView.view.visibility = View.VISIBLE - engineView.setDynamicToolbarMaxHeight(toolbarHeight) + if (FeatureFlags.dynamicBottomToolbar) { + engineView.setDynamicToolbarMaxHeight(toolbarHeight) + } } + if (!FeatureFlags.dynamicBottomToolbar) { updateLayoutMargins(inFullScreen) } }, owner = this, view = view @@ -461,15 +467,21 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session } private fun initializeEngineView(toolbarHeight: Int) { - engineView.setDynamicToolbarMaxHeight(toolbarHeight) + if (FeatureFlags.dynamicBottomToolbar) { + engineView.setDynamicToolbarMaxHeight(toolbarHeight) - val behavior = if (requireContext().settings().shouldUseBottomToolbar) { - EngineViewBottomBehavior(context, null) + val behavior = if (requireContext().settings().shouldUseBottomToolbar) { + EngineViewBottomBehavior(context, null) + } else { + AppBarLayout.ScrollingViewBehavior(context, null) + } + + (swipeRefresh.layoutParams as CoordinatorLayout.LayoutParams).behavior = behavior } else { - AppBarLayout.ScrollingViewBehavior(context, null) + if (!requireContext().settings().shouldUseBottomToolbar) { + engineView.setDynamicToolbarMaxHeight(toolbarHeight) + } } - - (swipeRefresh.layoutParams as CoordinatorLayout.LayoutParams).behavior = behavior } /** @@ -492,7 +504,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session // If the bitmap is null, the best we can do to reduce the flash is set transparent swipeRefresh.background = bitmap?.toDrawable(it.resources) ?: ColorDrawable(Color.TRANSPARENT) - + engineView.asView().visibility = View.GONE findNavController().nav(R.id.browserFragment, directions) } @@ -629,12 +641,35 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session protected abstract fun navToTrackingProtectionPanel(session: Session) + /** + * Returns the top and bottom margins. + */ + private fun getEngineMargins(): Pair = + if (context?.settings()?.shouldUseBottomToolbar == true) { + val toolbarSize = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height) + 0 to toolbarSize + } else { + 0 to 0 + } + /** * Returns the layout [android.view.Gravity] for the quick settings and ETP dialog. */ protected fun getAppropriateLayoutGravity(): Int = if (context?.settings()?.shouldUseBottomToolbar == true) Gravity.BOTTOM else Gravity.TOP + protected fun updateLayoutMargins(inFullScreen: Boolean) { + view?.swipeRefresh?.apply { + val (topMargin, bottomMargin) = if (inFullScreen) 0 to 0 else getEngineMargins() + (layoutParams as CoordinatorLayout.LayoutParams).setMargins( + 0, + topMargin, + 0, + bottomMargin + ) + } + } + /** * Updates the site permissions rules based on user settings. */ 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 782719c3a..6d49cf4ac 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -9,8 +9,10 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.transition.TransitionInflater import com.google.android.material.snackbar.Snackbar +import kotlinx.android.synthetic.main.fragment_browser.* import kotlinx.android.synthetic.main.fragment_browser.view.* import kotlinx.coroutines.ExperimentalCoroutinesApi import mozilla.components.browser.session.Session @@ -24,6 +26,7 @@ import mozilla.components.feature.tabs.WindowFeature import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.base.feature.ViewBoundFeatureWrapper +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar @@ -126,6 +129,16 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { } private fun updateEngineBottomMargin() { + if (!FeatureFlags.dynamicBottomToolbar) { + val browserEngine = swipeRefresh.layoutParams as CoordinatorLayout.LayoutParams + + browserEngine.bottomMargin = if (requireContext().settings().shouldUseBottomToolbar) { + requireContext().resources.getDimensionPixelSize(R.dimen.browser_toolbar_height) + } else { + 0 + } + } + val toolbarSessionObserver = TrackingProtectionOverlay( context = requireContext(), settings = requireContext().settings() diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt index c561cbba2..dcd346f04 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt @@ -5,6 +5,8 @@ package org.mozilla.fenix.customtabs import android.app.Activity +import android.view.View +import android.view.ViewGroup import androidx.appcompat.content.res.AppCompatResources import mozilla.components.browser.session.SessionManager import mozilla.components.browser.toolbar.BrowserToolbar @@ -12,6 +14,7 @@ import mozilla.components.browser.toolbar.display.DisplayToolbar import mozilla.components.feature.customtabs.CustomTabsToolbarFeature import mozilla.components.support.base.feature.LifecycleAwareFeature import mozilla.components.support.base.feature.UserInteractionHandler +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.components.toolbar.ToolbarMenu import org.mozilla.fenix.ext.settings @@ -21,6 +24,7 @@ class CustomTabsIntegration( toolbar: BrowserToolbar, sessionId: String, activity: Activity, + engineLayout: View, onItemTapped: (ToolbarMenu.Item) -> Unit = {}, shouldReverseItems: Boolean, isPrivate: Boolean @@ -30,6 +34,16 @@ class CustomTabsIntegration( // Remove toolbar shadow toolbar.elevation = 0f + if (!FeatureFlags.dynamicBottomToolbar) { + // Reduce margin height of EngineView from the top for the toolbar + engineLayout.run { + (layoutParams as ViewGroup.MarginLayoutParams).apply { + val toolbarHeight = resources.getDimension(R.dimen.browser_toolbar_height).toInt() + setMargins(0, toolbarHeight, 0, 0) + } + } + } + val uncoloredEtpShield = AppCompatResources.getDrawable( activity, R.drawable.ic_tracking_protection_enabled diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt index 33d05b322..331c912e4 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt @@ -8,6 +8,7 @@ import android.content.Context import android.view.View import androidx.navigation.fragment.navArgs import kotlinx.android.synthetic.main.component_browser_top_toolbar.* +import kotlinx.android.synthetic.main.fragment_browser.view.* import kotlinx.coroutines.ExperimentalCoroutinesApi import mozilla.components.browser.session.Session import mozilla.components.concept.engine.manifest.WebAppManifestParser @@ -26,6 +27,7 @@ import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.ktx.android.arch.lifecycle.addObservers +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.browser.BaseBrowserFragment @@ -66,6 +68,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler toolbar = toolbar, sessionId = customTabSessionId, activity = activity, + engineLayout = view.swipeRefresh, onItemTapped = { browserInteractor.onBrowserToolbarMenuItemTapped(it) }, isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate, shouldReverseItems = !activity.settings().shouldUseBottomToolbar @@ -90,7 +93,8 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler toolbar, customTabSessionId, trustedScopes - ) { + ) { toolbarVisible -> + if (!FeatureFlags.dynamicBottomToolbar) { updateLayoutMargins(inFullScreen = !toolbarVisible) } }, owner = this, view = toolbar diff --git a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt index 8b9de9046..683fa4a81 100644 --- a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt @@ -25,6 +25,7 @@ import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior import mozilla.components.concept.storage.HistoryStorage import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature import mozilla.components.support.ktx.android.util.dpToPx +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.ext.getColorFromAttr import org.mozilla.fenix.ext.settings @@ -181,11 +182,12 @@ class ToolbarView( fun BrowserToolbar.setScrollFlagsForTopToolbar() { // Don't set scroll flags for bottom toolbar if (context.settings().shouldUseBottomToolbar) { - if (layoutParams is CoordinatorLayout.LayoutParams) { + if (FeatureFlags.dynamicBottomToolbar && layoutParams is CoordinatorLayout.LayoutParams) { (layoutParams as CoordinatorLayout.LayoutParams).apply { behavior = BrowserToolbarBottomBehavior(context, null) } } + return } diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index c86cac55f..f39995e30 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -42,7 +42,6 @@ class Settings private constructor( companion object { const val showLoginsSecureWarningSyncMaxCount = 1 const val showLoginsSecureWarningMaxCount = 1 - const val autoBounceMaximumCount = 2 const val trackingProtectionOnboardingMaximumCount = 2 const val FENIX_PREFERENCES = "fenix_preferences" diff --git a/app/src/main/res/layout/fragment_browser.xml b/app/src/main/res/layout/fragment_browser.xml index 81238b6b8..0f6f70d49 100644 --- a/app/src/main/res/layout/fragment_browser.xml +++ b/app/src/main/res/layout/fragment_browser.xml @@ -14,7 +14,7 @@ android:id="@+id/swipeRefresh" android:layout_width="match_parent" android:layout_height="match_parent" - app:layout_behavior="mozilla.components.feature.session.behavior.EngineViewBottomBehavior"> + app:layout_behavior="@string/appbar_scrolling_view_behavior">