1
0
Fork 0

For #5905 - Creates private browsing settings fragment

master
Jeff Boek 2020-02-07 16:59:59 -08:00
parent ef6913ec25
commit a701988ae9
7 changed files with 92 additions and 68 deletions

View File

@ -0,0 +1,37 @@
/* 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.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import org.mozilla.fenix.R
import org.mozilla.fenix.components.PrivateShortcutCreateManager
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.showToolbar
/**
* Lets the user customize Private browsing options.
*/
class PrivateBrowsingFragment : PreferenceFragmentCompat() {
override fun onResume() {
super.onResume()
showToolbar(getString(R.string.preferences_private_browsing_options))
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.private_browsing_preferences, rootKey)
findPreference<Preference>(getPreferenceKey(R.string.pref_key_add_private_browsing_shortcut))?.apply {
setOnPreferenceClickListener {
requireContext().metrics.track(Event.PrivateBrowsingCreateShortcut)
PrivateShortcutCreateManager.createPrivateShortcut(requireContext())
true
}
}
}
}

View File

@ -27,32 +27,6 @@ import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.R.string.pref_key_about
import org.mozilla.fenix.R.string.pref_key_accessibility
import org.mozilla.fenix.R.string.pref_key_account
import org.mozilla.fenix.R.string.pref_key_account_auth_error
import org.mozilla.fenix.R.string.pref_key_account_category
import org.mozilla.fenix.R.string.pref_key_add_private_browsing_shortcut
import org.mozilla.fenix.R.string.pref_key_data_choices
import org.mozilla.fenix.R.string.pref_key_delete_browsing_data
import org.mozilla.fenix.R.string.pref_key_delete_browsing_data_on_quit_preference
import org.mozilla.fenix.R.string.pref_key_help
import org.mozilla.fenix.R.string.pref_key_language
import org.mozilla.fenix.R.string.pref_key_leakcanary
import org.mozilla.fenix.R.string.pref_key_make_default_browser
import org.mozilla.fenix.R.string.pref_key_passwords
import org.mozilla.fenix.R.string.pref_key_privacy_link
import org.mozilla.fenix.R.string.pref_key_rate
import org.mozilla.fenix.R.string.pref_key_remote_debugging
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_customize
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.R.string.pref_key_addons
import org.mozilla.fenix.components.PrivateShortcutCreateManager
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.application import org.mozilla.fenix.ext.application
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
@ -139,7 +113,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
private fun update() { private fun update() {
val trackingProtectionPreference = val trackingProtectionPreference =
findPreference<Preference>(getPreferenceKey(pref_key_tracking_protection_settings)) findPreference<Preference>(getPreferenceKey(R.string.pref_key_tracking_protection_settings))
trackingProtectionPreference?.summary = context?.let { trackingProtectionPreference?.summary = context?.let {
if (it.settings().shouldUseTrackingProtection) { if (it.settings().shouldUseTrackingProtection) {
getString(R.string.tracking_protection_on) getString(R.string.tracking_protection_on)
@ -149,17 +123,17 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
val toolbarPreference = val toolbarPreference =
findPreference<Preference>(getPreferenceKey(pref_key_toolbar)) findPreference<Preference>(getPreferenceKey(R.string.pref_key_toolbar))
toolbarPreference?.summary = context?.settings()?.toolbarSettingString toolbarPreference?.summary = context?.settings()?.toolbarSettingString
val aboutPreference = findPreference<Preference>(getPreferenceKey(pref_key_about)) val aboutPreference = findPreference<Preference>(getPreferenceKey(R.string.pref_key_about))
val appName = getString(R.string.app_name) val appName = getString(R.string.app_name)
aboutPreference?.title = getString(R.string.preferences_about, appName) aboutPreference?.title = getString(R.string.preferences_about, appName)
val deleteBrowsingDataPreference = val deleteBrowsingDataPreference =
findPreference<Preference>( findPreference<Preference>(
getPreferenceKey( getPreferenceKey(
pref_key_delete_browsing_data_on_quit_preference R.string.pref_key_delete_browsing_data_on_quit_preference
) )
) )
deleteBrowsingDataPreference?.summary = context?.let { deleteBrowsingDataPreference?.summary = context?.let {
@ -179,10 +153,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
private fun updatePreferenceVisibilityForFeatureFlags() { private fun updatePreferenceVisibilityForFeatureFlags() {
findPreference<Preference>(getPreferenceKey(pref_key_passwords))?.apply { findPreference<Preference>(getPreferenceKey(R.string.pref_key_passwords))?.apply {
isVisible = FeatureFlags.logins isVisible = FeatureFlags.logins
} }
findPreference<Preference>(getPreferenceKey(pref_key_language))?.apply { findPreference<Preference>(getPreferenceKey(R.string.pref_key_language))?.apply {
isVisible = FeatureFlags.fenixLanguagePicker isVisible = FeatureFlags.fenixLanguagePicker
} }
} }
@ -190,38 +164,35 @@ class SettingsFragment : PreferenceFragmentCompat() {
@Suppress("ComplexMethod", "LongMethod") @Suppress("ComplexMethod", "LongMethod")
override fun onPreferenceTreeClick(preference: Preference): Boolean { override fun onPreferenceTreeClick(preference: Preference): Boolean {
val directions: NavDirections? = when (preference.key) { val directions: NavDirections? = when (preference.key) {
resources.getString(pref_key_search_settings) -> { resources.getString(R.string.pref_key_search_settings) -> {
SettingsFragmentDirections.actionSettingsFragmentToSearchEngineFragment() SettingsFragmentDirections.actionSettingsFragmentToSearchEngineFragment()
} }
resources.getString(pref_key_tracking_protection_settings) -> { resources.getString(R.string.pref_key_tracking_protection_settings) -> {
requireContext().metrics.track(Event.TrackingProtectionSettings) requireContext().metrics.track(Event.TrackingProtectionSettings)
SettingsFragmentDirections.actionSettingsFragmentToTrackingProtectionFragment() SettingsFragmentDirections.actionSettingsFragmentToTrackingProtectionFragment()
} }
resources.getString(pref_key_site_permissions) -> { resources.getString(R.string.pref_key_site_permissions) -> {
SettingsFragmentDirections.actionSettingsFragmentToSitePermissionsFragment() SettingsFragmentDirections.actionSettingsFragmentToSitePermissionsFragment()
} }
resources.getString(pref_key_add_private_browsing_shortcut) -> { resources.getString(R.string.pref_key_private_browsing) -> {
requireContext().metrics.track(Event.PrivateBrowsingCreateShortcut) SettingsFragmentDirections.actionSettingsFragmentToPrivateBrowsingFragment()
PrivateShortcutCreateManager.createPrivateShortcut(requireContext())
null
} }
resources.getString(pref_key_accessibility) -> { resources.getString(R.string.pref_key_accessibility) -> {
SettingsFragmentDirections.actionSettingsFragmentToAccessibilityFragment() SettingsFragmentDirections.actionSettingsFragmentToAccessibilityFragment()
} }
resources.getString(pref_key_language) -> { resources.getString(R.string.pref_key_language) -> {
SettingsFragmentDirections.actionSettingsFragmentToLocaleSettingsFragment() SettingsFragmentDirections.actionSettingsFragmentToLocaleSettingsFragment()
} }
resources.getString(pref_key_addons) -> { resources.getString(R.string.pref_key_addons) -> {
SettingsFragmentDirections.actionSettingsFragmentToAddonsFragment() SettingsFragmentDirections.actionSettingsFragmentToAddonsFragment()
} }
resources.getString(R.string.pref_key_make_default_browser) -> {
resources.getString(pref_key_make_default_browser) -> {
SettingsFragmentDirections.actionSettingsFragmentToDefaultBrowserSettingsFragment() SettingsFragmentDirections.actionSettingsFragmentToDefaultBrowserSettingsFragment()
} }
resources.getString(pref_key_data_choices) -> { resources.getString(R.string.pref_key_data_choices) -> {
SettingsFragmentDirections.actionSettingsFragmentToDataChoicesFragment() SettingsFragmentDirections.actionSettingsFragmentToDataChoicesFragment()
} }
resources.getString(pref_key_help) -> { resources.getString(R.string.pref_key_help) -> {
(activity as HomeActivity).openToBrowserAndLoad( (activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = SupportUtils.getSumoURLForTopic( searchTermOrURL = SupportUtils.getSumoURLForTopic(
context!!, context!!,
@ -232,7 +203,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
) )
null null
} }
resources.getString(pref_key_rate) -> { resources.getString(R.string.pref_key_rate) -> {
try { try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(SupportUtils.RATE_APP_URL))) startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(SupportUtils.RATE_APP_URL)))
} catch (e: ActivityNotFoundException) { } catch (e: ActivityNotFoundException) {
@ -246,28 +217,28 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
null null
} }
resources.getString(pref_key_passwords) -> { resources.getString(R.string.pref_key_passwords) -> {
SettingsFragmentDirections.actionSettingsFragmentToLoginsFragment() SettingsFragmentDirections.actionSettingsFragmentToLoginsFragment()
} }
resources.getString(pref_key_about) -> { resources.getString(R.string.pref_key_about) -> {
SettingsFragmentDirections.actionSettingsFragmentToAboutFragment() SettingsFragmentDirections.actionSettingsFragmentToAboutFragment()
} }
resources.getString(pref_key_account) -> { resources.getString(R.string.pref_key_account) -> {
SettingsFragmentDirections.actionSettingsFragmentToAccountSettingsFragment() SettingsFragmentDirections.actionSettingsFragmentToAccountSettingsFragment()
} }
resources.getString(pref_key_account_auth_error) -> { resources.getString(R.string.pref_key_account_auth_error) -> {
SettingsFragmentDirections.actionSettingsFragmentToAccountProblemFragment() SettingsFragmentDirections.actionSettingsFragmentToAccountProblemFragment()
} }
resources.getString(pref_key_delete_browsing_data) -> { resources.getString(R.string.pref_key_delete_browsing_data) -> {
SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataFragment() SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataFragment()
} }
resources.getString(pref_key_delete_browsing_data_on_quit_preference) -> { resources.getString(R.string.pref_key_delete_browsing_data_on_quit_preference) -> {
SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataOnQuitFragment() SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataOnQuitFragment()
} }
resources.getString(pref_key_customize) -> { resources.getString(R.string.pref_key_customize) -> {
SettingsFragmentDirections.actionSettingsFragmentToCustomizationFragment() SettingsFragmentDirections.actionSettingsFragmentToCustomizationFragment()
} }
resources.getString(pref_key_privacy_link) -> { resources.getString(R.string.pref_key_privacy_link) -> {
val intent = SupportUtils.createCustomTabIntent( val intent = SupportUtils.createCustomTabIntent(
requireContext(), requireContext(),
SupportUtils.getPrivacyNoticeUrl() SupportUtils.getPrivacyNoticeUrl()
@ -275,7 +246,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
startActivity(intent) startActivity(intent)
null null
} }
resources.getString(pref_key_your_rights) -> { resources.getString(R.string.pref_key_your_rights) -> {
val context = requireContext() val context = requireContext()
val intent = SupportUtils.createCustomTabIntent( val intent = SupportUtils.createCustomTabIntent(
context, context,
@ -298,8 +269,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
private fun setupPreferences() { private fun setupPreferences() {
val leakKey = getPreferenceKey(pref_key_leakcanary) val leakKey = getPreferenceKey(R.string.pref_key_leakcanary)
val debuggingKey = getPreferenceKey(pref_key_remote_debugging) val debuggingKey = getPreferenceKey(R.string.pref_key_remote_debugging)
val preferenceLeakCanary = findPreference<Preference>(leakKey) val preferenceLeakCanary = findPreference<Preference>(leakKey)
val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey) val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey)
@ -334,17 +305,17 @@ class SettingsFragment : PreferenceFragmentCompat() {
*/ */
private fun updateAccountUIState(context: Context, profile: Profile?) { private fun updateAccountUIState(context: Context, profile: Profile?) {
val preferenceSignIn = val preferenceSignIn =
findPreference<Preference>(context.getPreferenceKey(pref_key_sign_in)) findPreference<Preference>(context.getPreferenceKey(R.string.pref_key_sign_in))
val preferenceFirefoxAccount = val preferenceFirefoxAccount =
findPreference<AccountPreference>(context.getPreferenceKey(pref_key_account)) findPreference<AccountPreference>(context.getPreferenceKey(R.string.pref_key_account))
val preferenceFirefoxAccountAuthError = val preferenceFirefoxAccountAuthError =
findPreference<AccountAuthErrorPreference>( findPreference<AccountAuthErrorPreference>(
context.getPreferenceKey( context.getPreferenceKey(
pref_key_account_auth_error R.string.pref_key_account_auth_error
) )
) )
val accountPreferenceCategory = val accountPreferenceCategory =
findPreference<PreferenceCategory>(context.getPreferenceKey(pref_key_account_category)) findPreference<PreferenceCategory>(context.getPreferenceKey(R.string.pref_key_account_category))
val accountManager = requireComponents.backgroundServices.accountManager val accountManager = requireComponents.backgroundServices.accountManager
val account = accountManager.authenticatedAccount() val account = accountManager.authenticatedAccount()

View File

@ -395,6 +395,9 @@
<action <action
android:id="@+id/action_settingsFragment_to_customizationFragment" android:id="@+id/action_settingsFragment_to_customizationFragment"
app:destination="@id/customizationFragment" /> app:destination="@id/customizationFragment" />
<action
android:id="@+id/action_settingsFragment_to_privateBrowsingFragment"
app:destination="@id/privateBrowsingFragment" />
<action <action
android:id="@+id/action_settingsFragment_to_trackingProtectionFragment" android:id="@+id/action_settingsFragment_to_trackingProtectionFragment"
app:destination="@id/trackingProtectionFragment" /> app:destination="@id/trackingProtectionFragment" />
@ -499,6 +502,10 @@
android:id="@+id/customizationFragment" android:id="@+id/customizationFragment"
android:name="org.mozilla.fenix.settings.CustomizationFragment" android:name="org.mozilla.fenix.settings.CustomizationFragment"
android:label="@string/preferences_customize" /> android:label="@string/preferences_customize" />
<fragment
android:id="@+id/privateBrowsingFragment"
android:name="org.mozilla.fenix.settings.PrivateBrowsingFragment"
android:label="@string/preferences_private_browsing_options" />
<fragment <fragment
android:id="@+id/trackingProtectionFragment" android:id="@+id/trackingProtectionFragment"
android:name="org.mozilla.fenix.settings.TrackingProtectionFragment"> android:name="org.mozilla.fenix.settings.TrackingProtectionFragment">

View File

@ -41,6 +41,7 @@
<string name="pref_key_private_mode" translatable="false">pref_key_private_mode</string> <string name="pref_key_private_mode" translatable="false">pref_key_private_mode</string>
<string name="pref_key_customize" translatable="false">pref_key_customize</string> <string name="pref_key_customize" translatable="false">pref_key_customize</string>
<string name="pref_key_toolbar" translatable="false">pref_key_toolbar</string> <string name="pref_key_toolbar" translatable="false">pref_key_toolbar</string>
<string name="pref_key_private_browsing" translatable="false">pref_key_private_browsing</string>
<string name="pref_key_leakcanary" translatable="false">pref_key_leakcanary</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_remote_debugging" translatable="false">pref_key_remote_debugging</string>
<string name="pref_key_experimentation" translatable="false">pref_key_experimentation</string> <string name="pref_key_experimentation" translatable="false">pref_key_experimentation</string>

View File

@ -8,9 +8,4 @@
android:key="@string/pref_key_make_default_browser" android:key="@string/pref_key_make_default_browser"
android:title="@string/preferences_set_as_default_browser" android:title="@string/preferences_set_as_default_browser"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<CheckBoxPreference
android:layout="@layout/checkbox_left_preference"
android:defaultValue="false"
android:key="@string/pref_key_open_links_in_a_private_tab"
android:title="@string/preferences_open_links_in_a_private_tab" />
</PreferenceScreen> </PreferenceScreen>

View File

@ -69,7 +69,7 @@
<androidx.preference.Preference <androidx.preference.Preference
android:icon="@drawable/ic_private_browsing" android:icon="@drawable/ic_private_browsing"
android:key="@string/pref_key_add_private_browsing_shortcut" android:key="@string/pref_key_private_browsing"
android:title="@string/preferences_private_browsing_options"/> android:title="@string/preferences_private_browsing_options"/>
<androidx.preference.Preference <androidx.preference.Preference

View File

@ -0,0 +1,13 @@
<?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">
<androidx.preference.Preference
android:key="@string/pref_key_add_private_browsing_shortcut"
android:title="@string/preferences_add_private_browsing_shortcut"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_open_links_in_a_private_tab"
android:title="@string/preferences_open_links_in_a_private_tab" />
</PreferenceScreen>