From b488103c43fdd5c7dfa059cc1c6e33c1f0b813dd Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 26 May 2022 11:45:14 +0200 Subject: [PATCH] fix behavior of system-back-button for webxdc for webxdc, the system-back-button should do the same as the back-button in the title bar - just close the webxdc. without this commit, it loads the previous page, which is often unexpected - eg. many games use reload() for simplicity, so you would have press one time 'back' for each round :) even if there may be situations where this may be useful, we do not want to encourage webxdc to rely on the system-back-button - eg. desktop or ios currently just do not have this button. technically, this pr changes the default - so, for all classes derived from WebViewActivity, the system-back-button will now behave as the title-bar-back-button. for the local-help, this behavior is changed explictly - i think, for HTML-mails, the 'just close' approach is also better. --- .../thoughtcrime/securesms/ConnectivityActivity.java | 7 ------- src/org/thoughtcrime/securesms/LocalHelpActivity.java | 9 +++++++++ src/org/thoughtcrime/securesms/WebViewActivity.java | 10 ++-------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConnectivityActivity.java b/src/org/thoughtcrime/securesms/ConnectivityActivity.java index ac06a1dc7..81207a98f 100644 --- a/src/org/thoughtcrime/securesms/ConnectivityActivity.java +++ b/src/org/thoughtcrime/securesms/ConnectivityActivity.java @@ -43,11 +43,4 @@ public class ConnectivityActivity extends WebViewActivity implements DcEventCent public void handleEvent(@NonNull DcEvent event) { refresh(); } - - @Override - public void onBackPressed() { - // If we did not override this function, the back button in the connectivity view would sometimes - // not work, probably because webView.canGoBack() in WebViewActivity.onBackPressed() wrongly returns true - finish(); - } } diff --git a/src/org/thoughtcrime/securesms/LocalHelpActivity.java b/src/org/thoughtcrime/securesms/LocalHelpActivity.java index 6e01f5fea..982e7f736 100644 --- a/src/org/thoughtcrime/securesms/LocalHelpActivity.java +++ b/src/org/thoughtcrime/securesms/LocalHelpActivity.java @@ -69,6 +69,15 @@ public class LocalHelpActivity extends WebViewActivity return false; } + @Override + public void onBackPressed() { + if (webView.canGoBack()) { + webView.goBack(); + } else { + super.onBackPressed(); + } + } + private boolean assetExists(String fileName) { // test using AssetManager.open(); // AssetManager.list() is unreliable eg. on my Android 7 Moto G diff --git a/src/org/thoughtcrime/securesms/WebViewActivity.java b/src/org/thoughtcrime/securesms/WebViewActivity.java index a86c92d87..272b681ea 100644 --- a/src/org/thoughtcrime/securesms/WebViewActivity.java +++ b/src/org/thoughtcrime/securesms/WebViewActivity.java @@ -262,14 +262,8 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity return false; } - @Override - public void onBackPressed() { - if (webView.canGoBack()) { - webView.goBack(); - } else { - super.onBackPressed(); - } - } + // onBackPressed() can be overwritten by derived classes as needed. + // the default behavior (close the activity) is just fine eg. for Webxdc, Connectivity, HTML-mails public static void openUrlInBrowser(Context context, String url) { try {