Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 81eb75b

Browse files
bluemarvinkeianhzo
andauthored
Add long press reload that bypasses cache (#2922)
* Add long press reload that bypasses cache * Prevent extra click after long press on Android O and greater * Revert "Prevent extra click after long press on Android O and greater" This reverts commit 243217e. * Check if the uibutton has a long click listener before applying the fix Co-authored-by: Manuel Martin <[email protected]>
1 parent dbb8ed3 commit 81eb75b

File tree

8 files changed

+65
-5
lines changed

8 files changed

+65
-5
lines changed

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
8282
public final static boolean WHATS_NEW_DISPLAYED = false;
8383
public final static long FXA_LAST_SYNC_NEVER = 0;
8484
public final static boolean RESTORE_TABS_ENABLED = true;
85+
public final static boolean BYPASS_CACHE_ON_RELOAD = false;
8586

8687
// Enable telemetry by default (opt-out).
8788
public final static boolean CRASH_REPORTING_DEFAULT = false;
@@ -652,5 +653,14 @@ public boolean isRestoreTabsEnabled() {
652653
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_restore_tabs), RESTORE_TABS_ENABLED);
653654
}
654655

656+
public void setBypassCacheOnReload(boolean isEnabled) {
657+
SharedPreferences.Editor editor = mPrefs.edit();
658+
editor.putBoolean(mContext.getString(R.string.settings_key_bypass_cache_on_reload),isEnabled);
659+
editor.commit();
660+
}
661+
662+
public boolean isBypassCacheOnReloadEnabled() {
663+
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_bypass_cache_on_reload), BYPASS_CACHE_ON_RELOAD);
664+
}
655665
}
656666

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,9 @@ public void setActive(boolean aActive) {
669669
}
670670
}
671671

672-
public void reload() {
672+
public void reload(final int flags) {
673673
if (mState.mSession != null) {
674-
mState.mSession.reload();
674+
mState.mSession.reload(flags);
675675
}
676676
}
677677

app/src/common/shared/org/mozilla/vrbrowser/ui/views/UIButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public UIButton(Context context, AttributeSet attrs, int defStyleAttr) {
9090
setOnTouchListener((v, event) -> {
9191
if (event.getAction() == MotionEvent.ACTION_UP) {
9292
long time = event.getEventTime() - event.getDownTime();
93-
if (time > ViewConfiguration.getLongPressTimeout()) {
93+
if (!v.isLongClickable() && time > ViewConfiguration.getLongPressTimeout()) {
9494
performClick();
9595
}
9696
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,29 @@ private void updateUI() {
187187
if (mViewModel.getIsLoading().getValue().get()) {
188188
getSession().stop();
189189
} else {
190-
getSession().reload();
190+
int flags = SettingsStore.getInstance(mAppContext).isBypassCacheOnReloadEnabled() ? GeckoSession.LOAD_FLAGS_BYPASS_CACHE : GeckoSession.LOAD_FLAGS_NONE;
191+
getSession().reload(flags);
191192
}
192193
if (mAudio != null) {
193194
mAudio.playSound(AudioEngine.Sound.CLICK);
194195
}
195196
mNavigationListeners.forEach(NavigationListener::onReload);
196197
});
197198

199+
mBinding.navigationBarNavigation.reloadButton.setOnLongClickListener(v -> {
200+
v.requestFocusFromTouch();
201+
if (mViewModel.getIsLoading().getValue().get()) {
202+
getSession().stop();
203+
} else {
204+
getSession().reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
205+
}
206+
if (mAudio != null) {
207+
mAudio.playSound(AudioEngine.Sound.CLICK);
208+
}
209+
mNavigationListeners.forEach(NavigationListener::onReload);
210+
return true;
211+
});
212+
198213
mBinding.navigationBarNavigation.homeButton.setOnClickListener(v -> {
199214
v.requestFocusFromTouch();
200215
getSession().loadUri(getSession().getHomeUri());

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DeveloperOptionsView.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ protected void updateUI() {
6666
mBinding.hardwareAccelerationSwitch.setOnCheckedChangeListener(mUIHardwareAccelerationListener);
6767
setUIHardwareAcceleration(SettingsStore.getInstance(getContext()).isUIHardwareAccelerationEnabled(), false);
6868

69+
mBinding.bypassCacheOnReloadSwitch.setOnCheckedChangeListener(mBypassCacheOnReloadListener);
70+
setBypassCacheOnReload(SettingsStore.getInstance(getContext()).isBypassCacheOnReloadEnabled(), false);
71+
6972
if (BuildConfig.DEBUG) {
7073
mBinding.debugLoggingSwitch.setVisibility(View.GONE);
7174
} else {
@@ -101,6 +104,10 @@ protected void updateUI() {
101104
setUIHardwareAcceleration(value, doApply);
102105
};
103106

107+
private SwitchSetting.OnCheckedChangeListener mBypassCacheOnReloadListener = (compundButton, value, doApply) -> {
108+
setBypassCacheOnReload(value, doApply);
109+
};
110+
104111
private SwitchSetting.OnCheckedChangeListener mServoListener = (compoundButton, b, doApply) -> {
105112
setServo(b, true);
106113
};
@@ -133,6 +140,10 @@ protected void updateUI() {
133140
restart = true;
134141
}
135142

143+
if (mBinding.bypassCacheOnReloadSwitch.isChecked() != SettingsStore.BYPASS_CACHE_ON_RELOAD) {
144+
setBypassCacheOnReload(SettingsStore.BYPASS_CACHE_ON_RELOAD, true);
145+
}
146+
136147
if (restart) {
137148
showRestartDialog();
138149
}
@@ -194,6 +205,16 @@ private void setDebugLogging(boolean value, boolean doApply) {
194205
}
195206
}
196207

208+
private void setBypassCacheOnReload(boolean value, boolean doApply) {
209+
mBinding.bypassCacheOnReloadSwitch.setOnCheckedChangeListener(null);
210+
mBinding.bypassCacheOnReloadSwitch.setValue(value, false);
211+
mBinding.bypassCacheOnReloadSwitch.setOnCheckedChangeListener(mBypassCacheOnReloadListener);
212+
213+
if (doApply) {
214+
SettingsStore.getInstance(getContext()).setBypassCacheOnReload(value);
215+
}
216+
}
217+
197218
private void setServo(boolean value, boolean doApply) {
198219
mBinding.servoSwitch.setOnCheckedChangeListener(null);
199220
mBinding.servoSwitch.setValue(value, false);

app/src/main/res/layout/options_developer.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
android:layout_height="wrap_content"
6868
app:description="@string/hardware_acceleration_switch" />
6969

70+
<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
71+
android:id="@+id/bypass_cache_on_reload_switch"
72+
android:layout_width="match_parent"
73+
android:layout_height="wrap_content"
74+
app:description="@string/bypass_cache_on_reload_switch" />
75+
7076
<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
7177
android:id="@+id/servo_switch"
7278
android:layout_width="match_parent"

app/src/main/res/values/non_L10n.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<string name="settings_key_ui_hardware_acceleration" translatable="false">settings_key_ui_hardware_acceleration_v3</string>
5050
<string name="settings_key_fxa_last_sync" translatable="false">settings_key_fxa_last_sync</string>
5151
<string name="settings_key_restore_tabs" translatable="false">settings_key_restore_tabs</string>
52+
<string name="settings_key_bypass_cache_on_reload" translatable="false">settings_key_bypass_cache_on_reload</string>
5253
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
5354
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
5455
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>

app/src/main/res/values/strings.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,16 @@
344344
<!-- This string labels an On/Off switch in the developer options dialog and is used to toggle
345345
UI render mode. If enables it uses hardware acceleration which should be faster but it may be more unstable.
346346
If disabled it uses software rendering which is stable but not as performant as hardware acceleration
347-
-->
347+
-->
348348
<string name="hardware_acceleration_switch">Enable UI Hardware Acceleration</string>
349349

350+
<!-- This string labels an On/Off switch in the developer options dialog and is used to toggle
351+
the behavior of the navigation bar reload button. When enabled, the reloads will bypass
352+
the browser cache. This feature is used by web developers when they want to always view
353+
the most recent version of a web site.
354+
-->
355+
<string name="bypass_cache_on_reload_switch">Enable Cache Bypass On Reload</string>
356+
350357
<!-- The string labels an On/Off switch in the developer options dialog and is used to toggle enabling Servo. -->
351358
<string name="developer_options_servo">Enable Servo</string>
352359

0 commit comments

Comments
 (0)