From a4ba981fa69419214ebbdf9e535e163ca0068404 Mon Sep 17 00:00:00 2001 From: rahulsainani Date: Sat, 17 Feb 2024 00:07:47 +0100 Subject: [PATCH] Bug 1875465 - Part 4: Add secret setting and remove toolbar customization --- .../org/mozilla/fenix/browser/BrowserFragment.kt | 2 +- .../java/org/mozilla/fenix/home/HomeFragment.kt | 2 +- .../java/org/mozilla/fenix/home/ToolbarView.kt | 2 +- .../fenix/settings/CustomizationFragment.kt | 12 +++++++++++- .../fenix/settings/SecretSettingsFragment.kt | 10 ++++++++++ .../main/java/org/mozilla/fenix/utils/Settings.kt | 15 +++++++++++++-- fenix/app/src/main/res/values/preference_keys.xml | 3 +++ fenix/app/src/main/res/values/static_strings.xml | 2 ++ .../main/res/xml/customization_preferences.xml | 4 +++- .../main/res/xml/secret_settings_preferences.xml | 5 +++++ 10 files changed, 50 insertions(+), 7 deletions(-) diff --git a/fenix/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/fenix/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 5c5e273807eb..ea4aa1f0d559 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -221,7 +221,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { } private fun initTabStrip() { - if (!resources.getBoolean(R.bool.tablet)) { + if (!requireContext().settings().isTabletAndTabStripEnabled) { return } diff --git a/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 31bbefd79d4a..1e213832c79c 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -659,7 +659,7 @@ class HomeFragment : Fragment() { } private fun initTabStrip() { - if (!resources.getBoolean(R.bool.tablet)) { + if (!requireContext().settings().isTabletAndTabStripEnabled) { return } diff --git a/fenix/app/src/main/java/org/mozilla/fenix/home/ToolbarView.kt b/fenix/app/src/main/java/org/mozilla/fenix/home/ToolbarView.kt index a8ed02acd414..0a5f30282229 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/home/ToolbarView.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/home/ToolbarView.kt @@ -71,7 +71,7 @@ class ToolbarView( clear(binding.bottomBar.id, ConstraintSet.BOTTOM) clear(binding.bottomBarShadow.id, ConstraintSet.BOTTOM) - if (context.resources.getBoolean(R.bool.tablet)) { + if (context.settings().isTabletAndTabStripEnabled) { connect( binding.bottomBar.id, ConstraintSet.TOP, diff --git a/fenix/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt b/fenix/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt index fb1d26a6d2af..58fc42f19d2b 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt @@ -10,7 +10,9 @@ import android.os.Build.VERSION.SDK_INT import android.os.Bundle import androidx.appcompat.app.AppCompatDelegate import androidx.preference.Preference +import androidx.preference.PreferenceCategory import androidx.preference.PreferenceFragmentCompat +import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreference import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.GleanMetrics.AppTheme @@ -51,7 +53,15 @@ class CustomizationFragment : PreferenceFragmentCompat() { bindLightTheme() bindAutoBatteryTheme() setupRadioGroups() - setupToolbarCategory() + if (requireContext().settings().isTabletAndTabStripEnabled) { + val preferenceScreen: PreferenceScreen = + requirePreference(R.string.pref_key_customization_preference_screen) + val toolbarPrefCategory: PreferenceCategory = + requirePreference(R.string.pref_key_customization_category_toolbar) + preferenceScreen.removePreference(toolbarPrefCategory) + } else { + setupToolbarCategory() + } setupGesturesCategory() } diff --git a/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt index 2d91285fedfb..7d7d4108c9b2 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt @@ -122,6 +122,8 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { } } + setupTabStripPreference() + // for performance reasons, this is only available in Nightly or Debug builds requirePreference(R.string.pref_key_custom_glean_server_url).apply { isVisible = Config.channel.isNightlyOrDebug && BuildConfig.GLEAN_CUSTOM_URL.isNullOrEmpty() @@ -138,6 +140,14 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { } } + private fun setupTabStripPreference() { + requirePreference(R.string.pref_key_enable_tab_strip).apply { + isVisible = Config.channel.isNightlyOrDebug && context.resources.getBoolean(R.bool.tablet) + isChecked = context.settings().isTabStripEnabled + onPreferenceChangeListener = SharedPreferenceUpdater() + } + } + override fun onPreferenceTreeClick(preference: Preference): Boolean { when (preference.key) { getString(R.string.pref_key_custom_sponsored_stories_parameters) -> diff --git a/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index b388c6ed890c..195247e67d26 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -851,12 +851,23 @@ class Settings(private val appContext: Context) : PreferencesHolder { */ val shouldUseFixedTopToolbar: Boolean get() { - return touchExplorationIsEnabled || switchServiceIsEnabled || isTablet + return touchExplorationIsEnabled || switchServiceIsEnabled || isTabletAndTabStripEnabled } private val isTablet: Boolean get() = appContext.resources.getBoolean(R.bool.tablet) + /** + * Indicates if the user has enabled the tab strip feature. + */ + val isTabStripEnabled by booleanPreference( + key = appContext.getPreferenceKey(R.string.pref_key_enable_tab_strip), + default = false, + ) + + val isTabletAndTabStripEnabled: Boolean + get() = isTablet && isTabStripEnabled + var lastKnownMode: BrowsingMode = BrowsingMode.Normal get() { val lastKnownModeWasPrivate = preferences.getBoolean( @@ -925,7 +936,7 @@ class Settings(private val appContext: Context) : PreferencesHolder { ) val toolbarPosition: ToolbarPosition - get() = if (isTablet) { + get() = if (isTabletAndTabStripEnabled) { ToolbarPosition.TOP } else if (shouldUseBottomToolbar) { ToolbarPosition.BOTTOM diff --git a/fenix/app/src/main/res/values/preference_keys.xml b/fenix/app/src/main/res/values/preference_keys.xml index 6c161555677b..0db2c3d738c3 100644 --- a/fenix/app/src/main/res/values/preference_keys.xml +++ b/fenix/app/src/main/res/values/preference_keys.xml @@ -78,6 +78,7 @@ pref_key_suggest_strong_password_enabled pref_key_enable_debug_drawer pref_key_show_first_time_translation + pref_key_enable_tab_strip pref_key_telemetry @@ -155,12 +156,14 @@ pref_key_follow_device_theme + pref_key_customization_preference_screen pref_key_website_pull_to_refresh pref_key_dynamic_toolbar pref_key_swipe_toolbar_switch_tabs pref_key_swipe_toolbar_show_tabs pref_key_recent_tabs pref_key_recent_bookmarks + pref_key_customization_category_toolbar pref_key_https_only_settings diff --git a/fenix/app/src/main/res/values/static_strings.xml b/fenix/app/src/main/res/values/static_strings.xml index 6432c5bedda1..649bfb5ae178 100644 --- a/fenix/app/src/main/res/values/static_strings.xml +++ b/fenix/app/src/main/res/values/static_strings.xml @@ -78,6 +78,8 @@ Enable Felt Privacy Enable Debug Drawer + + Enable Tab Strip Make inactive diff --git a/fenix/app/src/main/res/xml/customization_preferences.xml b/fenix/app/src/main/res/xml/customization_preferences.xml index cfd13f3aaf70..f1e1ea05e25b 100644 --- a/fenix/app/src/main/res/xml/customization_preferences.xml +++ b/fenix/app/src/main/res/xml/customization_preferences.xml @@ -3,7 +3,8 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto" + android:key="@string/pref_key_customization_preference_screen" > +