Skip to content

Commit

Permalink
For mozilla-mobile#6054: Adds toolbar position to core ping
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed Nov 25, 2019
1 parent 768791c commit 5b24b8f
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDirections
import androidx.navigation.fragment.findNavController
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.component_search.*
import kotlinx.android.synthetic.main.fragment_browser.*
import kotlinx.android.synthetic.main.fragment_browser.view.*
import kotlinx.coroutines.Dispatchers.IO
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.RadioButton
import androidx.appcompat.widget.AppCompatImageView
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
Expand All @@ -30,6 +29,7 @@ import mozilla.components.feature.tabs.WindowFeature
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.jetbrains.anko.dimen
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
Expand All @@ -48,7 +48,7 @@ import org.mozilla.fenix.trackingprotection.TrackingProtectionOverlay
* Fragment used for browsing the web within the main app.
*/
@ExperimentalCoroutinesApi
@Suppress("TooManyFunctions")
@Suppress("TooManyFunctions", "LargeClass")
class BrowserFragment : BaseBrowserFragment(), BackHandler {

private val windowFeature = ViewBoundFeatureWrapper<WindowFeature>()
Expand Down Expand Up @@ -120,20 +120,24 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
override fun onStart() {
super.onStart()
subscribeToTabCollections()
val toolbarSessionObserver = TrackingProtectionOverlay(
context = requireContext(),
settings = requireContext().settings()
) {
browserToolbarView.view
}
getSessionById()?.register(toolbarSessionObserver, this, autoPause = true)

updateToolbar()
updateEngineBottomMargin()
}

private fun updateToolbar() {
private fun updateEngineBottomMargin() {
val browserEngine = swipeRefresh.layoutParams as CoordinatorLayout.LayoutParams

browserEngine.bottomMargin = if (requireContext().settings().shouldUseBottomToolbar) {
requireContext().dimen(R.dimen.browser_toolbar_height)
} else {
0
}
}

val toolbarSessionObserver = TrackingProtectionOverlay(
context = requireContext(),
Expand Down Expand Up @@ -273,8 +277,6 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
)

companion object {
private const val THREE = 3
private const val BUTTON_INCREASE_DPS = 12
private const val SHARED_TRANSITION_MS = 200L
private const val TAB_ITEM_TRANSITION_NAME = "tab_item"
const val REPORT_SITE_ISSUE_URL =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package org.mozilla.fenix.browser
import android.animation.ValueAnimator
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.View.SCROLL_AXIS_VERTICAL
Expand Down Expand Up @@ -97,8 +96,6 @@ class BrowserToolbarTopBehavior(
override fun layoutDependsOn(parent: CoordinatorLayout, child: BrowserToolbar, dependency: View): Boolean {
if (dependency is Snackbar.SnackbarLayout) {
positionSnackbar(dependency)
} else {
Log.d("Sawyer", "depenedency: $dependency")
}

return super.layoutDependsOn(parent, child, dependency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package org.mozilla.fenix.components.metrics

import android.content.Context
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import mozilla.components.service.glean.BuildConfig
import mozilla.components.service.glean.Glean
import mozilla.components.service.glean.config.Configuration
Expand Down Expand Up @@ -507,6 +507,7 @@ class GleanMetricsService(private val context: Context) : MetricsService {
mozillaProducts.set(MozillaProductDetector.getInstalledMozillaProducts(context))
adjustCampaign.set(context.settings().adjustCampaignId)
totalUriCount.set(context.settings().totalUriCount.toString())
toolbarPosition.set(context.settings().toolbarSettingString)
}

SearchDefaultEngine.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.PopupWindow
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
Expand All @@ -28,6 +29,7 @@ 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.search.toolbar.setScrollFlagsForTopToolbar
import org.mozilla.fenix.theme.ThemeManager

interface BrowserToolbarViewInteractor {
Expand All @@ -48,22 +50,18 @@ class BrowserToolbarView(
override val containerView: View?
get() = container

val view: BrowserToolbar = if (container.context.settings().shouldUseBottomToolbar) {
LayoutInflater.from(container.context)
.inflate(R.layout.component_bottom_browser_toolbar, container, true)
.findViewById(R.id.toolbar_bottom)
} else {
if (container.context.settings().shouldUseFixedToolbar) {
LayoutInflater.from(container.context)
.inflate(R.layout.component_browser_top_toolbar_fixed, container, true)
.findViewById(R.id.toolbar_top_fixed)
} else {
LayoutInflater.from(container.context)
.inflate(R.layout.component_browser_bottom_toolbar, container, true)
.findViewById(R.id.toolbar_top)
}
private val settings = container.context.settings()

@LayoutRes
private val toolbarLayout = when {
settings.shouldUseBottomToolbar -> R.layout.component_bottom_browser_toolbar
else -> R.layout.component_browser_top_toolbar
}

val view: BrowserToolbar = LayoutInflater.from(container.context)
.inflate(toolbarLayout, container, true)
.findViewById(R.id.toolbar)

val toolbarIntegration: ToolbarIntegration

init {
Expand Down Expand Up @@ -127,6 +125,8 @@ class BrowserToolbarView(
val sessionManager = components.core.sessionManager

view.apply {
setScrollFlagsForTopToolbar()

elevation = TOOLBAR_ELEVATION.dpToFloat(resources.displayMetrics)

if (!isCustomTabSession) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.view.Gravity
import android.view.View
import androidx.core.view.isGone
import androidx.navigation.fragment.navArgs
import kotlinx.android.synthetic.main.component_browser_bottom_toolbar.*
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
Expand Down Expand Up @@ -64,7 +64,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
customTabsIntegration.set(
feature = CustomTabsIntegration(
sessionManager = requireComponents.core.sessionManager,
toolbar = toolbar_top,
toolbar = toolbar,
sessionId = customTabSessionId,
activity = activity,
engineLayout = view.swipeRefresh,
Expand All @@ -86,14 +86,14 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
hideToolbarFeature.set(
feature = WebAppHideToolbarFeature(
requireComponents.core.sessionManager,
toolbar_top,
toolbar,
customTabSessionId,
trustedScopes
) { toolbarVisible ->
updateLayoutMargins(inFullScreen = !toolbarVisible)
},
owner = this,
view = toolbar_top
view = toolbar
)

if (manifest != null) {
Expand Down Expand Up @@ -187,7 +187,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
}

override fun getEngineMargins(): Pair<Int, Int> {
val toolbarHidden = toolbar_top.isGone
val toolbarHidden = toolbar.isGone
return if (toolbarHidden) {
0 to 0
} else {
Expand Down
52 changes: 38 additions & 14 deletions app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP
import kotlinx.android.extensions.LayoutContainer
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
import mozilla.components.browser.toolbar.BrowserToolbar
Expand Down Expand Up @@ -59,28 +65,26 @@ class ToolbarView(
override val containerView: View?
get() = container

val view: BrowserToolbar = if (container.context.settings().shouldUseBottomToolbar) {
LayoutInflater.from(container.context)
.inflate(R.layout.component_bottom_browser_toolbar, container, true)
.findViewById(R.id.toolbar_bottom)
} else {
if (container.context.settings().shouldUseFixedToolbar) {
LayoutInflater.from(container.context)
.inflate(R.layout.component_browser_bottom_toolbar, container, true)
.findViewById(R.id.toolbar_top_fixed)
} else {
LayoutInflater.from(container.context)
.inflate(R.layout.component_browser_bottom_toolbar, container, true)
.findViewById(R.id.toolbar_top)
}
private val settings = container.context.settings()

@LayoutRes
private val toolbarLayout = when {
settings.shouldUseBottomToolbar -> R.layout.component_bottom_browser_toolbar
else -> R.layout.component_browser_top_toolbar
}

val view: BrowserToolbar = LayoutInflater.from(container.context)
.inflate(toolbarLayout, container, true)
.findViewById(R.id.toolbar)

private var isInitialized = false

init {
view.apply {
editMode()

setScrollFlagsForTopToolbar()

elevation = TOOLBAR_ELEVATION_IN_DP.dpToPx(resources.displayMetrics).toFloat()

setOnUrlCommitListener {
Expand Down Expand Up @@ -159,3 +163,23 @@ class ToolbarView(
private const val TOOLBAR_ELEVATION_IN_DP = 16
}
}

/**
* Dynamically sets scroll flags for the top toolbar when the user does not have a screen reader enabled
* Note that the bottom toolbar is currently fixed and will never have scroll flags set
*/
fun BrowserToolbar.setScrollFlagsForTopToolbar() {
// Don't set scroll flags for bottom toolbar
if (context.settings().shouldUseBottomToolbar) {
return
}

val params = layoutParams as AppBarLayout.LayoutParams
params.scrollFlags = when (context.settings().shouldUseFixedTopToolbar) {
true -> 0
false -> {
SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS or SCROLL_FLAG_SNAP or
SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
(activity as AppCompatActivity).title = getString(R.string.settings_title)
(activity as AppCompatActivity).supportActionBar?.show()

setSummaryAndTitleStrings()
update()
}

private fun setSummaryAndTitleStrings() {
private fun update() {
val trackingProtectionPreference =
findPreference<Preference>(getPreferenceKey(pref_key_tracking_protection_settings))
trackingProtectionPreference?.summary = context?.let {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ class Settings private constructor(
true
)

val shouldUseFixedToolbar: Boolean
val shouldUseFixedTopToolbar: Boolean
get() {
val accessibilityManager = appContext.getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager
val accessibilityManager =
appContext.getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager
return accessibilityManager?.isTouchExplorationEnabled ?: false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<mozilla.components.browser.toolbar.BrowserToolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_bottom"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/browser_toolbar_height"
android:layout_gravity="bottom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:layout_height="wrap_content">
<mozilla.components.browser.toolbar.BrowserToolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_top"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/browser_toolbar_height"
android:layout_gravity="top"
Expand All @@ -23,3 +23,5 @@
app:browserToolbarSecureColor="?primaryText"
app:browserToolbarTrackingProtectionAndSecurityIndicatorSeparatorColor="?toolbarDivider" />
</com.google.android.material.appbar.AppBarLayout>

<!-- NOTE: Scroll flags set dynamically with `setScrollFlagsForTopToolbar` -->
Loading

0 comments on commit 5b24b8f

Please sign in to comment.