Skip to content

Commit

Permalink
Add long press reload that bypasses cache (#2922)
Browse files Browse the repository at this point in the history
* 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 <imanol.martin@gmail.com>
  • Loading branch information
bluemarvin and keianhzo committed Mar 12, 2020
1 parent dbb8ed3 commit 81eb75b
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 5 deletions.
Expand Up @@ -82,6 +82,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean WHATS_NEW_DISPLAYED = false;
public final static long FXA_LAST_SYNC_NEVER = 0;
public final static boolean RESTORE_TABS_ENABLED = true;
public final static boolean BYPASS_CACHE_ON_RELOAD = false;

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

public void setBypassCacheOnReload(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_bypass_cache_on_reload),isEnabled);
editor.commit();
}

public boolean isBypassCacheOnReloadEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_bypass_cache_on_reload), BYPASS_CACHE_ON_RELOAD);
}
}

Expand Up @@ -669,9 +669,9 @@ public void setActive(boolean aActive) {
}
}

public void reload() {
public void reload(final int flags) {
if (mState.mSession != null) {
mState.mSession.reload();
mState.mSession.reload(flags);
}
}

Expand Down
Expand Up @@ -90,7 +90,7 @@ public UIButton(Context context, AttributeSet attrs, int defStyleAttr) {
setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) {
long time = event.getEventTime() - event.getDownTime();
if (time > ViewConfiguration.getLongPressTimeout()) {
if (!v.isLongClickable() && time > ViewConfiguration.getLongPressTimeout()) {
performClick();
}
}
Expand Down
Expand Up @@ -187,14 +187,29 @@ private void updateUI() {
if (mViewModel.getIsLoading().getValue().get()) {
getSession().stop();
} else {
getSession().reload();
int flags = SettingsStore.getInstance(mAppContext).isBypassCacheOnReloadEnabled() ? GeckoSession.LOAD_FLAGS_BYPASS_CACHE : GeckoSession.LOAD_FLAGS_NONE;
getSession().reload(flags);
}
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
mNavigationListeners.forEach(NavigationListener::onReload);
});

mBinding.navigationBarNavigation.reloadButton.setOnLongClickListener(v -> {
v.requestFocusFromTouch();
if (mViewModel.getIsLoading().getValue().get()) {
getSession().stop();
} else {
getSession().reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
}
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
mNavigationListeners.forEach(NavigationListener::onReload);
return true;
});

mBinding.navigationBarNavigation.homeButton.setOnClickListener(v -> {
v.requestFocusFromTouch();
getSession().loadUri(getSession().getHomeUri());
Expand Down
Expand Up @@ -66,6 +66,9 @@ protected void updateUI() {
mBinding.hardwareAccelerationSwitch.setOnCheckedChangeListener(mUIHardwareAccelerationListener);
setUIHardwareAcceleration(SettingsStore.getInstance(getContext()).isUIHardwareAccelerationEnabled(), false);

mBinding.bypassCacheOnReloadSwitch.setOnCheckedChangeListener(mBypassCacheOnReloadListener);
setBypassCacheOnReload(SettingsStore.getInstance(getContext()).isBypassCacheOnReloadEnabled(), false);

if (BuildConfig.DEBUG) {
mBinding.debugLoggingSwitch.setVisibility(View.GONE);
} else {
Expand Down Expand Up @@ -101,6 +104,10 @@ protected void updateUI() {
setUIHardwareAcceleration(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mBypassCacheOnReloadListener = (compundButton, value, doApply) -> {
setBypassCacheOnReload(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mServoListener = (compoundButton, b, doApply) -> {
setServo(b, true);
};
Expand Down Expand Up @@ -133,6 +140,10 @@ protected void updateUI() {
restart = true;
}

if (mBinding.bypassCacheOnReloadSwitch.isChecked() != SettingsStore.BYPASS_CACHE_ON_RELOAD) {
setBypassCacheOnReload(SettingsStore.BYPASS_CACHE_ON_RELOAD, true);
}

if (restart) {
showRestartDialog();
}
Expand Down Expand Up @@ -194,6 +205,16 @@ private void setDebugLogging(boolean value, boolean doApply) {
}
}

private void setBypassCacheOnReload(boolean value, boolean doApply) {
mBinding.bypassCacheOnReloadSwitch.setOnCheckedChangeListener(null);
mBinding.bypassCacheOnReloadSwitch.setValue(value, false);
mBinding.bypassCacheOnReloadSwitch.setOnCheckedChangeListener(mBypassCacheOnReloadListener);

if (doApply) {
SettingsStore.getInstance(getContext()).setBypassCacheOnReload(value);
}
}

private void setServo(boolean value, boolean doApply) {
mBinding.servoSwitch.setOnCheckedChangeListener(null);
mBinding.servoSwitch.setValue(value, false);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_developer.xml
Expand Up @@ -67,6 +67,12 @@
android:layout_height="wrap_content"
app:description="@string/hardware_acceleration_switch" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/bypass_cache_on_reload_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/bypass_cache_on_reload_switch" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/servo_switch"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Expand Up @@ -49,6 +49,7 @@
<string name="settings_key_ui_hardware_acceleration" translatable="false">settings_key_ui_hardware_acceleration_v3</string>
<string name="settings_key_fxa_last_sync" translatable="false">settings_key_fxa_last_sync</string>
<string name="settings_key_restore_tabs" translatable="false">settings_key_restore_tabs</string>
<string name="settings_key_bypass_cache_on_reload" translatable="false">settings_key_bypass_cache_on_reload</string>
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
<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>
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/values/strings.xml
Expand Up @@ -344,9 +344,16 @@
<!-- This string labels an On/Off switch in the developer options dialog and is used to toggle
UI render mode. If enables it uses hardware acceleration which should be faster but it may be more unstable.
If disabled it uses software rendering which is stable but not as performant as hardware acceleration
-->
-->
<string name="hardware_acceleration_switch">Enable UI Hardware Acceleration</string>

<!-- This string labels an On/Off switch in the developer options dialog and is used to toggle
the behavior of the navigation bar reload button. When enabled, the reloads will bypass
the browser cache. This feature is used by web developers when they want to always view
the most recent version of a web site.
-->
<string name="bypass_cache_on_reload_switch">Enable Cache Bypass On Reload</string>

<!-- The string labels an On/Off switch in the developer options dialog and is used to toggle enabling Servo. -->
<string name="developer_options_servo">Enable Servo</string>

Expand Down

0 comments on commit 81eb75b

Please sign in to comment.