Search in sources :

Example 1 with ThreadPoolTaskExecutor

use of net.osmand.plus.backup.ThreadPoolTaskExecutor in project Osmand by osmandapp.

the class BaseDeleteFilesCommand method deleteFiles.

protected void deleteFiles(@NonNull List<RemoteFile> remoteFiles) {
    Map<String, String> commonParameters = new HashMap<>();
    commonParameters.put("deviceid", getHelper().getDeviceId());
    commonParameters.put("accessToken", getHelper().getAccessToken());
    List<DeleteRemoteFileTask> tasks = new ArrayList<>();
    for (RemoteFile remoteFile : remoteFiles) {
        Map<String, String> parameters = new HashMap<>(commonParameters);
        parameters.put("name", remoteFile.getName());
        parameters.put("type", remoteFile.getType());
        if (byVersion) {
            parameters.put("updatetime", String.valueOf(remoteFile.getUpdatetimems()));
        }
        Request r = new Request(byVersion ? DELETE_FILE_VERSION_URL : DELETE_FILE_URL, parameters, null, false, true);
        tasks.add(new DeleteRemoteFileTask(getApp(), r, remoteFile, byVersion));
    }
    ThreadPoolTaskExecutor<DeleteRemoteFileTask> executor = new ThreadPoolTaskExecutor<>(new OnThreadPoolTaskExecutorListener<DeleteRemoteFileTask>() {

        @Override
        public void onTaskStarted(@NonNull DeleteRemoteFileTask task) {
        }

        @Override
        public void onTaskFinished(@NonNull DeleteRemoteFileTask task) {
            publishProgress(task);
        }

        @Override
        public void onTasksFinished(@NonNull List<DeleteRemoteFileTask> tasks) {
            BaseDeleteFilesCommand.this.tasks = tasks;
        }
    });
    executor.run(tasks);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Request(net.osmand.plus.utils.AndroidNetworkUtils.Request) ThreadPoolTaskExecutor(net.osmand.plus.backup.ThreadPoolTaskExecutor) RemoteFile(net.osmand.plus.backup.RemoteFile)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 RemoteFile (net.osmand.plus.backup.RemoteFile)1 ThreadPoolTaskExecutor (net.osmand.plus.backup.ThreadPoolTaskExecutor)1 Request (net.osmand.plus.utils.AndroidNetworkUtils.Request)1