For #10240 - New preferences to control gesture based features

Three new settings and one for which this patch just pre-lands the strings.
The behavior for the "Swipe toolbar up to open tabs" is to be added as part of
a later ticket.
pull/90/head
Mugurell 4 years ago committed by ekager
parent f7217021da
commit d8d896c500

@ -657,9 +657,9 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
}
}
view.swipeRefresh.isEnabled = FeatureFlags.pullToRefreshEnabled
@Suppress("ConstantConditionIf")
if (FeatureFlags.pullToRefreshEnabled) {
view.swipeRefresh.isEnabled =
FeatureFlags.pullToRefreshEnabled && context.settings().isPullToRefreshEnabledInBrowser
if (view.swipeRefresh.isEnabled) {
val primaryTextColor =
ThemeManager.resolveAttribute(R.attr.primaryText, context)
view.swipeRefresh.setColorSchemeColors(primaryTextColor)

@ -72,15 +72,17 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
val components = context.components
return super.initializeUI(view)?.also {
gestureLayout.addGestureListener(
ToolbarGestureHandler(
activity = requireActivity(),
contentLayout = browserLayout,
tabPreview = tabPreview,
toolbarLayout = browserToolbarView.view,
sessionManager = components.core.sessionManager
if (context.settings().isSwipeToolbarToSwitchTabsEnabled) {
gestureLayout.addGestureListener(
ToolbarGestureHandler(
activity = requireActivity(),
contentLayout = browserLayout,
tabPreview = tabPreview,
toolbarLayout = browserToolbarView.view,
sessionManager = components.core.sessionManager
)
)
)
}
val readerModeAction =
BrowserToolbar.ToggleButton(

@ -209,7 +209,8 @@ class BrowserToolbarView(
when (settings.toolbarPosition) {
ToolbarPosition.BOTTOM -> {
(view.layoutParams as CoordinatorLayout.LayoutParams).apply {
(behavior as BrowserToolbarBottomBehavior).forceExpand(view)
// behavior can be null if the "Scroll to hide toolbar" setting is toggled off.
(behavior as? BrowserToolbarBottomBehavior)?.forceExpand(view)
}
}
ToolbarPosition.TOP -> {
@ -220,7 +221,8 @@ class BrowserToolbarView(
/**
* Dynamically sets scroll flags for the toolbar when the user does not have a screen reader enabled
* Note that the bottom toolbar has a feature flag for being dynamic, so it may not get flags set.
* Note that the toolbar will have the flags set and be able to be hidden
* only if the user didn't disabled this behavior in app's settings.
*/
fun setScrollFlags(shouldDisableScroll: Boolean = false) {
when (settings.toolbarPosition) {
@ -231,7 +233,10 @@ class BrowserToolbarView(
}
ToolbarPosition.TOP -> {
view.updateLayoutParams<AppBarLayout.LayoutParams> {
scrollFlags = if (settings.shouldUseFixedTopToolbar || shouldDisableScroll) {
scrollFlags =
if (settings.shouldUseFixedTopToolbar ||
!settings.isDynamicToolbarEnabled ||
shouldDisableScroll) {
// Force expand the toolbar so the user is not stuck with a hidden toolbar
expand()
0

@ -51,6 +51,7 @@ class CustomizationFragment : PreferenceFragmentCompat() {
setupRadioGroups()
setupToolbarCategory()
setupHomeCategory()
setupGesturesCategory()
}
private fun setupRadioGroups() {
@ -144,4 +145,20 @@ class CustomizationFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}
private fun setupGesturesCategory() {
requirePreference<SwitchPreference>(R.string.pref_key_website_pull_to_refresh).apply {
isVisible = FeatureFlags.pullToRefreshEnabled
isChecked = context.settings().isPullToRefreshEnabledInBrowser
onPreferenceChangeListener = SharedPreferenceUpdater()
}
requirePreference<SwitchPreference>(R.string.pref_key_dynamic_toolbar).apply {
isChecked = context.settings().isDynamicToolbarEnabled
onPreferenceChangeListener = SharedPreferenceUpdater()
}
requirePreference<SwitchPreference>(R.string.pref_key_swipe_toolbar_switch_tabs).apply {
isChecked = context.settings().isSwipeToolbarToSwitchTabsEnabled
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}
}

@ -888,4 +888,19 @@ class Settings(private val appContext: Context) : PreferencesHolder {
SavedLoginsSortingStrategyMenu.Item.LastUsedSort.strategyString
}
}
var isPullToRefreshEnabledInBrowser by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_website_pull_to_refresh),
default = true
)
var isDynamicToolbarEnabled by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_dynamic_toolbar),
default = true
)
var isSwipeToolbarToSwitchTabsEnabled by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_swipe_toolbar_switch_tabs),
default = true
)
}

@ -125,6 +125,12 @@
<!-- Customization Settings -->
<string name="pref_home_category" translatable="false">pref_home_category</string>
<!-- Customization Settings -->
<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>
<!-- Tracking Protection Settings -->
<string name="pref_key_etp_learn_more" translatable="false">pref_key_etp_learn_more</string>
<string name="pref_key_tracking_protection_settings" translatable="false">pref_key_tracking_protection_settings</string>

@ -284,6 +284,8 @@
<string name="preferences_theme">Theme</string>
<!-- Preference for customizing the home screen -->
<string name="preferences_home">Home</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>
<!-- Preference description for banner about signing in -->
@ -453,6 +455,16 @@
<!-- Preference for using following device theme -->
<string name="preference_follow_device_theme">Follow device theme</string>
<!-- Gestures Preferences-->
<!-- Preferences for using pull to refresh in a webpage -->
<string name="preference_gestures_website_pull_to_refresh">Pull to refresh</string>
<!-- Preference for using the dynamic toolbar -->
<string name="preference_gestures_dynamic_toolbar">Scroll to hide toolbar</string>
<!-- Preference for switching tabs by swiping horizontally on the toolbar -->
<string name="preference_gestures_swipe_toolbar_switch_tabs">Swipe toolbar sideways to switch tabs</string>
<!-- Preference for showing the opened tabs by swiping up on the toolbar-->
<string name="preference_gestures_swipe_toolbar_show_tabs">Swipe toolbar up to open tabs</string>
<!-- Library -->
<!-- Option in Library to open Sessions page -->
<string name="library_sessions">Sessions</string>

@ -56,4 +56,24 @@
android:key="@string/pref_key_enable_top_frecent_sites"
android:title="@string/top_sites_toggle_top_frecent_sites" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_gestures"
app:allowDividerAbove="false"
app:iconSpaceReserved="false">
<androidx.preference.SwitchPreference
android:key="@string/pref_key_website_pull_to_refresh"
android:title="@string/preference_gestures_website_pull_to_refresh" />
<androidx.preference.SwitchPreference
android:key="@string/pref_key_dynamic_toolbar"
android:title="@string/preference_gestures_dynamic_toolbar" />
<androidx.preference.SwitchPreference
android:key="@string/pref_key_swipe_toolbar_switch_tabs"
android:title="@string/preference_gestures_swipe_toolbar_switch_tabs" />
<androidx.preference.SwitchPreference
android:key="@string/pref_key_swipe_toolbar_show_tabs"
android:title="@string/preference_gestures_swipe_toolbar_show_tabs"
app:isPreferenceVisible="false"/>
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>

Loading…
Cancel
Save