use of net.osmand.plus.backup.BackupHelper.STATUS_SUCCESS in project Osmand by osmandapp.
the class DeleteAllFilesCommand method getDeleteAllFilesListener.
private OnRequestResultListener getDeleteAllFilesListener() {
return (resultJson, error, resultCode) -> {
int status;
String message;
List<RemoteFile> remoteFiles = new ArrayList<>();
if (!Algorithms.isEmpty(error)) {
status = STATUS_SERVER_ERROR;
message = "Download file list error: " + new BackupError(error);
} else if (!Algorithms.isEmpty(resultJson)) {
try {
JSONObject result = new JSONObject(resultJson);
JSONArray files = result.getJSONArray("allFiles");
for (int i = 0; i < files.length(); i++) {
remoteFiles.add(new RemoteFile(files.getJSONObject(i)));
}
status = STATUS_SUCCESS;
message = "OK";
} catch (JSONException e) {
status = STATUS_PARSE_JSON_ERROR;
message = "Download file list error: json parsing";
}
} else {
status = STATUS_EMPTY_RESPONSE_ERROR;
message = "Download file list error: empty response";
}
if (status != STATUS_SUCCESS) {
publishProgress(status, message);
} else {
List<RemoteFile> filesToDelete = new ArrayList<>();
if (types != null) {
for (RemoteFile file : remoteFiles) {
ExportSettingsType exportType = ExportSettingsType.getExportSettingsTypeForRemoteFile(file);
if (types.contains(exportType)) {
filesToDelete.add(file);
}
}
} else {
filesToDelete.addAll(remoteFiles);
}
if (!filesToDelete.isEmpty()) {
publishProgress(filesToDelete);
deleteFiles(filesToDelete);
} else {
publishProgress(Collections.emptyMap());
}
}
};
}
use of net.osmand.plus.backup.BackupHelper.STATUS_SUCCESS in project Osmand by osmandapp.
the class DeleteOldFilesCommand method getDeleteOldFilesListener.
private OnRequestResultListener getDeleteOldFilesListener() {
return (resultJson, error, resultCode) -> {
int status;
String message;
List<RemoteFile> remoteFiles = new ArrayList<>();
if (!Algorithms.isEmpty(error)) {
status = STATUS_SERVER_ERROR;
message = "Download file list error: " + new BackupError(error);
} else if (!Algorithms.isEmpty(resultJson)) {
try {
JSONObject result = new JSONObject(resultJson);
JSONArray allFiles = result.getJSONArray("allFiles");
for (int i = 0; i < allFiles.length(); i++) {
remoteFiles.add(new RemoteFile(allFiles.getJSONObject(i)));
}
JSONArray uniqueFiles = result.getJSONArray("uniqueFiles");
for (int i = 0; i < uniqueFiles.length(); i++) {
remoteFiles.remove(new RemoteFile(uniqueFiles.getJSONObject(i)));
}
status = STATUS_SUCCESS;
message = "OK";
} catch (JSONException e) {
status = STATUS_PARSE_JSON_ERROR;
message = "Download file list error: json parsing";
}
} else {
status = STATUS_EMPTY_RESPONSE_ERROR;
message = "Download file list error: empty response";
}
if (status != STATUS_SUCCESS) {
publishProgress(status, message);
} else {
List<RemoteFile> filesToDelete = new ArrayList<>();
if (types != null) {
for (RemoteFile file : remoteFiles) {
ExportSettingsType exportType = ExportSettingsType.getExportSettingsTypeForRemoteFile(file);
if (types.contains(exportType)) {
filesToDelete.add(file);
}
}
} else {
filesToDelete.addAll(remoteFiles);
}
if (!filesToDelete.isEmpty()) {
publishProgress(filesToDelete);
deleteFiles(filesToDelete);
} else {
publishProgress(Collections.emptyMap());
}
}
};
}
Aggregations