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