diff --git a/app/src/main/java/org/mozilla/fenix/settings/ThemeFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt similarity index 73% rename from app/src/main/java/org/mozilla/fenix/settings/ThemeFragment.kt rename to app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt index 983246198..63d92459b 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/ThemeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt @@ -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(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(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) + } } 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 9fc970eef..0c7bcecb5 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -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(getPreferenceKey(pref_key_toolbar)) toolbarPreference?.summary = context?.settings()?.toolbarSettingString - val themesPreference = - findPreference(getPreferenceKey(pref_key_theme)) - themesPreference?.summary = context?.settings()?.themeSettingString - val aboutPreference = findPreference(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( diff --git a/app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt deleted file mode 100644 index 1abc31ceb..000000000 --- a/app/src/main/java/org/mozilla/fenix/settings/ToolbarSettingsFragment.kt +++ /dev/null @@ -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(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(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) - } -} diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 660853160..4cbeeacd3 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -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), diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 91d9b6a11..62ade0e69 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -393,8 +393,8 @@ android:id="@+id/action_settingsFragment_to_aboutFragment" app:destination="@id/aboutFragment" /> + android:id="@+id/action_settingsFragment_to_customizationFragment" + app:destination="@id/customizationFragment" /> @@ -410,9 +410,6 @@ - @@ -499,9 +496,9 @@ app:argType="android.content.Intent" /> + android:id="@+id/customizationFragment" + android:name="org.mozilla.fenix.settings.CustomizationFragment" + android:label="@string/preferences_customize" /> @@ -706,9 +703,6 @@ android:name="searchEngineIdentifier" app:argType="string" /> - diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 21bf3082e..1d2c48406 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -39,7 +39,7 @@ pref_key_sign_in pref_key_account_auth_error pref_key_private_mode - pref_key_theme + pref_key_customize pref_key_toolbar pref_key_leakcanary pref_key_remote_debugging diff --git a/app/src/main/res/xml/customization_preferences.xml b/app/src/main/res/xml/customization_preferences.xml new file mode 100644 index 000000000..e651f85ad --- /dev/null +++ b/app/src/main/res/xml/customization_preferences.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index ac0d5d61b..7a5cee4cc 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -29,7 +29,7 @@ + android:key="@string/pref_key_customize" + android:title="@string/preferences_customize" /> + + + + - - + + + - - + + + + + + + - + - - - - - - - - - - - diff --git a/app/src/main/res/xml/toolbar_preferences.xml b/app/src/main/res/xml/toolbar_preferences.xml deleted file mode 100644 index 1f1a4db22..000000000 --- a/app/src/main/res/xml/toolbar_preferences.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - -