Skip to content

Commit

Permalink
For mozilla-mobile#5694 & mozilla-mobile#6054: Adds preference screen…
Browse files Browse the repository at this point in the history
… for toolbar
  • Loading branch information
sblatz committed Nov 15, 2019
1 parent 55a2009 commit ccc996e
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 11 deletions.
16 changes: 16 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -444,6 +445,9 @@ private val Event.wrapper: EventWrapper<*>?
)
is Event.ViewLoginPassword -> EventWrapper<NoExtraKeys>(
{ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -165,6 +166,12 @@ sealed class Event {
}
}

data class ToolbarPositionChanged(val position: Position) : Event() {
enum class Position { TOP, BOTTOM }
override val extras: Map<ToolbarSettings.changedPositionKeys, String>?
get() = hashMapOf(ToolbarSettings.changedPositionKeys.position to position.name)
}

data class OpenedLink(val mode: Mode) : Event() {
enum class Mode { NORMAL, PRIVATE }
override val extras: Map<Events.openedLinkKeys, String>?
Expand Down
36 changes: 26 additions & 10 deletions app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Preference>(getPreferenceKey(pref_key_tracking_protection_settings))
trackingProtectionPreference?.summary = context?.let {
Expand All @@ -125,11 +138,15 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
}
}

val toolbarPreference =
findPreference<Preference>(getPreferenceKey(pref_key_toolbar))
toolbarPreference?.summary = context?.settings()?.toolbarSettingString

val themesPreference =
findPreference<Preference>(getPreferenceKey(pref_key_theme))
themesPreference?.summary = context?.settings()?.themeSettingString

val aboutPreference = findPreference<Preference>(getPreferenceKey(R.string.pref_key_about))
val aboutPreference = findPreference<Preference>(getPreferenceKey(pref_key_about))
val appName = getString(R.string.app_name)
aboutPreference?.title = getString(R.string.preferences_about, appName)

Expand All @@ -151,15 +168,6 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
isVisible =
!PrivateShortcutCreateManager.doesPrivateBrowsingPinnedShortcutExist(context)
}

setupPreferences()

updateAccountUIState(
context!!,
requireComponents.backgroundServices.accountManager.accountProfile()
)

updatePreferenceVisibilityForFeatureFlags()
}

private fun updatePreferenceVisibilityForFeatureFlags() {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@
<action
android:id="@+id/action_settingsFragment_to_defaultBrowserSettingsFragment"
app:destination="@id/defaultBrowserSettingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_toolbarSettingsFragment"
app:destination="@id/toolbarSettingsFragment" />
</fragment>
<fragment
android:id="@+id/dataChoicesFragment"
Expand Down Expand Up @@ -659,4 +662,8 @@
android:name="savedLoginItem"
app:argType="org.mozilla.fenix.logins.SavedLoginsItem" />
</fragment>
<fragment
android:id="@+id/toolbarSettingsFragment"
android:name="org.mozilla.fenix.settings.ToolbarSettingsFragment"
android:label="ToolbarSettingsFragment" />
</navigation>
5 changes: 5 additions & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<string name="pref_key_account_auth_error" translatable="false">pref_key_account_auth_error</string>
<string name="pref_key_private_mode" translatable="false">pref_key_private_mode</string>
<string name="pref_key_theme" translatable="false">pref_key_theme</string>
<string name="pref_key_toolbar" translatable="false">pref_key_toolbar</string>
<string name="pref_key_leakcanary" translatable="false">pref_key_leakcanary</string>
<string name="pref_key_remote_debugging" translatable="false">pref_key_remote_debugging</string>
<string name="pref_key_experimentation" translatable="false">pref_key_experimentation</string>
Expand Down Expand Up @@ -86,6 +87,10 @@
<string name="pref_key_category_phone_feature" translatable="false">pref_key_category_phone_feature</string>
<string name="pref_key_exceptions_clear_site_permissions" translatable="false">pref_key_exceptions_clear_site_permissions</string>

<!-- Toolbar Settings -->
<string name="pref_key_toolbar_top" translatable="false">pref_key_toolbar_top</string>
<string name="pref_key_toolbar_bottom" translatable="false">pref_key_toolbar_bottom</string>

<!-- Theme Settings -->
<string name="pref_key_light_theme" translatable="false">pref_key_light_theme</string>
<string name="pref_key_dark_theme" translatable="false">pref_key_dark_theme</string>
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
<string name="preferences_category_account">Account</string>
<!-- Preference shown on banner to sign into account -->
<string name="preferences_sign_in">Sign in</string>
<!-- Preference for changing where the toolbar is positioned -->
<string name="preferences_toolbar">Toolbar</string>
<!-- Preference for changing default theme to dark or light mode -->
<string name="preferences_theme">Theme</string>
<!-- Preference description for banner about signing in -->
Expand Down Expand Up @@ -302,6 +304,12 @@
<!-- Button to cancel pairing -->
<string name="pair_cancel">Cancel</string>

<!-- Toolbar Preferences -->
<!-- Preference for using top toolbar -->
<string name="preference_top_toolbar">Top</string>
<!-- Preference for using bottom toolbar -->
<string name="preference_bottom_toolbar">Bottom</string>

<!-- Theme Preferences -->
<!-- Preference for using light theme -->
<string name="preference_light_theme">Light</string>
Expand Down Expand Up @@ -922,7 +930,7 @@
<string name="browser_toolbar_long_press_popup_paste">Paste</string>
<!-- Snackbar message shown after an URL has been copied to clipboard. -->
<string name="browser_toolbar_url_copied_to_clipboard_snackbar">URL copied to clipboard</string>

<!-- Title text for the Add To Homescreen dialog -->
<string name="add_to_homescreen_title">Add to Home screen</string>
<!-- Cancel button text for the Add to Homescreen dialog -->
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<androidx.preference.Preference
android:key="@string/pref_key_toolbar"
android:title="@string/preferences_toolbar" />
</androidx.preference.PreferenceCategory>

<androidx.preference.PreferenceCategory
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/xml/toolbar_preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_toolbar_top"
android:title="@string/preference_top_toolbar" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="true"
android:key="@string/pref_key_toolbar_bottom"
android:title="@string/preference_bottom_toolbar" />
</PreferenceScreen>
1 change: 1 addition & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)|<ul><li>position: A string that indicates the new position of the toolbar TOP or BOTTOM</li></ul>|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)|<ul><li>etp_setting: The new setting for ETP: strict, standard</li></ul>|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 |
Expand Down

0 comments on commit ccc996e

Please sign in to comment.