Bug 1875465 - Part 4: Add secret setting and remove toolbar customization

fenix/125.0
rahulsainani 3 months ago committed by mergify[bot]
parent 54d7785896
commit 5ea4da3abe

@ -93,9 +93,12 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
val context = requireContext()
val components = context.components
initTabStrip()
val isTabletAndTabStripEnabled = context.settings().isTabletAndTabStripEnabled
if (isTabletAndTabStripEnabled) {
initTabStrip()
}
if (context.settings().isSwipeToolbarToSwitchTabsEnabled) {
if (!isTabletAndTabStripEnabled && context.settings().isSwipeToolbarToSwitchTabsEnabled) {
binding.gestureLayout.addGestureListener(
ToolbarGestureHandler(
activity = requireActivity(),
@ -246,10 +249,6 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
}
private fun initTabStrip() {
if (!resources.getBoolean(R.bool.tablet)) {
return
}
binding.tabStripView.isVisible = true
binding.tabStripView.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

@ -579,7 +579,9 @@ class HomeFragment : Fragment() {
)
toolbarView?.build()
initTabStrip()
if (requireContext().settings().isTabletAndTabStripEnabled) {
initTabStrip()
}
PrivateBrowsingButtonView(binding.privateBrowsingButton, browsingModeManager) { newMode ->
sessionControlInteractor.onPrivateModeButtonClicked(newMode)
@ -658,10 +660,6 @@ class HomeFragment : Fragment() {
}
private fun initTabStrip() {
if (!resources.getBoolean(R.bool.tablet)) {
return
}
binding.tabStripView.isVisible = true
binding.tabStripView.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

@ -66,7 +66,7 @@ class ToolbarView(
gravity = Gravity.TOP
}
val isTabletAndTabStripEnabled = context.resources.getBoolean(R.bool.tablet)
val isTabletAndTabStripEnabled = context.settings().isTabletAndTabStripEnabled
ConstraintSet().apply {
clone(binding.toolbarLayout)
clear(binding.bottomBar.id, ConstraintSet.BOTTOM)

@ -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,8 +53,19 @@ class CustomizationFragment : PreferenceFragmentCompat() {
bindLightTheme()
bindAutoBatteryTheme()
setupRadioGroups()
setupToolbarCategory()
setupGesturesCategory()
val tabletAndTabStripEnabled = requireContext().settings().isTabletAndTabStripEnabled
if (tabletAndTabStripEnabled) {
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()
}
// if tab strip is enabled, swipe toolbar to switch tabs should not be enabled so the
// preference is not shown
setupGesturesCategory(isSwipeToolbarToSwitchTabsVisible = !tabletAndTabStripEnabled)
}
private fun setupRadioGroups() {
@ -140,7 +153,7 @@ class CustomizationFragment : PreferenceFragmentCompat() {
addToRadioGroup(topPreference, bottomPreference)
}
private fun setupGesturesCategory() {
private fun setupGesturesCategory(isSwipeToolbarToSwitchTabsVisible: Boolean) {
requirePreference<SwitchPreference>(R.string.pref_key_website_pull_to_refresh).apply {
isVisible = FeatureFlags.pullToRefreshEnabled
isChecked = context.settings().isPullToRefreshEnabledInBrowser
@ -152,6 +165,7 @@ class CustomizationFragment : PreferenceFragmentCompat() {
}
requirePreference<SwitchPreference>(R.string.pref_key_swipe_toolbar_switch_tabs).apply {
isChecked = context.settings().isSwipeToolbarToSwitchTabsEnabled
isVisible = isSwipeToolbarToSwitchTabsVisible
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}

@ -122,6 +122,8 @@ class SecretSettingsFragment : PreferenceFragmentCompat() {
}
}
setupTabStripPreference()
// for performance reasons, this is only available in Nightly or Debug builds
requirePreference<EditTextPreference>(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<SwitchPreference>(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) ->

@ -857,6 +857,17 @@ class Settings(private val appContext: Context) : PreferencesHolder {
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

@ -78,6 +78,7 @@
<string name="pref_key_enable_suggest_strong_password" translatable="false">pref_key_suggest_strong_password_enabled</string>
<string name="pref_key_enable_debug_drawer" translatable="false">pref_key_enable_debug_drawer</string>
<string name="pref_key_show_first_time_translation" translatable="false">pref_key_show_first_time_translation</string>
<string name="pref_key_enable_tab_strip" translatable="false">pref_key_enable_tab_strip</string>
<!-- Data Choices -->
<string name="pref_key_telemetry" translatable="false">pref_key_telemetry</string>
@ -155,12 +156,14 @@
<string name="pref_key_follow_device_theme" translatable="false">pref_key_follow_device_theme</string>
<!-- Customization Settings -->
<string name="pref_key_customization_preference_screen" translatable="false">pref_key_customization_preference_screen</string>
<string name="pref_key_website_pull_to_refresh" translatable="false">pref_key_website_pull_to_refresh</string>
<string name="pref_key_dynamic_toolbar" translatable="false">pref_key_dynamic_toolbar</string>
<string name="pref_key_swipe_toolbar_switch_tabs" translatable="false">pref_key_swipe_toolbar_switch_tabs</string>
<string name="pref_key_swipe_toolbar_show_tabs" translatable="false">pref_key_swipe_toolbar_show_tabs</string>
<string name="pref_key_recent_tabs" translatable="false">pref_key_recent_tabs</string>
<string name="pref_key_recent_bookmarks" translatable="false">pref_key_recent_bookmarks</string>
<string name="pref_key_customization_category_toolbar" translatable="false">pref_key_customization_category_toolbar</string>
<!-- HTTPS Only Settings -->
<string name="pref_key_https_only_settings" translatable="false">pref_key_https_only_settings</string>

@ -78,6 +78,8 @@
<string name="preferences_debug_felt_privacy" translatable="false">Enable Felt Privacy</string>
<!-- Label for enabling the Debug Drawer -->
<string name="preferences_debug_settings_debug_drawer" translatable="false">Enable Debug Drawer</string>
<!-- Label for enabling the Tab Strip -->
<string name="preferences_debug_settings_tab_strip" translatable="false">Enable Tab Strip</string>
<!-- A secret menu option in the tabs tray for making a tab inactive for testing. -->
<string name="inactive_tabs_menu_item">Make inactive</string>

@ -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/. -->
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:key="@string/pref_key_customization_preference_screen" >
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_theme"
@ -34,6 +35,7 @@
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_toolbar"
android:key="@string/pref_key_customization_category_toolbar"
app:iconSpaceReserved="false">
<org.mozilla.fenix.settings.RadioButtonPreference
android:key="@string/pref_key_toolbar_top"

@ -50,6 +50,11 @@
android:key="@string/pref_key_enable_debug_drawer"
android:title="@string/preferences_debug_settings_debug_drawer"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_enable_tab_strip"
android:title="@string/preferences_debug_settings_tab_strip"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="@string/pref_key_custom_glean_server_url"
android:title="@string/preferences_debug_settings_custom_glean_server_url"

@ -146,6 +146,7 @@ class ToolbarViewTest {
every { context.settings().showUnifiedSearchFeature } returns true
every { context.settings().shouldShowHistorySuggestions } returns true
every { context.settings().shouldShowBookmarkSuggestions } returns true
every { context.settings().isTabletAndTabStripEnabled } returns false
val view = buildToolbarView(false)
mockkObject(FeatureFlags)
@ -161,6 +162,7 @@ class ToolbarViewTest {
every { context.settings().showUnifiedSearchFeature } returns true
every { context.settings().shouldShowHistorySuggestions } returns true
every { context.settings().shouldShowBookmarkSuggestions } returns true
every { context.settings().isTabletAndTabStripEnabled } returns false
val view = buildToolbarView(false)
mockkObject(FeatureFlags)
@ -446,6 +448,7 @@ class ToolbarViewTest {
fun `GIVEN autocomplete disabled WHEN the toolbar view is initialized THEN create an autocomplete with disabled functionality`() {
val settings: Settings = mockk {
every { shouldAutocompleteInAwesomebar } returns false
every { isTabletAndTabStripEnabled } returns false
}
val toolbarView = buildToolbarView(true, settings)
@ -458,6 +461,7 @@ class ToolbarViewTest {
fun `GIVEN autocomplete enabled WHEN the toolbar view is initialized THEN create an autocomplete with enabled functionality`() {
val settings: Settings = mockk {
every { shouldAutocompleteInAwesomebar } returns true
every { isTabletAndTabStripEnabled } returns false
}
val toolbarView = buildToolbarView(true, settings)

Loading…
Cancel
Save