From 3fbbbd6efe62727dce9d296079833382ff2bd9bd Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Tue, 12 Nov 2019 08:38:04 -0800 Subject: [PATCH] For #5694 & #6054: Adds preference screen for toolbar --- app/metrics.yaml | 16 ++++++ .../components/metrics/GleanMetricsService.kt | 5 ++ .../fenix/components/metrics/Metrics.kt | 9 +++- .../fenix/settings/SettingsFragment.kt | 36 +++++++++---- .../fenix/settings/ToolbarSettingsFragment.kt | 54 +++++++++++++++++++ .../java/org/mozilla/fenix/utils/Settings.kt | 11 ++++ app/src/main/res/navigation/nav_graph.xml | 7 +++ app/src/main/res/values/preference_keys.xml | 5 ++ app/src/main/res/values/strings.xml | 10 +++- app/src/main/res/xml/preferences.xml | 4 ++ app/src/main/res/xml/toolbar_preferences.xml | 14 +++++ docs/metrics.md | 1 + 12 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt create mode 100644 app/src/main/res/xml/toolbar_preferences.xml diff --git a/app/metrics.yaml b/app/metrics.yaml index 55b943f6bd4b..55db3014dd40 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -173,6 +173,22 @@ search_shortcuts: - fenix-core@mozilla.com expires: "2020-03-01" +toolbar_settings: + changed_position: + type: event + description: > + The user selected a new position for the toolbar + extra_keys: + position: + description: "A string that indicates the new position of the toolbar TOP or BOTTOM" + bugs: + - https://github.com/mozilla-mobile/fenix/issue/6054 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TODO + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + crash_reporter: opened: type: event 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 cdd1ffa0eca4..8c40be977919 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 @@ -38,6 +38,7 @@ import org.mozilla.fenix.GleanMetrics.SearchWidget import org.mozilla.fenix.GleanMetrics.SyncAccount import org.mozilla.fenix.GleanMetrics.SyncAuth import org.mozilla.fenix.GleanMetrics.Tab +import org.mozilla.fenix.GleanMetrics.ToolbarSettings import org.mozilla.fenix.GleanMetrics.TrackingProtection import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings @@ -401,6 +402,10 @@ private val Event.wrapper: EventWrapper<*>? { Events.openedLink.record(it) }, { Events.openedLinkKeys.valueOf(it) } ) + is Event.ToolbarPositionChanged -> EventWrapper( + { ToolbarSettings.changedPosition.record(it) }, + { ToolbarSettings.changedPositionKeys.valueOf(it) } + ) // Don't record other events in Glean: is Event.AddBookmark -> null is Event.OpenedBookmark -> null diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 0cd7d3a3b1dc..7725a58f2752 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -25,6 +25,7 @@ import org.mozilla.fenix.GleanMetrics.ErrorPage import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Library import org.mozilla.fenix.GleanMetrics.SearchShortcuts +import org.mozilla.fenix.GleanMetrics.ToolbarSettings import org.mozilla.fenix.GleanMetrics.TrackingProtection import org.mozilla.fenix.R import java.util.Locale @@ -134,7 +135,7 @@ sealed class Event { context.getString(R.string.pref_key_show_clipboard_suggestions), context.getString(R.string.pref_key_show_search_shortcuts), context.getString(R.string.pref_key_open_links_in_a_private_tab) - ) + ) override val extras: Map? get() = mapOf( @@ -148,6 +149,12 @@ sealed class Event { } } + data class ToolbarPositionChanged(val position: Position) : Event() { + enum class Position { TOP, BOTTOM } + override val extras: Map? + get() = hashMapOf(ToolbarSettings.changedPositionKeys.position to position.name) + } + data class OpenedLink(val mode: Mode) : Event() { enum class Mode { NORMAL, PRIVATE } override val extras: Map? diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index 1e73064403a6..cbb9f3b25dde 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -49,6 +49,7 @@ import org.mozilla.fenix.R.string.pref_key_search_settings import org.mozilla.fenix.R.string.pref_key_sign_in import org.mozilla.fenix.R.string.pref_key_site_permissions import org.mozilla.fenix.R.string.pref_key_theme +import org.mozilla.fenix.R.string.pref_key_toolbar import org.mozilla.fenix.R.string.pref_key_tracking_protection_settings import org.mozilla.fenix.R.string.pref_key_your_rights import org.mozilla.fenix.components.PrivateShortcutCreateManager @@ -115,6 +116,18 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver { (activity as AppCompatActivity).title = getString(R.string.settings_title) (activity as AppCompatActivity).supportActionBar?.show() + setSummaryAndTitleStrings() + setupPreferences() + + updateAccountUIState( + context!!, + requireComponents.backgroundServices.accountManager.accountProfile() + ) + + updatePreferenceVisibilityForFeatureFlags() + } + + private fun setSummaryAndTitleStrings() { val trackingProtectionPreference = findPreference(getPreferenceKey(pref_key_tracking_protection_settings)) trackingProtectionPreference?.summary = context?.let { @@ -125,11 +138,15 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver { } } + val toolbarPreference = + findPreference(getPreferenceKey(pref_key_toolbar)) + toolbarPreference?.summary = context?.settings()?.toolbarSettingString + val themesPreference = findPreference(getPreferenceKey(pref_key_theme)) themesPreference?.summary = context?.settings()?.themeSettingString - val aboutPreference = findPreference(getPreferenceKey(R.string.pref_key_about)) + val aboutPreference = findPreference(getPreferenceKey(pref_key_about)) val appName = getString(R.string.app_name) aboutPreference?.title = getString(R.string.preferences_about, appName) @@ -151,15 +168,6 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver { isVisible = !PrivateShortcutCreateManager.doesPrivateBrowsingPinnedShortcutExist(context) } - - setupPreferences() - - updateAccountUIState( - context!!, - requireComponents.backgroundServices.accountManager.accountProfile() - ) - - updatePreferenceVisibilityForFeatureFlags() } private fun updatePreferenceVisibilityForFeatureFlags() { @@ -242,6 +250,9 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver { resources.getString(pref_key_theme) -> { navigateToThemeSettings() } + resources.getString(pref_key_toolbar) -> { + navigateToToolbarSettings() + } resources.getString(pref_key_privacy_link) -> { requireContext().let { context -> val intent = SupportUtils.createCustomTabIntent( @@ -322,6 +333,11 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver { Navigation.findNavController(view!!).navigate(directions) } + private fun navigateToToolbarSettings() { + val directions = SettingsFragmentDirections.actionSettingsFragmentToToolbarSettingsFragment() + Navigation.findNavController(view!!).navigate(directions) + } + private fun navigateToSitePermissions() { val directions = SettingsFragmentDirections.actionSettingsFragmentToSitePermissionsFragment() diff --git a/app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt new file mode 100644 index 000000000000..b1c16bf01c1d --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt @@ -0,0 +1,54 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.settings + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.preference.PreferenceFragmentCompat +import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.getPreferenceKey + +class ToolbarSettingsFragment: PreferenceFragmentCompat() { + private lateinit var topPreference: RadioButtonPreference + private lateinit var bottomPreference: RadioButtonPreference + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.toolbar_preferences, rootKey) + } + + override fun onResume() { + super.onResume() + (activity as AppCompatActivity).title = getString(R.string.preferences_toolbar) + (activity as AppCompatActivity).supportActionBar?.show() + + setupClickListeners() + setupRadioGroups() + } + + private fun setupClickListeners() { + val keyToolbarTop = getPreferenceKey(R.string.pref_key_toolbar_top) + topPreference = requireNotNull(findPreference(keyToolbarTop)) + topPreference.onClickListener { + requireContext().components.analytics.metrics.track(Event.ToolbarPositionChanged( + Event.ToolbarPositionChanged.Position.TOP + )) + } + + val keyToolbarBottom = getPreferenceKey(R.string.pref_key_toolbar_bottom) + bottomPreference = requireNotNull(findPreference(keyToolbarBottom)) + bottomPreference.onClickListener { + requireContext().components.analytics.metrics.track(Event.ToolbarPositionChanged( + Event.ToolbarPositionChanged.Position.BOTTOM + )) + } + } + + private fun setupRadioGroups() { + topPreference.addToRadioGroup(bottomPreference) + bottomPreference.addToRadioGroup(topPreference) + } +} 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 5789ac3ebcec..365ba8bfb255 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -203,6 +203,17 @@ class Settings private constructor( default = false ) + var shouldUseBottomToolbar by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_toolbar_bottom), + default = true + ) + + val toolbarSettingString: String + get() = when { + shouldUseBottomToolbar -> appContext.getString(R.string.preference_bottom_toolbar) + else -> appContext.getString(R.string.preference_top_toolbar) + } + fun getDeleteDataOnQuit(type: DeleteBrowsingDataOnQuitType): Boolean = preferences.getBoolean(type.getPreferenceKey(appContext), false) diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index e3cc2cdc591f..552548277779 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -395,6 +395,9 @@ + + diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 9c216399da64..5bc0ac3ac329 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -37,6 +37,7 @@ pref_key_account_auth_error pref_key_private_mode pref_key_theme + pref_key_toolbar pref_key_leakcanary pref_key_remote_debugging pref_key_experimentation @@ -86,6 +87,10 @@ pref_key_category_phone_feature pref_key_exceptions_clear_site_permissions + + pref_key_toolbar_top + pref_key_toolbar_bottom + pref_key_light_theme pref_key_dark_theme diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 948fb36fdb2f..cc07536eae47 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -167,6 +167,8 @@ Account Sign in + + Toolbar Theme @@ -302,6 +304,12 @@ Cancel + + + Top + + Bottom + Light @@ -918,7 +926,7 @@ Paste URL copied to clipboard - + Add to Home screen diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 63da0050c67c..f96fbd6a37ac 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -50,6 +50,10 @@ android:icon="@drawable/ic_internet" android:key="@string/pref_key_make_default_browser" android:title="@string/preferences_set_as_default_browser" /> + + + + + + + diff --git a/docs/metrics.md b/docs/metrics.md index 34168861592f..15807316fdc9 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -135,6 +135,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.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/TODO)|
  • 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 |