Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
fenix
Commits
a701988a
Commit
a701988a
authored
Feb 07, 2020
by
Jeff Boek
Browse files
For #5905 - Creates private browsing settings fragment
parent
ef6913ec
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/settings/PrivateBrowsingFragment.kt
0 → 100644
View file @
a701988a
/* 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
}
}
}
}
app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
View file @
a701988a
...
...
@@ -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
<
Preference
>(
getPreferenceKey
(
pref_key_tracking_protection_settings
))
findPreference
<
Preference
>(
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
<
Preference
>(
getPreferenceKey
(
pref_key_toolbar
))
findPreference
<
Preference
>(
getPreferenceKey
(
R
.
string
.
pref_key_toolbar
))
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
)
aboutPreference
?.
title
=
getString
(
R
.
string
.
preferences_about
,
appName
)
val
deleteBrowsingDataPreference
=
findPreference
<
Preference
>(
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
<
Preference
>(
getPreferenceKey
(
pref_key_passwords
))
?.
apply
{
findPreference
<
Preference
>(
getPreferenceKey
(
R
.
string
.
pref_key_passwords
))
?.
apply
{
isVisible
=
FeatureFlags
.
logins
}
findPreference
<
Preference
>(
getPreferenceKey
(
pref_key_language
))
?.
apply
{
findPreference
<
Preference
>(
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
<
Preference
>(
leakKey
)
val
preferenceRemoteDebugging
=
findPreference
<
Preference
>(
debuggingKey
)
...
...
@@ -334,17 +305,17 @@ class SettingsFragment : PreferenceFragmentCompat() {
*/
private
fun
updateAccountUIState
(
context
:
Context
,
profile
:
Profile
?)
{
val
preferenceSignIn
=
findPreference
<
Preference
>(
context
.
getPreferenceKey
(
pref_key_sign_in
))
findPreference
<
Preference
>(
context
.
getPreferenceKey
(
R
.
string
.
pref_key_sign_in
))
val
preferenceFirefoxAccount
=
findPreference
<
AccountPreference
>(
context
.
getPreferenceKey
(
pref_key_account
))
findPreference
<
AccountPreference
>(
context
.
getPreferenceKey
(
R
.
string
.
pref_key_account
))
val
preferenceFirefoxAccountAuthError
=
findPreference
<
AccountAuthErrorPreference
>(
context
.
getPreferenceKey
(
pref_key_account_auth_error
R
.
string
.
pref_key_account_auth_error
)
)
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
account
=
accountManager
.
authenticatedAccount
()
...
...
app/src/main/res/navigation/nav_graph.xml
View file @
a701988a
...
...
@@ -395,6 +395,9 @@
<action
android:id=
"@+id/action_settingsFragment_to_customizationFragment"
app:destination=
"@id/customizationFragment"
/>
<action
android:id=
"@+id/action_settingsFragment_to_privateBrowsingFragment"
app:destination=
"@id/privateBrowsingFragment"
/>
<action
android:id=
"@+id/action_settingsFragment_to_trackingProtectionFragment"
app:destination=
"@id/trackingProtectionFragment"
/>
...
...
@@ -499,6 +502,10 @@
android:id=
"@+id/customizationFragment"
android:name=
"org.mozilla.fenix.settings.CustomizationFragment"
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
android:id=
"@+id/trackingProtectionFragment"
android:name=
"org.mozilla.fenix.settings.TrackingProtectionFragment"
>
...
...
app/src/main/res/values/preference_keys.xml
View file @
a701988a
...
...
@@ -41,6 +41,7 @@
<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_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_remote_debugging"
translatable=
"false"
>
pref_key_remote_debugging
</string>
<string
name=
"pref_key_experimentation"
translatable=
"false"
>
pref_key_experimentation
</string>
...
...
app/src/main/res/xml/default_browser_preferences.xml
View file @
a701988a
...
...
@@ -8,9 +8,4 @@
android:key=
"@string/pref_key_make_default_browser"
android:title=
"@string/preferences_set_as_default_browser"
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>
app/src/main/res/xml/preferences.xml
View file @
a701988a
...
...
@@ -69,7 +69,7 @@
<androidx.preference.Preference
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"
/>
<androidx.preference.Preference
...
...
app/src/main/res/xml/private_browsing_preferences.xml
0 → 100644
View file @
a701988a
<?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>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment