diff --git a/app/src/main/java/org/mozilla/fenix/settings/PrivateBrowsingFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/PrivateBrowsingFragment.kt new file mode 100644 index 000000000..639075063 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/settings/PrivateBrowsingFragment.kt @@ -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(getPreferenceKey(R.string.pref_key_add_private_browsing_shortcut))?.apply { + setOnPreferenceClickListener { + requireContext().metrics.track(Event.PrivateBrowsingCreateShortcut) + PrivateShortcutCreateManager.createPrivateShortcut(requireContext()) + true + } + } + } +} 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 0c7bcecb5..8033c5dbe 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -27,32 +27,6 @@ import org.mozilla.fenix.Config import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.HomeActivity 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.ext.application import org.mozilla.fenix.ext.components @@ -139,7 +113,7 @@ class SettingsFragment : PreferenceFragmentCompat() { private fun update() { val trackingProtectionPreference = - findPreference(getPreferenceKey(pref_key_tracking_protection_settings)) + findPreference(getPreferenceKey(R.string.pref_key_tracking_protection_settings)) trackingProtectionPreference?.summary = context?.let { if (it.settings().shouldUseTrackingProtection) { getString(R.string.tracking_protection_on) @@ -149,17 +123,17 @@ class SettingsFragment : PreferenceFragmentCompat() { } val toolbarPreference = - findPreference(getPreferenceKey(pref_key_toolbar)) + findPreference(getPreferenceKey(R.string.pref_key_toolbar)) toolbarPreference?.summary = context?.settings()?.toolbarSettingString - val aboutPreference = findPreference(getPreferenceKey(pref_key_about)) + val aboutPreference = findPreference(getPreferenceKey(R.string.pref_key_about)) val appName = getString(R.string.app_name) aboutPreference?.title = getString(R.string.preferences_about, appName) val deleteBrowsingDataPreference = findPreference( getPreferenceKey( - pref_key_delete_browsing_data_on_quit_preference + R.string.pref_key_delete_browsing_data_on_quit_preference ) ) deleteBrowsingDataPreference?.summary = context?.let { @@ -179,10 +153,10 @@ class SettingsFragment : PreferenceFragmentCompat() { } private fun updatePreferenceVisibilityForFeatureFlags() { - findPreference(getPreferenceKey(pref_key_passwords))?.apply { + findPreference(getPreferenceKey(R.string.pref_key_passwords))?.apply { isVisible = FeatureFlags.logins } - findPreference(getPreferenceKey(pref_key_language))?.apply { + findPreference(getPreferenceKey(R.string.pref_key_language))?.apply { isVisible = FeatureFlags.fenixLanguagePicker } } @@ -190,38 +164,35 @@ class SettingsFragment : PreferenceFragmentCompat() { @Suppress("ComplexMethod", "LongMethod") override fun onPreferenceTreeClick(preference: Preference): Boolean { val directions: NavDirections? = when (preference.key) { - resources.getString(pref_key_search_settings) -> { + resources.getString(R.string.pref_key_search_settings) -> { SettingsFragmentDirections.actionSettingsFragmentToSearchEngineFragment() } - resources.getString(pref_key_tracking_protection_settings) -> { + resources.getString(R.string.pref_key_tracking_protection_settings) -> { requireContext().metrics.track(Event.TrackingProtectionSettings) SettingsFragmentDirections.actionSettingsFragmentToTrackingProtectionFragment() } - resources.getString(pref_key_site_permissions) -> { + resources.getString(R.string.pref_key_site_permissions) -> { SettingsFragmentDirections.actionSettingsFragmentToSitePermissionsFragment() } - resources.getString(pref_key_add_private_browsing_shortcut) -> { - requireContext().metrics.track(Event.PrivateBrowsingCreateShortcut) - PrivateShortcutCreateManager.createPrivateShortcut(requireContext()) - null + resources.getString(R.string.pref_key_private_browsing) -> { + SettingsFragmentDirections.actionSettingsFragmentToPrivateBrowsingFragment() } - resources.getString(pref_key_accessibility) -> { + resources.getString(R.string.pref_key_accessibility) -> { SettingsFragmentDirections.actionSettingsFragmentToAccessibilityFragment() } - resources.getString(pref_key_language) -> { + resources.getString(R.string.pref_key_language) -> { SettingsFragmentDirections.actionSettingsFragmentToLocaleSettingsFragment() } - resources.getString(pref_key_addons) -> { + resources.getString(R.string.pref_key_addons) -> { SettingsFragmentDirections.actionSettingsFragmentToAddonsFragment() } - - resources.getString(pref_key_make_default_browser) -> { + resources.getString(R.string.pref_key_make_default_browser) -> { SettingsFragmentDirections.actionSettingsFragmentToDefaultBrowserSettingsFragment() } - resources.getString(pref_key_data_choices) -> { + resources.getString(R.string.pref_key_data_choices) -> { SettingsFragmentDirections.actionSettingsFragmentToDataChoicesFragment() } - resources.getString(pref_key_help) -> { + resources.getString(R.string.pref_key_help) -> { (activity as HomeActivity).openToBrowserAndLoad( searchTermOrURL = SupportUtils.getSumoURLForTopic( context!!, @@ -232,7 +203,7 @@ class SettingsFragment : PreferenceFragmentCompat() { ) null } - resources.getString(pref_key_rate) -> { + resources.getString(R.string.pref_key_rate) -> { try { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(SupportUtils.RATE_APP_URL))) } catch (e: ActivityNotFoundException) { @@ -246,28 +217,28 @@ class SettingsFragment : PreferenceFragmentCompat() { } null } - resources.getString(pref_key_passwords) -> { + resources.getString(R.string.pref_key_passwords) -> { SettingsFragmentDirections.actionSettingsFragmentToLoginsFragment() } - resources.getString(pref_key_about) -> { + resources.getString(R.string.pref_key_about) -> { SettingsFragmentDirections.actionSettingsFragmentToAboutFragment() } - resources.getString(pref_key_account) -> { + resources.getString(R.string.pref_key_account) -> { SettingsFragmentDirections.actionSettingsFragmentToAccountSettingsFragment() } - resources.getString(pref_key_account_auth_error) -> { + resources.getString(R.string.pref_key_account_auth_error) -> { SettingsFragmentDirections.actionSettingsFragmentToAccountProblemFragment() } - resources.getString(pref_key_delete_browsing_data) -> { + resources.getString(R.string.pref_key_delete_browsing_data) -> { 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() } - resources.getString(pref_key_customize) -> { + resources.getString(R.string.pref_key_customize) -> { SettingsFragmentDirections.actionSettingsFragmentToCustomizationFragment() } - resources.getString(pref_key_privacy_link) -> { + resources.getString(R.string.pref_key_privacy_link) -> { val intent = SupportUtils.createCustomTabIntent( requireContext(), SupportUtils.getPrivacyNoticeUrl() @@ -275,7 +246,7 @@ class SettingsFragment : PreferenceFragmentCompat() { startActivity(intent) null } - resources.getString(pref_key_your_rights) -> { + resources.getString(R.string.pref_key_your_rights) -> { val context = requireContext() val intent = SupportUtils.createCustomTabIntent( context, @@ -298,8 +269,8 @@ class SettingsFragment : PreferenceFragmentCompat() { } private fun setupPreferences() { - val leakKey = getPreferenceKey(pref_key_leakcanary) - val debuggingKey = getPreferenceKey(pref_key_remote_debugging) + val leakKey = getPreferenceKey(R.string.pref_key_leakcanary) + val debuggingKey = getPreferenceKey(R.string.pref_key_remote_debugging) val preferenceLeakCanary = findPreference(leakKey) val preferenceRemoteDebugging = findPreference(debuggingKey) @@ -334,17 +305,17 @@ class SettingsFragment : PreferenceFragmentCompat() { */ private fun updateAccountUIState(context: Context, profile: Profile?) { val preferenceSignIn = - findPreference(context.getPreferenceKey(pref_key_sign_in)) + findPreference(context.getPreferenceKey(R.string.pref_key_sign_in)) val preferenceFirefoxAccount = - findPreference(context.getPreferenceKey(pref_key_account)) + findPreference(context.getPreferenceKey(R.string.pref_key_account)) val preferenceFirefoxAccountAuthError = findPreference( context.getPreferenceKey( - pref_key_account_auth_error + R.string.pref_key_account_auth_error ) ) val accountPreferenceCategory = - findPreference(context.getPreferenceKey(pref_key_account_category)) + findPreference(context.getPreferenceKey(R.string.pref_key_account_category)) val accountManager = requireComponents.backgroundServices.accountManager val account = accountManager.authenticatedAccount() diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 62ade0e69..57d4e27c9 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -395,6 +395,9 @@ + @@ -499,6 +502,10 @@ android:id="@+id/customizationFragment" android:name="org.mozilla.fenix.settings.CustomizationFragment" android:label="@string/preferences_customize" /> + diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 1d2c48406..5c667c290 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -41,6 +41,7 @@ pref_key_private_mode pref_key_customize pref_key_toolbar + pref_key_private_browsing pref_key_leakcanary pref_key_remote_debugging pref_key_experimentation diff --git a/app/src/main/res/xml/default_browser_preferences.xml b/app/src/main/res/xml/default_browser_preferences.xml index 2fcfd4eb7..d82e6ab04 100644 --- a/app/src/main/res/xml/default_browser_preferences.xml +++ b/app/src/main/res/xml/default_browser_preferences.xml @@ -8,9 +8,4 @@ android:key="@string/pref_key_make_default_browser" android:title="@string/preferences_set_as_default_browser" app:iconSpaceReserved="false" /> - diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 7a5cee4cc..bd1c53b76 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -69,7 +69,7 @@ + + + + +