use of net.osmand.plus.backup.BackupListeners.OnDeleteFilesListener in project Osmand by osmandapp.
the class BackupExporter method exportItems.
private void exportItems() throws IOException {
AtomicInteger dataProgress = new AtomicInteger(0);
Set<Object> itemsProgress = Collections.synchronizedSet(new HashSet<>());
Map<String, String> errors = new ConcurrentHashMap<>();
OnUploadItemListener uploadItemListener = getOnUploadItemListener(itemsProgress, dataProgress, errors);
OnDeleteFilesListener deleteFilesListener = getOnDeleteFilesListener(itemsProgress, dataProgress);
NetworkWriter networkWriter = new NetworkWriter(backupHelper, uploadItemListener);
writeItems(networkWriter);
deleteFiles(deleteFilesListener);
deleteOldFiles(deleteFilesListener);
if (!isCancelled()) {
backupHelper.updateBackupUploadTime();
}
if (listener != null) {
listener.networkExportDone(errors);
}
}
use of net.osmand.plus.backup.BackupListeners.OnDeleteFilesListener in project Osmand by osmandapp.
the class DeleteAllFilesCommand method onProgressUpdate.
@Override
protected void onProgressUpdate(Object... objects) {
super.onProgressUpdate(objects);
for (OnDeleteFilesListener listener : getListeners()) {
Object obj = objects[0];
if (obj instanceof Map) {
listener.onFilesDeleteDone((Map) obj);
} else if (obj instanceof List) {
listener.onFilesDeleteStarted((List) obj);
} else if (obj instanceof Integer && objects.length == 2) {
int status = (Integer) obj;
String message = (String) objects[1];
listener.onFilesDeleteError(status, message);
}
}
}
use of net.osmand.plus.backup.BackupListeners.OnDeleteFilesListener in project Osmand by osmandapp.
the class DeleteOldFilesCommand method onProgressUpdate.
@Override
protected void onProgressUpdate(Object... objects) {
super.onProgressUpdate(objects);
for (OnDeleteFilesListener listener : getListeners()) {
Object obj = objects[0];
if (obj instanceof Map) {
listener.onFilesDeleteDone((Map) obj);
} else if (obj instanceof List) {
listener.onFilesDeleteStarted((List) obj);
} else if (obj instanceof Integer && objects.length == 2) {
int status = (Integer) obj;
String message = (String) objects[1];
listener.onFilesDeleteError(status, message);
}
}
}
use of net.osmand.plus.backup.BackupListeners.OnDeleteFilesListener in project Osmand by osmandapp.
the class BaseDeleteFilesCommand method onProgressUpdate.
@Override
protected void onProgressUpdate(Object... objects) {
for (OnDeleteFilesListener listener : getListeners()) {
Object obj = objects[0];
if (obj instanceof DeleteRemoteFileTask) {
RemoteFile remoteFile = ((DeleteRemoteFileTask) obj).remoteFile;
itemsProgress.add(remoteFile);
listener.onFileDeleteProgress(remoteFile, itemsProgress.size());
}
}
}
use of net.osmand.plus.backup.BackupListeners.OnDeleteFilesListener in project Osmand by osmandapp.
the class BaseDeleteFilesCommand method onPostExecute.
@Override
protected void onPostExecute(Object o) {
List<OnDeleteFilesListener> listeners = getListeners();
if (!listeners.isEmpty()) {
Map<RemoteFile, String> errors = new HashMap<>();
for (DeleteRemoteFileTask task : tasks) {
boolean success;
String message = null;
RequestResponse response = task.response;
if (response != null) {
String errorStr = response.getError();
if (!Algorithms.isEmpty(errorStr)) {
message = new BackupError(errorStr).toString();
success = false;
} else {
String responseStr = response.getResponse();
try {
JSONObject result = new JSONObject(responseStr);
if (result.has("status") && "ok".equals(result.getString("status"))) {
success = true;
} else {
message = "Unknown error";
success = false;
}
} catch (JSONException e) {
message = "Json parsing error";
success = false;
}
}
if (!success) {
errors.put(task.remoteFile, message);
}
}
}
for (OnDeleteFilesListener listener : listeners) {
listener.onFilesDeleteDone(errors);
}
}
if (listener != null) {
getListeners().remove(listener);
}
}
Aggregations