diff --git a/app/src/main/java/protect/card_locker/ImportExportActivity.java b/app/src/main/java/protect/card_locker/ImportExportActivity.java index 2a5a3d02c..5b020c9b7 100644 --- a/app/src/main/java/protect/card_locker/ImportExportActivity.java +++ b/app/src/main/java/protect/card_locker/ImportExportActivity.java @@ -9,6 +9,7 @@ import android.text.InputType; import android.util.Log; import android.view.MenuItem; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; import android.widget.FrameLayout; @@ -163,6 +164,10 @@ public class ImportExportActivity extends CatimaAppCompatActivity { // Check that there is an app that data can be imported from Button importApplication = binding.importOptionApplicationButton; importApplication.setOnClickListener(v -> chooseImportType(true, null)); + + // FIXME: The importer/exporter is currently quite broken + // To prevent the screen from turning off during import/export and some devices killing Catima as it's no longer foregrounded, force the screen to stay on here + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } private void openFileForImport(Uri uri, char[] password) { diff --git a/app/src/main/java/protect/card_locker/ImportExportTask.java b/app/src/main/java/protect/card_locker/ImportExportTask.java index 8284edff7..05e167c0e 100644 --- a/app/src/main/java/protect/card_locker/ImportExportTask.java +++ b/app/src/main/java/protect/card_locker/ImportExportTask.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.DialogInterface; import android.database.sqlite.SQLiteDatabase; import android.util.Log; +import android.widget.Toast; import java.io.IOException; import java.io.InputStream; @@ -90,16 +91,20 @@ public class ImportExportTask implements CompatCallable { progress = new ProgressDialog(activity); progress.setTitle(doImport ? R.string.importing : R.string.exporting); - progress.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - ImportExportTask.this.stop(); - } - }); + progress.setOnCancelListener(dialog -> cancel(doImport, true)); + progress.setOnDismissListener(dialog -> cancel(doImport, true)); progress.show(); } + private void cancel(boolean isImport, boolean showToast) { + ImportExportTask.this.stop(); + + if (showToast) { + Toast.makeText(activity, isImport ? R.string.importCancelled : R.string.exportCancelled, Toast.LENGTH_LONG).show(); + } + } + protected ImportExportResult doInBackground(Void... nothing) { final SQLiteDatabase database = new DBHelper(activity).getWritableDatabase(); ImportExportResult result; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1fd701487..60580b163 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -347,4 +347,6 @@ Which of the found barcodes do you want to use? Page %d Your device does not seem to have a camera. If it does, try rebooting the device. Otherwise, use the "More options" button below to add a barcode another way. + Import cancelled + Export cancelled