For #5905 - Combine theme and toolbar settings
parent
cfb9b16863
commit
ef6913ec25
|
@ -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_theme))
|
||||
showToolbar(getString(R.string.preferences_customize))
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -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_theme
|
||||
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
|
||||
|
@ -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(
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/* 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)
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
|
|
|
@ -393,8 +393,8 @@
|
|||
android:id="@+id/action_settingsFragment_to_aboutFragment"
|
||||
app:destination="@id/aboutFragment" />
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_themeFragment"
|
||||
app:destination="@id/themeFragment" />
|
||||
android:id="@+id/action_settingsFragment_to_customizationFragment"
|
||||
app:destination="@id/customizationFragment" />
|
||||
<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/themeFragment"
|
||||
android:name="org.mozilla.fenix.settings.ThemeFragment"
|
||||
android:label="@string/preferences_theme" />
|
||||
android:id="@+id/customizationFragment"
|
||||
android:name="org.mozilla.fenix.settings.CustomizationFragment"
|
||||
android:label="@string/preferences_customize" />
|
||||
<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" />
|
||||
|
|
|
@ -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_theme" translatable="false">pref_key_theme</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_leakcanary" translatable="false">pref_key_leakcanary</string>
|
||||
<string name="pref_key_remote_debugging" translatable="false">pref_key_remote_debugging</string>
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?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>
|
|
@ -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"
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
<?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>
|
|
@ -1,12 +0,0 @@
|
|||
<?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>
|
Loading…
Reference in New Issue