Skip to content

Commit 968729f

Browse files
Merge pull request #1983 from CatimaLoyalty/fix/importExportHacks
Fix/import export hacks
2 parents 2374e99 + 8a8d5c6 commit 968729f

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

app/src/main/java/protect/card_locker/ImportExportActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.util.Log;
1010
import android.view.MenuItem;
1111
import android.view.ViewGroup;
12+
import android.view.WindowManager;
1213
import android.widget.Button;
1314
import android.widget.EditText;
1415
import android.widget.FrameLayout;
@@ -163,6 +164,10 @@ public void run() {
163164
// Check that there is an app that data can be imported from
164165
Button importApplication = binding.importOptionApplicationButton;
165166
importApplication.setOnClickListener(v -> chooseImportType(true, null));
167+
168+
// FIXME: The importer/exporter is currently quite broken
169+
// 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
170+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
166171
}
167172

168173
private void openFileForImport(Uri uri, char[] password) {

app/src/main/java/protect/card_locker/ImportExportTask.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.DialogInterface;
77
import android.database.sqlite.SQLiteDatabase;
88
import android.util.Log;
9+
import android.widget.Toast;
910

1011
import java.io.IOException;
1112
import java.io.InputStream;
@@ -90,16 +91,20 @@ public void onPreExecute() {
9091
progress = new ProgressDialog(activity);
9192
progress.setTitle(doImport ? R.string.importing : R.string.exporting);
9293

93-
progress.setOnDismissListener(new DialogInterface.OnDismissListener() {
94-
@Override
95-
public void onDismiss(DialogInterface dialog) {
96-
ImportExportTask.this.stop();
97-
}
98-
});
94+
progress.setOnCancelListener(dialog -> cancel(doImport, true));
95+
progress.setOnDismissListener(dialog -> cancel(doImport, true));
9996

10097
progress.show();
10198
}
10299

100+
private void cancel(boolean isImport, boolean showToast) {
101+
ImportExportTask.this.stop();
102+
103+
if (showToast) {
104+
Toast.makeText(activity, isImport ? R.string.importCancelled : R.string.exportCancelled, Toast.LENGTH_LONG).show();
105+
}
106+
}
107+
103108
protected ImportExportResult doInBackground(Void... nothing) {
104109
final SQLiteDatabase database = new DBHelper(activity).getWritableDatabase();
105110
ImportExportResult result;

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,6 @@
347347
<string name="multipleBarcodesFoundPleaseChooseOne">Which of the found barcodes do you want to use?</string>
348348
<string name="pageWithNumber">Page <xliff:g>%d</xliff:g></string>
349349
<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>
350+
<string name="importCancelled">Import cancelled</string>
351+
<string name="exportCancelled">Export cancelled</string>
350352
</resources>

0 commit comments

Comments
 (0)