commit e1666f8fd6ff1f18db2e43c141fc75e349ecc505 parent 4b62952df685c617010837dc8cda0fd05a37e241 Author: Andrey Zinovyev <azinovyev@mozilla.com> Date: Thu, 16 Oct 2025 14:05:03 +0000 Bug 1969021 - Build 'Customize Toolbar Layout' setting r=android-reviewers,Roger Differential Revision: https://phabricator.services.mozilla.com/D267048 Diffstat:
14 files changed, 385 insertions(+), 60 deletions(-)
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMiddleware.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMiddleware.kt @@ -124,6 +124,7 @@ import org.mozilla.fenix.ext.isWideWindow import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.navigateSafe import org.mozilla.fenix.nimbus.FxNimbus +import org.mozilla.fenix.settings.ToolbarShortcutPreference import org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.getCookieBannerUIMode import org.mozilla.fenix.tabstray.Page import org.mozilla.fenix.tabstray.ext.isActiveDownload @@ -741,9 +742,12 @@ class BrowserToolbarMiddleware( val isTallWindow = environment?.fragment?.isTallWindow() == true val tabStripEnabled = settings.isTabStripEnabled val shouldUseExpandedToolbar = settings.shouldUseExpandedToolbar + val useCustomPrimary = settings.shouldShowToolbarCustomization && !shouldUseExpandedToolbar + val primarySlotAction = mapShortcutToAction(settings.toolbarShortcutKey) + .takeIf { useCustomPrimary } ?: ToolbarAction.NewTab val configs = listOf( - ToolbarActionConfig(ToolbarAction.NewTab) { + ToolbarActionConfig(primarySlotAction) { !tabStripEnabled && (!shouldUseExpandedToolbar || !isTallWindow || isWideWindow) }, ToolbarActionConfig(ToolbarAction.TabCounter) { @@ -1240,4 +1244,14 @@ class BrowserToolbarMiddleware( Source.AddressBar -> MetricsUtils.BookmarkAction.Source.BROWSER_TOOLBAR Source.NavigationBar -> MetricsUtils.BookmarkAction.Source.BROWSER_NAVBAR } + + companion object { + @VisibleForTesting + @JvmStatic + internal fun mapShortcutToAction(key: String): ToolbarAction = when (key) { + ToolbarShortcutPreference.Keys.NEW_TAB -> ToolbarAction.NewTab + ToolbarShortcutPreference.Keys.SHARE -> ToolbarAction.Share + else -> ToolbarAction.NewTab + } + } } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt @@ -60,6 +60,7 @@ class CustomizationFragment : PreferenceFragmentCompat() { updateToolbarCategoryBasedOnTabStrip(tabletAndTabStripEnabled) setupTabStripCategory() setupToolbarLayout() + updateToolbarShortcutBasedOnLayout() // if tab strip is enabled, swipe toolbar to switch tabs should not be enabled so the // preference is not shown @@ -86,6 +87,21 @@ class CustomizationFragment : PreferenceFragmentCompat() { } } + private fun updateToolbarShortcutBasedOnLayout() { + val category = requirePreference<PreferenceCategory>( + R.string.pref_key_customization_category_toolbar_shortcut, + ) + val settings = requireContext().settings() + + category.isVisible = + settings.shouldShowToolbarCustomization && + Config.channel.isNightlyOrDebug && + settings.shouldUseComposableToolbar && + settings.toolbarRedesignEnabled && + isTallWindow() && + !settings.shouldUseExpandedToolbar + } + private fun setupRadioGroups() { addToRadioGroup( radioLightTheme, @@ -194,6 +210,11 @@ class CustomizationFragment : PreferenceFragmentCompat() { isVisible = Config.channel.isNightlyOrDebug && settings.shouldUseComposableToolbar && settings.toolbarRedesignEnabled && isTallWindow() && !isWideWindow() } + + val layoutToggle = requirePreference<ToggleRadioButtonPreference>(R.string.pref_key_toolbar_expanded) + layoutToggle.setOnToggleChanged { + updateToolbarShortcutBasedOnLayout() + } updateToolbarLayoutIcons() } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt @@ -82,57 +82,30 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { } } } - requirePreference<SwitchPreference>(R.string.pref_key_enable_simple_toolbar_customization).apply { + requirePreference<SwitchPreference>(R.string.pref_key_enable_toolbar_customization).apply { + val newOption = context.settings().toolbarRedesignEnabled isEnabled = newOption - when (newOption) { - true -> { - summary = null - } - - false -> { - isChecked = false - summary = getString(R.string.preferences_debug_settings_toolbar_redesign_summary) - context.settings().shouldShowSimpleToolbarCustomization = false - } + summary = when (newOption) { + true -> null + false -> getString(R.string.preferences_debug_settings_toolbar_customization_summary) } - } - requirePreference<SwitchPreference>(R.string.pref_key_enable_expanded_toolbar_customization).apply { - isEnabled = newOption - when (newOption) { - true -> { - summary = null - } - - false -> { - isChecked = false - summary = getString(R.string.preferences_debug_settings_toolbar_redesign_summary) - context.settings().shouldShowExpandedToolbarCustomization = false - } + if (!newOption && isChecked) { + isChecked = false + context.settings().shouldShowToolbarCustomization = false } } } true } } - - requirePreference<SwitchPreference>(R.string.pref_key_enable_simple_toolbar_customization).apply { - isVisible = Config.channel.isDebug - isChecked = context.settings().shouldShowSimpleToolbarCustomization - isEnabled = context.settings().shouldUseComposableToolbar - summary = when (context.settings().shouldUseComposableToolbar) { - true -> null - false -> getString(R.string.preferences_debug_settings_toolbar_redesign_summary) - } - onPreferenceChangeListener = SharedPreferenceUpdater() - } - - requirePreference<SwitchPreference>(R.string.pref_key_enable_expanded_toolbar_customization).apply { + requirePreference<SwitchPreference>(R.string.pref_key_enable_toolbar_customization).apply { isVisible = Config.channel.isDebug - isChecked = context.settings().shouldShowExpandedToolbarCustomization - isEnabled = context.settings().shouldUseComposableToolbar - summary = when (context.settings().shouldUseComposableToolbar) { + isChecked = context.settings().shouldShowToolbarCustomization + val newOption = context.settings().toolbarRedesignEnabled + isEnabled = newOption + summary = when (newOption) { true -> null - false -> getString(R.string.preferences_debug_settings_toolbar_redesign_summary) + false -> getString(R.string.preferences_debug_settings_toolbar_customization_summary) } onPreferenceChangeListener = SharedPreferenceUpdater() } @@ -148,9 +121,20 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> (newValue as? Boolean)?.let { newOption -> context.settings().toolbarRedesignEnabled = newOption - if (newOption == false) { + if (!newOption) { context.settings().shouldUseExpandedToolbar = false } + requirePreference<SwitchPreference>(R.string.pref_key_enable_toolbar_customization).apply { + isEnabled = newOption + summary = when (newOption) { + true -> null + false -> getString(R.string.preferences_debug_settings_toolbar_customization_summary) + } + if (!newOption && isChecked) { + isChecked = false + context.settings().shouldShowToolbarCustomization = false + } + } } true } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToggleRadioButtonPreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToggleRadioButtonPreference.kt @@ -35,6 +35,15 @@ class ToggleRadioButtonPreference @JvmOverloads constructor( private var trueOptionIconRes: Int = 0 private var falseOptionIconRes: Int = 0 + private var onToggleChanged: ((Boolean) -> Unit)? = null + + /** + * Registers a listener that is invoked whenever the toggle selection changes. + */ + fun setOnToggleChanged(listener: (Boolean) -> Unit) { + onToggleChanged = listener + } + init { layoutResource = R.layout.preference_widget_toggle_radio_button isSelectable = false @@ -82,6 +91,7 @@ class ToggleRadioButtonPreference @JvmOverloads constructor( optionFalseIconView.isSelected = false preferences.edit { putBoolean(sharedKey, true) } notifyChanged() + onToggleChanged?.invoke(true) } optionFalseView.setOnClickListener { @@ -89,6 +99,7 @@ class ToggleRadioButtonPreference @JvmOverloads constructor( optionFalseIconView.isSelected = true preferences.edit { putBoolean(sharedKey, false) } notifyChanged() + onToggleChanged?.invoke(false) } } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarShortcutPreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarShortcutPreference.kt @@ -0,0 +1,175 @@ +/* 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.content.Context +import android.content.res.ColorStateList +import android.content.res.Configuration +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.RadioButton +import android.widget.TextView +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import androidx.compose.ui.graphics.toArgb +import androidx.core.widget.ImageViewCompat +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder +import mozilla.components.compose.base.theme.AcornColors +import mozilla.components.compose.base.theme.darkColorPalette +import mozilla.components.compose.base.theme.lightColorPalette +import org.mozilla.fenix.R +import org.mozilla.fenix.ext.settings +import mozilla.components.ui.icons.R as iconsR + +/** + * Custom Preference that renders the options list. + * Selecting an option moves it to the top and persists to SharedPreferences. + */ +class ToolbarShortcutPreference @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, +) : Preference(context, attrs) { + + private val options: List<Option> by lazy { + listOf( + Option(Keys.NEW_TAB, iconsR.drawable.mozac_ic_plus_24, R.string.home_screen_shortcut_open_new_tab_2), + Option(Keys.SHARE, iconsR.drawable.mozac_ic_share_android_24, R.string.browser_menu_share), + ) + } + + init { + layoutResource = R.layout.preference_toolbar_shortcut + isSelectable = false + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + + val settings = context.settings() + val selectedKey = settings.toolbarShortcutKey + + val selectedContainer = holder.findViewById(R.id.selected_container) as LinearLayout + val optionsContainer = holder.findViewById(R.id.options_container) as LinearLayout + val separator = holder.findViewById(R.id.separator) as View + + val selected = options.firstOrNull { it.key == selectedKey } ?: options.first() + + selectedContainer.removeAllViews() + selectedContainer.addView( + makeRow( + parent = selectedContainer, + option = selected, + isChecked = true, + isEnabled = false, + onClick = {}, + ), + ) + + val remaining = options.filter { it.key != selected.key }.distinctBy { it.key } + optionsContainer.removeAllViews() + remaining.forEach { opt -> + optionsContainer.addView( + makeRow( + parent = optionsContainer, + option = opt, + isChecked = false, + isEnabled = true, + ) { newlySelected -> + settings.toolbarShortcutKey = newlySelected.key + notifyChanged() + }, + ) + } + + separator.visibility = if (remaining.isEmpty()) View.GONE else View.VISIBLE + } + + private fun makeRow( + parent: ViewGroup, + option: Option, + isChecked: Boolean, + isEnabled: Boolean, + onClick: (Option) -> Unit, + ): View { + val row = LayoutInflater.from(context) + .inflate(R.layout.toolbar_shortcut_row, parent, false) as LinearLayout + + val radio = row.findViewById<RadioButton>(R.id.row_radio) + val icon = row.findViewById<ImageView>(R.id.row_icon) + val label = row.findViewById<TextView>(R.id.row_label) + + icon.setImageResource(option.icon) + label.setText(option.label) + + radio?.setStartCheckedIndicator() + radio.isChecked = isChecked + radio.isEnabled = true + + val colors = getPalette(context) + + label.setTextColor( + (if (isChecked) colors.textAccentDisabled else colors.textPrimary).toArgb(), + ) + + ImageViewCompat.setImageTintList( + icon, + ColorStateList.valueOf( + (if (isChecked) colors.iconAccentViolet else colors.iconPrimary).toArgb(), + ), + ) + + radio.buttonTintList = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), + intArrayOf(-android.R.attr.state_checked), + ), + intArrayOf(colors.formSelected.toArgb(), colors.formDefault.toArgb()), + ) + + if (isEnabled) { + val clicker = View.OnClickListener { + onClick(option) + } + row.setOnClickListener(clicker) + } + + row.isEnabled = isEnabled + + return row + } + + /** + * Get the color palette based on the current browsing mode. + * + * N.B: This logic was taken from [Theme.getTheme] in FirefoxTheme, however we cannot use it + * directly because those functions are annotated to be Composable and refactoring that can be + * done in a follow-up when needed. This needs to be done less hacky. + * https://bugzilla.mozilla.org/show_bug.cgi?id=1993265 + */ + private fun getPalette(context: Context): AcornColors { + val uiMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return if (uiMode == Configuration.UI_MODE_NIGHT_YES) darkColorPalette else lightColorPalette + } + + private data class Option( + val key: String, + @param:DrawableRes val icon: Int, + @param:StringRes val label: Int, + ) + + /** + * String keys used to persist and map the selected toolbar shortcut option. + * These values are stored in preferences and also used to resolve the UI/action. + */ + object Keys { + const val NEW_TAB = "new_tab" + const val SHARE = "share" + } +} diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -229,6 +229,15 @@ class Settings(private val appContext: Context) : PreferencesHolder { ) /** + * Indicates what toolbar shortcut key is currently selected. + */ + var toolbarShortcutKey: String by stringPreference( + key = appContext.getPreferenceKey(R.string.pref_key_toolbar_shortcut), + default = { "new_tab" }, + persistDefaultIfNotExists = true, + ) + + /** * Indicates if the Pocket recommendations homescreen section should also show sponsored stories. */ val showPocketSponsoredStories by lazyFeatureFlagPreference( @@ -1394,13 +1403,8 @@ class Settings(private val appContext: Context) : PreferencesHolder { persistDefaultIfNotExists = true, ) - var shouldShowSimpleToolbarCustomization by booleanPreference( - key = appContext.getPreferenceKey(R.string.pref_key_enable_simple_toolbar_customization), - default = { FxNimbus.features.toolbarRedesignOption.value().showSimpleCustomization }, - ) - - var shouldShowExpandedToolbarCustomization by booleanPreference( - key = appContext.getPreferenceKey(R.string.pref_key_enable_expanded_toolbar_customization), + var shouldShowToolbarCustomization by booleanPreference( + key = appContext.getPreferenceKey(R.string.pref_key_enable_toolbar_customization), default = { FxNimbus.features.toolbarRedesignOption.value().showExpandedCustomization }, ) diff --git a/mobile/android/fenix/app/src/main/res/layout/preference_toolbar_shortcut.xml b/mobile/android/fenix/app/src/main/res/layout/preference_toolbar_shortcut.xml @@ -0,0 +1,42 @@ +<?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/. --> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="0dp" + android:paddingEnd="0dp" + android:paddingBottom="12dp"> + + <TextView + android:id="@+id/toolbar_shortcut_title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/top_bar_alignment_margin_start" + android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" + android:text="@string/preferences_toolbar_select_shortcut" /> + + <LinearLayout + android:id="@+id/selected_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingTop="8dp" /> + + <View + android:id="@+id/separator" + android:layout_width="match_parent" + android:layout_height="1dp" + android:alpha="0.12" + android:background="?attr/colorOnSurface" + android:visibility="gone" /> + + <LinearLayout + android:id="@+id/options_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" /> +</LinearLayout> diff --git a/mobile/android/fenix/app/src/main/res/layout/toolbar_shortcut_row.xml b/mobile/android/fenix/app/src/main/res/layout/toolbar_shortcut_row.xml @@ -0,0 +1,39 @@ +<?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/. --> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="48dp" + android:gravity="center_vertical" + android:orientation="horizontal" + android:paddingStart="@dimen/top_bar_no_icon_alignment_margin_start" + android:paddingEnd="16dp" + android:foreground="?android:attr/selectableItemBackground"> + + <RadioButton + android:id="@+id/row_radio" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:minWidth="0dp" + android:padding="0dp" + android:focusable="false" + android:clickable="false" + android:button="@null"/> + + <ImageView + android:id="@+id/row_icon" + android:layout_width="24dp" + android:layout_height="24dp" + android:layout_marginStart="@dimen/top_bar_no_icon_alignment_margin_start" + android:layout_marginEnd="8dp" + android:contentDescription="@null" /> + + <TextView + android:id="@+id/row_label" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:textAppearance="?android:attr/textAppearanceListItem" /> +</LinearLayout> diff --git a/mobile/android/fenix/app/src/main/res/values/preference_keys.xml b/mobile/android/fenix/app/src/main/res/values/preference_keys.xml @@ -203,6 +203,8 @@ <string name="pref_key_customization_category_toolbar" translatable="false">pref_key_customization_category_toolbar</string> <string name="pref_key_customization_category_toolbar_layout" translatable="false">pref_key_customization_category_toolbar_layout</string> <string name="pref_key_customization_category_app_icon" translatable="false">pref_key_customization_category_app_icon</string> + <string name="pref_key_customization_category_toolbar_shortcut" translatable="false">pref_key_customization_category_toolbar_shortcut</string> + <string name="pref_key_toolbar_shortcut" translatable="false">pref_key_toolbar_shortcut</string> <!-- HTTPS Only Settings --> <string name="pref_key_https_only_settings" translatable="false">pref_key_https_only_settings</string> @@ -437,8 +439,7 @@ <string name="pref_key_enable_composable_toolbar" translatable="false">pref_key_enable_composable_toolbar</string>" <string name="pref_key_enable_toolbar_redesign" translatable="false">pref_key_enable_toolbar_redesign</string>" <string name="pref_key_enable_address_sync" translatable="false">pref_key_enable_address_sync</string>" - <string name="pref_key_enable_simple_toolbar_customization">pref_key_enable_simple_toolbar_customization</string> - <string name="pref_key_enable_expanded_toolbar_customization">pref_key_enable_expanded_toolbar_customization</string> + <string name="pref_key_enable_toolbar_customization">pref_key_enable_toolbar_customization</string> <string name="pref_key_enable_lna_blocking_enabled" translatable="false">pref_key_enable_lna_blocking_enabled</string> <string name="pref_key_enable_isolated_process" translatable="false">pref_key_enable_isolated_process</string> diff --git a/mobile/android/fenix/app/src/main/res/values/static_strings.xml b/mobile/android/fenix/app/src/main/res/values/static_strings.xml @@ -90,11 +90,15 @@ <!-- Label for enabling the redesigned toolbar options --> <string name="preferences_debug_settings_toolbar_redesign" translatable="false">Enable Redesigned Toolbar Options</string> <!-- Label for enabling the redesigned simple toolbar --> - <string name="preferences_debug_settings_simple_toolbar_customization">Enable simple toolbar customization</string> + <string name="preferences_debug_settings_simple_toolbar_customization" tools:ignore="UnusedResources" moz:removedIn="145">Enable simple toolbar customization</string> <!-- Label for enabling the redesigned expanded toolbar --> - <string name="preferences_debug_settings_expanded_toolbar_customization">Enable expanded toolbar customization</string> + <string name="preferences_debug_settings_expanded_toolbar_customization" tools:ignore="UnusedResources" moz:removedIn="145">Enable expanded toolbar customization</string> + <!-- Label for enabling the redesigned toolbar --> + <string name="preferences_debug_settings_toolbar_customization">Enable Toolbar Customization</string> <!-- Label for a longer description of the redesigned toolbar depending on the composable toolbar feature --> <string name="preferences_debug_settings_toolbar_redesign_summary" translatable="false">This needs the Composable Toolbar feature enabled</string> + <!-- Label for a longer description of the redesigned toolbar depending on the redesigned toolbar options feature --> + <string name="preferences_debug_settings_toolbar_customization_summary" translatable="false">This needs the Redesigned Toolbar Options feature enabled</string> <!-- Label for toggling Remote Crash Pull --> <string name="preferences_crash_pull_never_show_again" translatable="false">Never show Crash Pull</string> <!-- Label for enabling the Debug Drawer --> diff --git a/mobile/android/fenix/app/src/main/res/values/strings.xml b/mobile/android/fenix/app/src/main/res/values/strings.xml @@ -731,6 +731,10 @@ <!-- Preference for showing the tab strip --> <string name="preferences_tab_strip">Tab bar display</string> <!-- Preference for gestures based actions --> + <string name="preferences_toolbar_shortcut">Toolbar shortcut</string> + <!-- Preference for gestures based actions --> + <string name="preferences_toolbar_select_shortcut">Select a shortcut</string> + <!-- Preference for gestures based actions --> <string name="preferences_gestures">Gestures</string> <!-- Preference for settings related to visual options --> <string name="preferences_customize">Customize</string> diff --git a/mobile/android/fenix/app/src/main/res/xml/customization_preferences.xml b/mobile/android/fenix/app/src/main/res/xml/customization_preferences.xml @@ -82,6 +82,19 @@ app:trueOptionTitle="@string/preference_expanded_toolbar" /> </androidx.preference.PreferenceCategory> + <!-- Toolbar shortcut picker (simple layout only) --> + <androidx.preference.PreferenceCategory + android:layout="@layout/preference_cat_style" + android:title="@string/preferences_toolbar_shortcut" + android:key="@string/pref_key_customization_category_toolbar_shortcut" + app:iconSpaceReserved="false"> + + <!-- Custom preference shows the selected option on top --> + <org.mozilla.fenix.settings.ToolbarShortcutPreference + android:key="@string/pref_key_toolbar_shortcut" + android:layout="@layout/preference_toolbar_shortcut"/> + </androidx.preference.PreferenceCategory> + <androidx.preference.PreferenceCategory android:layout="@layout/preference_cat_style" android:title="@string/preferences_gestures" diff --git a/mobile/android/fenix/app/src/main/res/xml/secret_settings_preferences.xml b/mobile/android/fenix/app/src/main/res/xml/secret_settings_preferences.xml @@ -65,12 +65,8 @@ android:title="@string/preferences_debug_settings_toolbar_redesign" app:iconSpaceReserved="false" /> <SwitchPreference - android:key="@string/pref_key_enable_simple_toolbar_customization" - android:title="@string/preferences_debug_settings_simple_toolbar_customization" - app:iconSpaceReserved="false" /> - <SwitchPreference - android:key="@string/pref_key_enable_expanded_toolbar_customization" - android:title="@string/preferences_debug_settings_expanded_toolbar_customization" + android:key="@string/pref_key_enable_toolbar_customization" + android:title="@string/preferences_debug_settings_toolbar_customization" app:iconSpaceReserved="false" /> <SwitchPreference android:defaultValue="false" diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMiddlewareTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMiddlewareTest.kt @@ -164,6 +164,7 @@ import org.mozilla.fenix.ext.directionsEq import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.settings import org.mozilla.fenix.helpers.FenixGleanTestRule +import org.mozilla.fenix.settings.ToolbarShortcutPreference import org.mozilla.fenix.tabstray.Page import org.mozilla.fenix.utils.Settings import org.robolectric.Shadows.shadowOf @@ -2760,6 +2761,22 @@ class BrowserToolbarMiddlewareTest { assertEquals(expectedMenuButton(), updatedMenuButton) } + @Test + fun `mapShortcutToAction maps keys to actions and falls back to NewTab`() { + assertEquals( + ToolbarAction.NewTab, + BrowserToolbarMiddleware.mapShortcutToAction(ToolbarShortcutPreference.Keys.NEW_TAB), + ) + assertEquals( + ToolbarAction.Share, + BrowserToolbarMiddleware.mapShortcutToAction(ToolbarShortcutPreference.Keys.SHARE), + ) + assertEquals( + ToolbarAction.NewTab, + BrowserToolbarMiddleware.mapShortcutToAction("does_not_exist"), + ) + } + private fun assertEqualsTabCounterButton(expected: TabCounterAction, actual: TabCounterAction) { assertEquals(expected.count, actual.count) assertEquals(expected.contentDescription, actual.contentDescription)