1
0
Fork 0

For #4383: Add feature flag

master
Sawyer Blatz 2020-02-25 16:20:58 -08:00
parent 009a7f3020
commit 13c9c39658
8 changed files with 87 additions and 15 deletions

View File

@ -44,6 +44,11 @@ object FeatureFlags {
*/
const val asFeatureFxAPairingDisabled = false
/**
* Enables dynamic bottom toolbar
*/
val dynamicBottomToolbar = Config.channel.isNightlyOrDebug
/**
* Enables the new language picker
*/

View File

@ -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<Int, Int> =
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.
*/

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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"

View File

@ -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">
<mozilla.components.concept.engine.EngineView
android:id="@+id/engineView"
android:layout_width="match_parent"