mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-01-18 17:44:22 +01:00
Fixed bug where the Logs folder would get exported instead of the Worldmap folder
+cleanup +API level safety markers
This commit is contained in:
@@ -306,6 +306,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
|
||||
//region Imports/Exports
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void exportSaveGames(Intent data) {
|
||||
Uri uri = data.getData();
|
||||
|
||||
@@ -342,6 +343,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void exportSaveGamesFolderContentToFolder(ContentResolver resolver, DocumentFile target, DocumentFile[] files) {
|
||||
DocumentFile[] sourceFiles = new DocumentFile[files.length];
|
||||
|
||||
@@ -351,7 +353,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
DocumentFile file = files[i];
|
||||
if (file.isFile()) {
|
||||
sourceFiles[i] = file;
|
||||
} else if (file.isDirectory()) {
|
||||
} else if (file.isDirectory() && Objects.equals(file.getName(), Constants.FILENAME_WORLDMAP_DIRECTORY)) {
|
||||
worldmapFiles = file.listFiles();
|
||||
}
|
||||
}
|
||||
@@ -375,7 +377,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
}
|
||||
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private void importSaveGames(Intent data) {
|
||||
Uri uri = data.getData();
|
||||
ClipData uris = data.getClipData();
|
||||
@@ -401,6 +403,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
importSaveGamesFromUris(context, resolver, appSavegameFolder, uriList);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private void importSaveGamesFromUris(Context context, ContentResolver resolver, DocumentFile appSavegameFolder, List<Uri> uriList) {
|
||||
int count = uriList.size();
|
||||
|
||||
@@ -515,6 +518,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
return targetFile;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void importWorldmap(Intent data) {
|
||||
Uri uri = data.getData();
|
||||
|
||||
@@ -568,6 +572,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void showConfirmOverwriteByExportQuestion(ContentResolver resolver, DocumentFile targetFolder, DocumentFile[] files) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(this,
|
||||
getString(R.string.loadsave_export_overwrite_confirmation_title),
|
||||
@@ -582,6 +587,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private void showConfirmOverwriteByImportQuestion(ContentResolver resolver,
|
||||
DocumentFile appSavegameFolder,
|
||||
List<DocumentFile> alreadyExistingFiles,
|
||||
@@ -656,6 +662,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
GoToNextConflictOrFinish(resolver, appSavegameFolder, newFiles, dialogs);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private void GoToNextConflictOrFinish(ContentResolver resolver, DocumentFile appSavegameFolder, List<DocumentFile> newFiles, ArrayList<CustomDialog> dialogs) {
|
||||
if(dialogs.stream().count() > 0){
|
||||
CustomDialog d = dialogs.remove(0);
|
||||
@@ -673,7 +680,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
if (resultCode != Activity.RESULT_OK)
|
||||
return;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
switch (-requestCode) {
|
||||
case SLOT_NUMBER_EXPORT_SAVEGAMES:
|
||||
exportSaveGames(data);
|
||||
|
||||
@@ -229,53 +229,50 @@ public final class AndroidStorage {
|
||||
worker.run();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
public static void copyDocumentFilesToDirAsync(DocumentFile[] files,
|
||||
Context context,
|
||||
DocumentFile targetDirectory,
|
||||
Consumer<Boolean> callback) {
|
||||
BackgroundWorker worker = new BackgroundWorker();
|
||||
BackgroundWorker<Boolean> worker = new BackgroundWorker<>();
|
||||
CustomDialogFactory.CustomDialog progressDialog = getLoadingDialog(context);
|
||||
progressDialog.setOnCancelListener(dialog -> worker.cancel());
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Handler handler = Handler.createAsync(Looper.getMainLooper());
|
||||
|
||||
worker.setTask(new BackgroundWorker.worker() {
|
||||
@Override
|
||||
public void doWork(BackgroundWorkerCallback callback) {
|
||||
try {
|
||||
callback.onInitialize();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (worker.isCancelled()) {
|
||||
callback.onFailure(new CancellationException("Cancelled"));
|
||||
return;
|
||||
}
|
||||
DocumentFile file = files[i];
|
||||
if(file == null)
|
||||
continue;
|
||||
|
||||
copyDocumentFileToNewOrExistingFile(file, resolver, targetDirectory);
|
||||
float progress = i /(float) files.length;
|
||||
callback.onProgress(progress);
|
||||
}
|
||||
callback.onComplete(true);
|
||||
} catch (NullPointerException e) {
|
||||
worker.setTask(workerCallback -> {
|
||||
try {
|
||||
workerCallback.onInitialize();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (worker.isCancelled()) {
|
||||
callback.onFailure(new CancellationException("Cancelled"));
|
||||
workerCallback.onFailure(new CancellationException("Cancelled"));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
callback.onFailure(e);
|
||||
DocumentFile file = files[i];
|
||||
if(file == null)
|
||||
continue;
|
||||
|
||||
copyDocumentFileToNewOrExistingFile(file, resolver, targetDirectory);
|
||||
float progress = i /(float) files.length;
|
||||
workerCallback.onProgress(progress);
|
||||
}
|
||||
workerCallback.onComplete(true);
|
||||
} catch (NullPointerException e) {
|
||||
if (worker.isCancelled()) {
|
||||
workerCallback.onFailure(new CancellationException("Cancelled"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
workerCallback.onFailure(e);
|
||||
}
|
||||
});
|
||||
worker.setCallback(getDefaultBackgroundWorkerCallback(handler, progressDialog, callback));
|
||||
worker.run();
|
||||
}
|
||||
|
||||
private static BackgroundWorkerCallback getDefaultBackgroundWorkerCallback(Handler handler,
|
||||
private static BackgroundWorkerCallback<Boolean> getDefaultBackgroundWorkerCallback(Handler handler,
|
||||
CustomDialogFactory.CustomDialog progressDialog,
|
||||
Consumer<Boolean> callback) {
|
||||
return new BackgroundWorkerCallback() {
|
||||
return new BackgroundWorkerCallback<Boolean>() {
|
||||
private int progress = -1;
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
@@ -296,6 +293,7 @@ public final class AndroidStorage {
|
||||
});
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
handler.post(() -> {
|
||||
@@ -304,8 +302,9 @@ public final class AndroidStorage {
|
||||
});
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public void onComplete(Object result) {
|
||||
public void onComplete(Boolean result) {
|
||||
handler.post(() -> {
|
||||
progressDialog.dismiss();
|
||||
callback.accept(true);
|
||||
@@ -315,14 +314,13 @@ public final class AndroidStorage {
|
||||
}
|
||||
|
||||
private static CustomDialogFactory.CustomDialog getLoadingDialog(Context context) {
|
||||
CustomDialogFactory.CustomDialog progressDialog = CustomDialogFactory.createDialog(context,
|
||||
return CustomDialogFactory.createDialog(context,
|
||||
context.getResources().getString(R.string.dialog_loading_message),
|
||||
context.getResources().getDrawable(R.drawable.loading_anim),
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
false);
|
||||
return progressDialog;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user