2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/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.
This commit is contained in:
Mugurell 2020-09-03 09:36:06 +03:00 committed by ekager
parent 997899cc06
commit 089a60c195
8 changed files with 91 additions and 14 deletions

View File

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

View File

@ -72,6 +72,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
val components = context.components val components = context.components
return super.initializeUI(view)?.also { return super.initializeUI(view)?.also {
if (context.settings().isSwipeToolbarToSwitchTabsEnabled) {
gestureLayout.addGestureListener( gestureLayout.addGestureListener(
ToolbarGestureHandler( ToolbarGestureHandler(
activity = requireActivity(), activity = requireActivity(),
@ -81,6 +82,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
sessionManager = components.core.sessionManager sessionManager = components.core.sessionManager
) )
) )
}
val readerModeAction = val readerModeAction =
BrowserToolbar.ToggleButton( BrowserToolbar.ToggleButton(

View File

@ -209,7 +209,8 @@ class BrowserToolbarView(
when (settings.toolbarPosition) { when (settings.toolbarPosition) {
ToolbarPosition.BOTTOM -> { ToolbarPosition.BOTTOM -> {
(view.layoutParams as CoordinatorLayout.LayoutParams).apply { (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 -> { 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 * 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) { fun setScrollFlags(shouldDisableScroll: Boolean = false) {
when (settings.toolbarPosition) { when (settings.toolbarPosition) {
@ -231,7 +233,10 @@ class BrowserToolbarView(
} }
ToolbarPosition.TOP -> { ToolbarPosition.TOP -> {
view.updateLayoutParams<AppBarLayout.LayoutParams> { 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 // Force expand the toolbar so the user is not stuck with a hidden toolbar
expand() expand()
0 0

View File

@ -51,6 +51,7 @@ class CustomizationFragment : PreferenceFragmentCompat() {
setupRadioGroups() setupRadioGroups()
setupToolbarCategory() setupToolbarCategory()
setupHomeCategory() setupHomeCategory()
setupGesturesCategory()
} }
private fun setupRadioGroups() { private fun setupRadioGroups() {
@ -144,4 +145,20 @@ class CustomizationFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater() 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()
}
}
} }

View File

@ -888,4 +888,19 @@ class Settings(private val appContext: Context) : PreferencesHolder {
SavedLoginsSortingStrategyMenu.Item.LastUsedSort.strategyString 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
)
} }

View File

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

View File

@ -284,6 +284,8 @@
<string name="preferences_theme">Theme</string> <string name="preferences_theme">Theme</string>
<!-- Preference for customizing the home screen --> <!-- Preference for customizing the home screen -->
<string name="preferences_home">Home</string> <string name="preferences_home">Home</string>
<!-- Preference for gestures based actions -->
<string name="preferences_gestures">Gestures</string>
<!-- Preference for settings related to visual options --> <!-- Preference for settings related to visual options -->
<string name="preferences_customize">Customize</string> <string name="preferences_customize">Customize</string>
<!-- Preference description for banner about signing in --> <!-- Preference description for banner about signing in -->
@ -453,6 +455,16 @@
<!-- Preference for using following device theme --> <!-- Preference for using following device theme -->
<string name="preference_follow_device_theme">Follow device theme</string> <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 --> <!-- Library -->
<!-- Option in Library to open Sessions page --> <!-- Option in Library to open Sessions page -->
<string name="library_sessions">Sessions</string> <string name="library_sessions">Sessions</string>

View File

@ -56,4 +56,24 @@
android:key="@string/pref_key_enable_top_frecent_sites" android:key="@string/pref_key_enable_top_frecent_sites"
android:title="@string/top_sites_toggle_top_frecent_sites" /> android:title="@string/top_sites_toggle_top_frecent_sites" />
</androidx.preference.PreferenceCategory> </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> </androidx.preference.PreferenceScreen>