Add option to 'Add as New' on import

This commit is contained in:
OMGeeky
2022-10-18 22:15:53 +02:00
parent f8ae18721f
commit 6d5ddfdbfa
2 changed files with 39 additions and 11 deletions

View File

@@ -175,10 +175,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
private void completeLoadSaveActivity(int slot) {
Intent i = new Intent();
if (slot == SLOT_NUMBER_CREATE_NEW_SLOT) {
List<Integer> usedSlots = Savegames.getUsedSavegameSlots(this);
if (usedSlots.isEmpty())
slot = SLOT_NUMBER_FIRST_SLOT;
else slot = Collections.max(usedSlots) + 1;
slot = getFirstFreeSlot();
} else if (slot == SLOT_NUMBER_EXPORT_SAVEGAMES
|| slot == SLOT_NUMBER_IMPORT_SAVEGAMES
|| slot == SLOT_NUMBER_IMPORT_WORLDMAP) {
@@ -191,6 +188,15 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
LoadSaveActivity.this.finish();
}
private int getFirstFreeSlot() {
int slot;
List<Integer> usedSlots = Savegames.getUsedSavegameSlots(this);
if (usedSlots.isEmpty())
slot = SLOT_NUMBER_FIRST_SLOT;
else slot = Collections.max(usedSlots) + 1;
return slot;
}
private String getConfirmOverwriteQuestion(int slot) {
if (isLoading)
return null;
@@ -400,8 +406,16 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
}
private void importSaveGames(ContentResolver resolver, DocumentFile appSavegameFolder, List<DocumentFile> saveFiles) {
importSaveGames(resolver, appSavegameFolder, saveFiles, false);
}
private void importSaveGames(ContentResolver resolver, DocumentFile appSavegameFolder, List<DocumentFile> saveFiles, boolean addAsNew) {
for (DocumentFile file : saveFiles) {
int slot = getSlotFromSavegameFileName(file.getName());
int slot;
if(addAsNew)
slot = getFirstFreeSlot();
else
slot = getSlotFromSavegameFileName(file.getName());
importSaveGameFile(resolver, appSavegameFolder, file, slot);
}
}
@@ -543,7 +557,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
List<DocumentFile> alreadyExistingFiles,
List<DocumentFile> newFiles) {
final String title = getString(R.string.loadsave_import_overwrite_confirmation_title);
String message = getString(R.string.loadsave_import_overwrite_confirmation);
String message = getString(R.string.loadsave_import_file_exists_confirmation);
StringBuilder sb = new StringBuilder();
sb.append('\n');
@@ -560,7 +574,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
if (fileHeader != null)
fileHeaderDesription = fileHeader.describe();
sb.append(getString(R.string.loadsave_import_overwrite_confirmation_file_pattern, alreadyExistingFileName, fileHeaderDesription));
sb.append(getString(R.string.loadsave_import_file_exists_confirmation_file_pattern, alreadyExistingFileName, fileHeaderDesription));
// sb.append(alreadyExistingFile.getName());
}
if (amount > 3) {
@@ -572,12 +586,24 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
getResources().getDrawable(android.R.drawable.ic_dialog_alert),
message,
null,
true,
true);
CustomDialogFactory.addButton(d, android.R.string.yes, v -> newFiles.addAll(alreadyExistingFiles));
CustomDialogFactory.addButton(d, R.string.loadsave_import_option_overwrite, v -> newFiles.addAll(alreadyExistingFiles));
CustomDialogFactory.addButton(d, R.string.loadsave_import_option_add_as_new, v -> {
newFiles.add(null);//add a null element as marker to know later if the files should be imported as new or overwrite the existing ones
newFiles.addAll(alreadyExistingFiles);
});
CustomDialogFactory.addDismissButton(d, android.R.string.no);
CustomDialogFactory.setDismissListener(d, dialog -> {
importSaveGames(resolver, appSavegameFolder, newFiles);
boolean addAsNew = false;
if(newFiles.size() > 0 && newFiles.get(0) == null) {
newFiles.remove(0);
addAsNew = true;
}
importSaveGames(resolver, appSavegameFolder, newFiles, addAsNew);
completeLoadSaveActivity(SLOT_NUMBER_IMPORT_SAVEGAMES);
});
CustomDialogFactory.show(d);

View File

@@ -494,8 +494,10 @@
<string name="loadsave_export_overwrite_confirmation_title">Overwrite Existing Files?</string>
<string name="loadsave_export_overwrite_confirmation">The target Folder contains existing files with the same name of some Files that should be exported. Are you sure you want to overwrite those files?</string>
<string name="loadsave_import_overwrite_confirmation_title">Overwrite Existing Files?</string>
<string name="loadsave_import_overwrite_confirmation">The target Folder contains existing files with the same name. Are you sure you want to overwrite these files:</string>
<string name="loadsave_import_overwrite_confirmation_file_pattern">(%1$s) - (%2$s)</string>
<string name="loadsave_import_option_overwrite">Overwrite Existing</string>
<string name="loadsave_import_option_add_as_new">Add as new Save</string>
<string name="loadsave_import_file_exists_confirmation">The target Folder contains existing files with the same name. Do you want to overwrite these slots or import them as new saves?</string>
<string name="loadsave_import_file_exists_confirmation_file_pattern">(%1$s) - (%2$s)</string>
<string name="loadsave_import_save">Import savegames</string>
<string name="loadsave_import_save_successfull">Import successful</string>
<string name="loadsave_import_save_unsuccessfull">Import unsuccessful</string>