From 82d19c5d920983f9a466e8016d0869b05303f479 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Fri, 15 Nov 2019 11:41:12 -0800 Subject: [PATCH] Adds toolbar position to core ping --- .../mozilla/fenix/browser/BrowserFragment.kt | 9 ++-- .../browser/BrowserToolbarTopBehavior.kt | 3 -- .../components/metrics/GleanMetricsService.kt | 3 +- .../toolbar/EngineViewTopBehavior.kt | 46 ------------------- .../java/org/mozilla/fenix/utils/Settings.kt | 3 +- docs/metrics.md | 3 +- 6 files changed, 10 insertions(+), 57 deletions(-) delete mode 100644 app/src/main/java/org/mozilla/fenix/components/toolbar/EngineViewTopBehavior.kt 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 f3a890333d2d..e123f9d084e6 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -57,7 +57,7 @@ import org.mozilla.fenix.mvi.getManagedEmitter * Fragment used for browsing the web within the main app. */ @ExperimentalCoroutinesApi -@Suppress("TooManyFunctions") +@Suppress("TooManyFunctions", "LargeClass") class BrowserFragment : BaseBrowserFragment(), BackHandler { private val windowFeature = ViewBoundFeatureWrapper() @@ -130,11 +130,10 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler { super.onStart() subscribeToTabCollections() 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) { @@ -332,7 +331,7 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler { private fun shouldShowTrackingProtectionOnboarding(session: Session) = context?.settings()?.shouldShowTrackingProtectionOnboarding ?: false && - session.trackerBlockingEnabled && session.trackersBlocked.isNotEmpty() + session.trackerBlockingEnabled && session.trackersBlocked.isNotEmpty() companion object { private const val THREE = 3 diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarTopBehavior.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarTopBehavior.kt index 3620bc887d43..c42d3397996d 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarTopBehavior.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarTopBehavior.kt @@ -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 @@ -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) diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index 47dbfed543f9..243fdc03f9ca 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -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 @@ -485,6 +485,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 { diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/EngineViewTopBehavior.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/EngineViewTopBehavior.kt deleted file mode 100644 index 4e630e8e88ef..000000000000 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/EngineViewTopBehavior.kt +++ /dev/null @@ -1,46 +0,0 @@ -package org.mozilla.fenix.components.toolbar - -import android.annotation.SuppressLint -import android.content.Context -import android.util.AttributeSet -import android.view.View -import androidx.coordinatorlayout.widget.CoordinatorLayout -import mozilla.components.concept.engine.EngineView -import mozilla.components.support.ktx.android.view.findViewInHierarchy - -/** - * A [CoordinatorLayout.Behavior] implementation to be used with [EngineView] when placing a toolbar at the - * bottom of the screen. - * - * Using this behavior requires the toolbar to use the BrowserToolbarTopBehavior. - * - * This implementation will update the vertical clipping of the [EngineView] so that top-aligned web content will - * be drawn above the native toolbar. - */ -class EngineViewTopBehavior( - context: Context?, - attrs: AttributeSet? -) : CoordinatorLayout.Behavior(context, attrs) { - @SuppressLint("LogUsage") - override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean { - // This package does not have access to "BrowserToolbar" ... so we are just checking the class name here since - // we actually do not need anything from that class - we only need to identify the instance. - // Right now we do not have a component that has access to (concept/browser-toolbar and concept-engine). - // Creating one just for this behavior is too excessive. - if (dependency::class.java.simpleName == "BrowserToolbar") { - return true - } - - return super.layoutDependsOn(parent, child, dependency) - } - - /** - * Apply vertical clipping to [EngineView]. This requires [EngineViewTopehavior] to be set - * in/on the [EngineView] or its parent. Must be a direct descending child of [CoordinatorLayout]. - */ - override fun onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View): Boolean { - val engineView = child.findViewInHierarchy { it is EngineView } as EngineView? - engineView?.setVerticalClipping(dependency.height - dependency.translationY.toInt()) - return true - } -} 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 df05e9793f5d..9610015ea73a 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -201,7 +201,8 @@ class Settings private constructor( val shouldUseFixedToolbar: Boolean get() { - val accessibilityManager = appContext.getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager + val accessibilityManager = + appContext.getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager return accessibilityManager?.isTouchExplorationEnabled ?: false } diff --git a/docs/metrics.md b/docs/metrics.md index 32bf082477a0..1561f8ab0dda 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -103,6 +103,7 @@ The following metrics are added to the ping: | media_state.pause |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Media playback was paused. |[1](https://github.com/mozilla-mobile/fenix/pull/6463)||2020-03-01 | | media_state.play |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Media started playing. |[1](https://github.com/mozilla-mobile/fenix/pull/6463)||2020-03-01 | | media_state.stop |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Media playback has ended. |[1](https://github.com/mozilla-mobile/fenix/pull/6463)||2020-03-01 | +| metrics.toolbar_position |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The browser toolbar position |[1](https://github.com/mozilla-mobile/fenix/pull/6608)|
  • position: A string that indicates the new position of the toolbar TOP or BOTTOM
|2020-03-01 | | private_browsing_mode.garbage_icon |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the garbage can icon on the private browsing home page, deleting all private tabs. |[1](https://github.com/mozilla-mobile/fenix/pull/4968)||2020-03-01 | | private_browsing_mode.notification_delete |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the private browsing mode notification's "Delete and Open" button. |[1](https://github.com/mozilla-mobile/fenix/pull/4968)||2020-03-01 | | private_browsing_mode.notification_open |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the private browsing mode notification's "Open" button. |[1](https://github.com/mozilla-mobile/fenix/pull/4968)||2020-03-01 | @@ -142,7 +143,7 @@ The following metrics are added to the ping: | sync_auth.sign_up |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |User registered a new Firefox Account, and was signed into it |[1](https://github.com/mozilla-mobile/fenix/pull/4931#issuecomment-529740300)||2020-03-01 | | tab.media_pause |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the pause icon on a tab from the home screen |[1](https://github.com/mozilla-mobile/fenix/pull/5266)||2020-03-01 | | tab.media_play |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the play icon on a tab from the home screen |[1](https://github.com/mozilla-mobile/fenix/pull/5266)||2020-03-01 | -| toolbar_settings.changed_position |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The user selected a new position for the toolbar |[1](https://github.com/mozilla-mobile/fenix/pull/6571)|
  • position: A string that indicates the new position of the toolbar TOP or BOTTOM
|2020-03-01 | +| toolbar_settings.changed_position |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The user selected a new position for the toolbar |[1](https://github.com/mozilla-mobile/fenix/pull/6608)|
  • position: A string that indicates the new position of the toolbar TOP or BOTTOM
|2020-03-01 | | tracking_protection.etp_setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user changed their tracking protection level setting to either strict or standard. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)|
  • etp_setting: The new setting for ETP: strict, standard
|2020-03-01 | | tracking_protection.etp_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened tracking protection settings through settings. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-03-01 | | tracking_protection.etp_shield |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the tracking protection shield icon in toolbar. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-03-01 |