Fix cancelling import/export by tapping away from dialog

This commit is contained in:
Sylvia van Os
2024-07-07 14:06:31 +02:00
parent 80e05a0392
commit 8a8d5c65f2
2 changed files with 13 additions and 6 deletions

View File

@@ -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<ImportExportResult> {
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;

View File

@@ -347,4 +347,6 @@
<string name="multipleBarcodesFoundPleaseChooseOne">Which of the found barcodes do you want to use?</string>
<string name="pageWithNumber">Page <xliff:g>%d</xliff:g></string>
<string name="noCameraFoundGuideText">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.</string>
<string name="importCancelled">Import cancelled</string>
<string name="exportCancelled">Export cancelled</string>
</resources>