Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1875465 - Part 4: Add secret setting and remove toolbar customiza…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
rahulsainani committed Feb 19, 2024
1 parent 044908a commit a4ba981
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
}

private fun initTabStrip() {
if (!resources.getBoolean(R.bool.tablet)) {
if (!requireContext().settings().isTabletAndTabStripEnabled) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ class HomeFragment : Fragment() {
}

private fun initTabStrip() {
if (!resources.getBoolean(R.bool.tablet)) {
if (!requireContext().settings().isTabletAndTabStripEnabled) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) ->
Expand Down
15 changes: 13 additions & 2 deletions fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions fenix/app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions fenix/app/src/main/res/values/static_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion fenix/app/src/main/res/xml/customization_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions fenix/app/src/main/res/xml/secret_settings_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a4ba981

Please sign in to comment.