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
ef6913ec
Commit
ef6913ec
authored
Feb 07, 2020
by
Jeff Boek
Browse files
For #5905 - Combine theme and toolbar settings
parent
cfb9b168
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/settings/
Theme
Fragment.kt
→
app/src/main/java/org/mozilla/fenix/settings/
Customization
Fragment.kt
View file @
ef6913ec
...
...
@@ -15,21 +15,25 @@ import org.mozilla.fenix.components.metrics.Event
import
org.mozilla.fenix.ext.components
import
org.mozilla.fenix.ext.getPreferenceKey
import
org.mozilla.fenix.ext.requireComponents
import
org.mozilla.fenix.ext.settings
import
org.mozilla.fenix.ext.showToolbar
class
ThemeFragment
:
PreferenceFragmentCompat
()
{
/**
* Lets the user customize the UI.
*/
class
CustomizationFragment
:
PreferenceFragmentCompat
()
{
private
lateinit
var
radioLightTheme
:
RadioButtonPreference
private
lateinit
var
radioDarkTheme
:
RadioButtonPreference
private
lateinit
var
radioAutoBatteryTheme
:
RadioButtonPreference
private
lateinit
var
radioFollowDeviceTheme
:
RadioButtonPreference
override
fun
onCreatePreferences
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
setPreferencesFromResource
(
R
.
xml
.
theme
_preferences
,
rootKey
)
setPreferencesFromResource
(
R
.
xml
.
customization
_preferences
,
rootKey
)
}
override
fun
onResume
()
{
super
.
onResume
()
showToolbar
(
getString
(
R
.
string
.
preferences_
them
e
))
showToolbar
(
getString
(
R
.
string
.
preferences_
customiz
e
))
setupPreferences
()
}
...
...
@@ -39,6 +43,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
bindLightTheme
()
bindAutoBatteryTheme
()
setupRadioGroups
()
setupToolbarCategory
()
}
private
fun
setupRadioGroups
()
{
...
...
@@ -111,4 +116,28 @@ class ThemeFragment : PreferenceFragmentCompat() {
}
requireComponents
.
useCases
.
sessionUseCases
.
reload
.
invoke
()
}
private
fun
setupToolbarCategory
()
{
val
keyToolbarTop
=
getPreferenceKey
(
R
.
string
.
pref_key_toolbar_top
)
val
topPreference
=
requireNotNull
(
findPreference
<
RadioButtonPreference
>(
keyToolbarTop
))
topPreference
.
onClickListener
{
requireContext
().
components
.
analytics
.
metrics
.
track
(
Event
.
ToolbarPositionChanged
(
Event
.
ToolbarPositionChanged
.
Position
.
TOP
))
}
val
keyToolbarBottom
=
getPreferenceKey
(
R
.
string
.
pref_key_toolbar_bottom
)
val
bottomPreference
=
requireNotNull
(
findPreference
<
RadioButtonPreference
>(
keyToolbarBottom
))
bottomPreference
.
onClickListener
{
requireContext
().
components
.
analytics
.
metrics
.
track
(
Event
.
ToolbarPositionChanged
(
Event
.
ToolbarPositionChanged
.
Position
.
BOTTOM
))
}
topPreference
.
setCheckedWithoutClickListener
(!
requireContext
().
settings
().
shouldUseBottomToolbar
)
bottomPreference
.
setCheckedWithoutClickListener
(
requireContext
().
settings
().
shouldUseBottomToolbar
)
topPreference
.
addToRadioGroup
(
bottomPreference
)
bottomPreference
.
addToRadioGroup
(
topPreference
)
}
}
app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
View file @
ef6913ec
...
...
@@ -47,7 +47,7 @@ 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_
them
e
import
org.mozilla.fenix.R.string.pref_key_
customiz
e
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
...
...
@@ -152,10 +152,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
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
(
pref_key_about
))
val
appName
=
getString
(
R
.
string
.
app_name
)
aboutPreference
?.
title
=
getString
(
R
.
string
.
preferences_about
,
appName
)
...
...
@@ -268,11 +264,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
resources
.
getString
(
pref_key_delete_browsing_data_on_quit_preference
)
->
{
SettingsFragmentDirections
.
actionSettingsFragmentToDeleteBrowsingDataOnQuitFragment
()
}
resources
.
getString
(
pref_key_theme
)
->
{
SettingsFragmentDirections
.
actionSettingsFragmentToThemeFragment
()
}
resources
.
getString
(
pref_key_toolbar
)
->
{
SettingsFragmentDirections
.
actionSettingsFragmentToToolbarSettingsFragment
()
resources
.
getString
(
pref_key_customize
)
->
{
SettingsFragmentDirections
.
actionSettingsFragmentToCustomizationFragment
()
}
resources
.
getString
(
pref_key_privacy_link
)
->
{
val
intent
=
SupportUtils
.
createCustomTabIntent
(
...
...
app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt
deleted
100644 → 0
View file @
cfb9b168
/* 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.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
import
org.mozilla.fenix.ext.settings
import
org.mozilla.fenix.ext.showToolbar
/**
* Settings to adjust the position of the browser toolbar.
*/
class
ToolbarSettingsFragment
:
PreferenceFragmentCompat
()
{
override
fun
onCreatePreferences
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
setPreferencesFromResource
(
R
.
xml
.
toolbar_preferences
,
rootKey
)
}
override
fun
onResume
()
{
super
.
onResume
()
showToolbar
(
getString
(
R
.
string
.
preferences_toolbar
))
setupPreferences
()
}
private
fun
setupPreferences
()
{
val
keyToolbarTop
=
getPreferenceKey
(
R
.
string
.
pref_key_toolbar_top
)
val
topPreference
=
requireNotNull
(
findPreference
<
RadioButtonPreference
>(
keyToolbarTop
))
topPreference
.
onClickListener
{
requireContext
().
components
.
analytics
.
metrics
.
track
(
Event
.
ToolbarPositionChanged
(
Event
.
ToolbarPositionChanged
.
Position
.
TOP
))
}
val
keyToolbarBottom
=
getPreferenceKey
(
R
.
string
.
pref_key_toolbar_bottom
)
val
bottomPreference
=
requireNotNull
(
findPreference
<
RadioButtonPreference
>(
keyToolbarBottom
))
bottomPreference
.
onClickListener
{
requireContext
().
components
.
analytics
.
metrics
.
track
(
Event
.
ToolbarPositionChanged
(
Event
.
ToolbarPositionChanged
.
Position
.
BOTTOM
))
}
topPreference
.
setCheckedWithoutClickListener
(!
requireContext
().
settings
().
shouldUseBottomToolbar
)
bottomPreference
.
setCheckedWithoutClickListener
(
requireContext
().
settings
().
shouldUseBottomToolbar
)
topPreference
.
addToRadioGroup
(
bottomPreference
)
bottomPreference
.
addToRadioGroup
(
topPreference
)
}
}
app/src/main/java/org/mozilla/fenix/utils/Settings.kt
View file @
ef6913ec
...
...
@@ -107,10 +107,10 @@ class Settings private constructor(
val
isCrashReportingEnabled
:
Boolean
get
()
=
isCrashReportEnabledInBuild
&&
preferences
.
getBoolean
(
appContext
.
getPreferenceKey
(
R
.
string
.
pref_key_crash_reporter
),
true
)
preferences
.
getBoolean
(
appContext
.
getPreferenceKey
(
R
.
string
.
pref_key_crash_reporter
),
true
)
val
isRemoteDebuggingEnabled
by
booleanPreference
(
appContext
.
getPreferenceKey
(
R
.
string
.
pref_key_remote_debugging
),
...
...
@@ -308,15 +308,6 @@ class Settings private constructor(
true
).
apply
()
val
themeSettingString
:
String
get
()
=
when
{
shouldFollowDeviceTheme
->
appContext
.
getString
(
R
.
string
.
preference_follow_device_theme
)
shouldUseAutoBatteryTheme
->
appContext
.
getString
(
R
.
string
.
preference_auto_battery_theme
)
shouldUseDarkTheme
->
appContext
.
getString
(
R
.
string
.
preference_dark_theme
)
shouldUseLightTheme
->
appContext
.
getString
(
R
.
string
.
preference_light_theme
)
else
->
appContext
.
getString
(
R
.
string
.
preference_light_theme
)
}
@VisibleForTesting
(
otherwise
=
PRIVATE
)
internal
val
loginsSecureWarningSyncCount
by
intPreference
(
appContext
.
getPreferenceKey
(
R
.
string
.
pref_key_logins_secure_warning_sync
),
...
...
app/src/main/res/navigation/nav_graph.xml
View file @
ef6913ec
...
...
@@ -393,8 +393,8 @@
android:id=
"@+id/action_settingsFragment_to_aboutFragment"
app:destination=
"@id/aboutFragment"
/>
<action
android:id=
"@+id/action_settingsFragment_to_
theme
Fragment"
app:destination=
"@id/
theme
Fragment"
/>
android:id=
"@+id/action_settingsFragment_to_
customization
Fragment"
app:destination=
"@id/
customization
Fragment"
/>
<action
android:id=
"@+id/action_settingsFragment_to_trackingProtectionFragment"
app:destination=
"@id/trackingProtectionFragment"
/>
...
...
@@ -410,9 +410,6 @@
<action
android:id=
"@+id/action_settingsFragment_to_defaultBrowserSettingsFragment"
app:destination=
"@id/defaultBrowserSettingsFragment"
/>
<action
android:id=
"@+id/action_settingsFragment_to_toolbarSettingsFragment"
app:destination=
"@id/toolbarSettingsFragment"
/>
<action
android:id=
"@+id/action_settingsFragment_to_localeSettingsFragment"
app:destination=
"@id/localeSettingsFragment"
/>
...
...
@@ -499,9 +496,9 @@
app:argType=
"android.content.Intent"
/>
</fragment>
<fragment
android:id=
"@+id/
theme
Fragment"
android:name=
"org.mozilla.fenix.settings.
Theme
Fragment"
android:label=
"@string/preferences_
them
e"
/>
android:id=
"@+id/
customization
Fragment"
android:name=
"org.mozilla.fenix.settings.
Customization
Fragment"
android:label=
"@string/preferences_
customiz
e"
/>
<fragment
android:id=
"@+id/trackingProtectionFragment"
android:name=
"org.mozilla.fenix.settings.TrackingProtectionFragment"
>
...
...
@@ -706,9 +703,6 @@
android:name=
"searchEngineIdentifier"
app:argType=
"string"
/>
</fragment>
<fragment
android:id=
"@+id/toolbarSettingsFragment"
android:name=
"org.mozilla.fenix.settings.ToolbarSettingsFragment"
/>
<fragment
android:id=
"@+id/localeSettingsFragment"
android:name=
"org.mozilla.fenix.settings.advanced.LocaleSettingsFragment"
/>
...
...
app/src/main/res/values/preference_keys.xml
View file @
ef6913ec
...
...
@@ -39,7 +39,7 @@
<string
name=
"pref_key_sign_in"
translatable=
"false"
>
pref_key_sign_in
</string>
<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_
them
e"
translatable=
"false"
>
pref_key_
them
e
</string>
<string
name=
"pref_key_
customiz
e"
translatable=
"false"
>
pref_key_
customiz
e
</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>
...
...
app/src/main/res/xml/customization_preferences.xml
0 → 100644
View file @
ef6913ec
<?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/. -->
<androidx.preference.PreferenceScreen
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<androidx.preference.PreferenceCategory
android:title=
"@string/preferences_theme"
app:iconSpaceReserved=
"false"
app:allowDividerBelow=
"false"
>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"@bool/underAPI28"
android:key=
"@string/pref_key_light_theme"
android:title=
"@string/preference_light_theme"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"false"
android:key=
"@string/pref_key_dark_theme"
android:title=
"@string/preference_dark_theme"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"false"
android:key=
"@string/pref_key_auto_battery_theme"
android:title=
"@string/preference_auto_battery_theme"
app:isPreferenceVisible=
"@bool/underAPI28"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"@bool/API28"
android:key=
"@string/pref_key_follow_device_theme"
android:title=
"@string/preference_follow_device_theme"
app:isPreferenceVisible=
"@bool/API28"
/>
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:title=
"@string/preferences_toolbar"
app:iconSpaceReserved=
"false"
app:allowDividerAbove=
"false"
>
<org.mozilla.fenix.settings.RadioButtonPreference
android:key=
"@string/pref_key_toolbar_top"
android:title=
"@string/preference_top_toolbar"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:key=
"@string/pref_key_toolbar_bottom"
android:title=
"@string/preference_bottom_toolbar"
/>
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>
app/src/main/res/xml/preferences.xml
View file @
ef6913ec
...
...
@@ -29,7 +29,7 @@
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:title=
"@string/preferences_category_
basics
"
android:title=
"@string/preferences_category_
general
"
app:iconSpaceReserved=
"false"
>
<androidx.preference.Preference
android:icon=
"@drawable/ic_search"
...
...
@@ -38,67 +38,78 @@
<androidx.preference.Preference
android:icon=
"@drawable/ic_customize"
android:key=
"@string/pref_key_theme"
android:title=
"@string/preferences_theme"
/>
android:key=
"@string/pref_key_customize"
android:title=
"@string/preferences_customize"
/>
<androidx.preference.Preference
app:isPreferenceVisible=
"false"
android:icon=
"@drawable/ic_login"
android:key=
"@string/pref_key_passwords"
android:title=
"@string/preferences_passwords_logins_and_passwords"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_accessibility"
android:key=
"@string/pref_key_accessibility"
android:title=
"@string/preferences_accessibility"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_language"
android:key=
"@string/pref_key_language"
android:title=
"@string/preferences_language"
/>
<androidx.preference.Preference
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
android:title=
"@string/preferences_category_privacy"
android:title=
"@string/preferences_category_privacy
_security
"
app:iconSpaceReserved=
"false"
>
<androidx.preference.Preference
android:icon=
"@drawable/ic_private_browsing"
android:key=
"@string/pref_key_add_private_browsing_shortcut"
android:title=
"@string/preferences_private_browsing_options"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_tracking_protection_enabled"
android:key=
"@string/pref_key_tracking_protection_settings"
android:title=
"@string/preference_enhanced_tracking_protection"
/>
<androidx.preference.Preference
app:isPreferenceVisible=
"false"
android:icon=
"@drawable/ic_login"
android:key=
"@string/pref_key_passwords"
android:title=
"@string/preferences_passwords_logins_and_passwords"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_private_browsing"
android:key=
"@string/pref_key_add_private_browsing_shortcut"
android:title=
"@string/preferences_add_private_browsing_shortcut"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_permission"
android:key=
"@string/pref_key_site_permissions"
android:title=
"@string/preferences_site_permissions"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_delete"
android:key=
"@string/pref_key_delete_browsing_data"
android:title=
"@string/preferences_delete_browsing_data"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_exit"
android:key=
"@string/pref_key_delete_browsing_data_on_quit_preference"
android:title=
"@string/preferences_delete_browsing_data_on_quit"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_data_collection"
android:key=
"@string/pref_key_data_choices"
android:title=
"@string/preferences_data_collection"
/>
<androidx.preference.SwitchPreference
android:defaultValue=
"false"
android:icon=
"@drawable/ic_app_links"
android:key=
"@string/pref_key_open_links_in_external_app"
android:title=
"@string/preferences_open_links_in_apps"
/>
<androidx.preference.SwitchPreference
android:defaultValue=
"false"
android:icon=
"@drawable/ic_info"
android:key=
"@string/pref_key_leakcanary"
android:title=
"@string/preference_leakcanary"
app:isPreferenceVisible=
"@bool/IS_DEBUG"
/>
</androidx.preference.PreferenceCategory>
<PreferenceCategory
...
...
@@ -109,11 +120,6 @@
android:icon=
"@drawable/mozac_ic_extensions_black"
android:key=
"@string/pref_key_addons"
android:title=
"@string/preferences_addons"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_language"
android:key=
"@string/pref_key_language"
android:title=
"@string/preferences_language"
app:isPreferenceVisible=
"false"
/>
</PreferenceCategory>
<PreferenceCategory
...
...
@@ -133,6 +139,7 @@
android:icon=
"@drawable/ic_bookmark_outline"
android:key=
"@string/pref_key_rate"
android:title=
"@string/preferences_rate"
/>
<androidx.preference.Preference
android:icon=
"@drawable/ic_info"
android:key=
"@string/pref_key_about"
...
...
app/src/main/res/xml/theme_preferences.xml
deleted
100644 → 0
View file @
cfb9b168
<?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/. -->
<androidx.preference.PreferenceScreen
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"@bool/underAPI28"
android:key=
"@string/pref_key_light_theme"
android:title=
"@string/preference_light_theme"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"false"
android:key=
"@string/pref_key_dark_theme"
android:title=
"@string/preference_dark_theme"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"false"
android:key=
"@string/pref_key_auto_battery_theme"
android:title=
"@string/preference_auto_battery_theme"
app:isPreferenceVisible=
"@bool/underAPI28"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue=
"@bool/API28"
android:key=
"@string/pref_key_follow_device_theme"
android:title=
"@string/preference_follow_device_theme"
app:isPreferenceVisible=
"@bool/API28"
/>
</androidx.preference.PreferenceScreen>
app/src/main/res/xml/toolbar_preferences.xml
deleted
100644 → 0
View file @
cfb9b168
<?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:key=
"@string/pref_key_toolbar_top"
android:title=
"@string/preference_top_toolbar"
/>
<org.mozilla.fenix.settings.RadioButtonPreference
android:key=
"@string/pref_key_toolbar_bottom"
android:title=
"@string/preference_bottom_toolbar"
/>
</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