From 53cf20d77aaaf19aca1eb84f95a66c081234ab9c Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 9 Apr 2022 18:50:30 +0530 Subject: [PATCH 1/2] added warning on accidental exit --- .../fragments/AbsWebTableFragmentStub.java | 9 +++++++++ .../tables/activities/AbsBaseActivity.java | 3 +++ .../tables/activities/AbsBaseWebActivity.java | 3 ++- .../tables/activities/MainActivity.java | 18 +++++++++++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/broken_tests/src/org/opendatakit/tables/fragments/AbsWebTableFragmentStub.java b/broken_tests/src/org/opendatakit/tables/fragments/AbsWebTableFragmentStub.java index c0adb11c..4f8e2f85 100644 --- a/broken_tests/src/org/opendatakit/tables/fragments/AbsWebTableFragmentStub.java +++ b/broken_tests/src/org/opendatakit/tables/fragments/AbsWebTableFragmentStub.java @@ -65,4 +65,13 @@ public void databaseUnavailable() { // we assume the service connection is mocked and does not require any of these calls } + @Override + public void onBackPressed() { + if (ODKWebView.canGoBack()) { + ODKWebView.goBack(); + } else { + super.onBackPressed(); + } + } + } diff --git a/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseActivity.java b/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseActivity.java index 96d21ff7..6612fffd 100644 --- a/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseActivity.java +++ b/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseActivity.java @@ -17,8 +17,11 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import android.app.Activity; +import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.ComponentName; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; diff --git a/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseWebActivity.java b/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseWebActivity.java index ff077683..2c62d8b5 100644 --- a/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseWebActivity.java +++ b/tables_app/src/main/java/org/opendatakit/tables/activities/AbsBaseWebActivity.java @@ -1,5 +1,6 @@ package org.opendatakit.tables.activities; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; @@ -83,7 +84,7 @@ public abstract class AbsBaseWebActivity extends AbsTableActivity implements IOd // no need to preserve private PropertyManager mPropertyManager; - public abstract String getInstanceId(); + public abstract String getInstanceId(); /** * Gets the active webkit view diff --git a/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java b/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java index 48ead2da..10686e27 100644 --- a/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java +++ b/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java @@ -21,8 +21,10 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager.BackStackEntry; import androidx.fragment.app.FragmentTransaction; +import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.ComponentName; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.Menu; @@ -299,7 +301,21 @@ public void initializationCompleted() { @Override public void onBackPressed() { - popBackStack(); + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle("Closing Application") + .setMessage("Are you sure you want to close this application?") + .setPositiveButton("Yes", new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } + + }) + .setNegativeButton("No", null) + .show(); + //popBackStack(); } /** From 12fb201c7d50a7367162bc3a43e8af42522e0f71 Mon Sep 17 00:00:00 2001 From: dikshamalik2552 <89207778+dikshamalik2552@users.noreply.github.com> Date: Mon, 18 Apr 2022 12:41:30 +0530 Subject: [PATCH 2/2] added warning on accidental exit --- .../tables/activities/MainActivity.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java b/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java index 10686e27..8ffaf580 100644 --- a/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java +++ b/tables_app/src/main/java/org/opendatakit/tables/activities/MainActivity.java @@ -267,7 +267,20 @@ private void popBackStack() { if (idxLast < 0) { Intent result = new Intent(); this.setResult(RESULT_OK, result); - finish(); + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle("Closing Application") + .setMessage("Are you sure you want to close this application?") + .setPositiveButton("Yes", new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } + + }) + .setNegativeButton("No", null) + .show(); } else { BackStackEntry entry = mgr.getBackStackEntryAt(idxLast); swapScreens(ScreenType.valueOf(entry.getName())); @@ -301,21 +314,7 @@ public void initializationCompleted() { @Override public void onBackPressed() { - new AlertDialog.Builder(this) - .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle("Closing Application") - .setMessage("Are you sure you want to close this application?") - .setPositiveButton("Yes", new DialogInterface.OnClickListener() - { - @Override - public void onClick(DialogInterface dialog, int which) { - finish(); - } - - }) - .setNegativeButton("No", null) - .show(); - //popBackStack(); + popBackStack(); } /**