diff --git a/app/metrics.yaml b/app/metrics.yaml index 2c3ccff6c4e7..b57dcdee2bfd 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -176,6 +176,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 0f1ca812fb51..c804ad1c4547 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 @@ -40,6 +40,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 @@ -444,6 +445,9 @@ private val Event.wrapper: EventWrapper<*>? ) is Event.ViewLoginPassword -> EventWrapper( { Logins.viewPasswordLogin.record(it) } + is Event.ToolbarPositionChanged -> EventWrapper( + { ToolbarSettings.changedPosition.record(it) }, + { ToolbarSettings.changedPositionKeys.valueOf(it) } ) // Don't record other events in Glean: is Event.AddBookmark -> 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 9bf6f83548f9..e1e7136a3c24 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 @@ -27,6 +27,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 @@ -165,6 +166,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 269a16555403..4f90b20e2574 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 3eca3854bd4f..67f4267b22e4 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -394,6 +394,9 @@ + + diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index a4a8a7176875..d271c8787206 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 aae590cad0c8..893071b214cb 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 @@ -922,7 +930,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 8523c5a081ee..da102ea0ee09 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -149,6 +149,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 |