+ /**
+ * Binder to let client components to perform operations on the queue of uploads.
+ *
+ * It provides by itself the available operations.
+ */
+ public class FileUploaderBinder extends Binder {
+
+ /**
+ * Cancels a pending or current upload of a remote file.
+ *
+ * @param account Owncloud account where the remote file will be stored.
+ * @param file A file in the queue of pending uploads
+ */
+ public void cancel(Account account, OCFile file) {
+ UploadFileOperation upload = null;
+ synchronized (mPendingUploads) {
+ upload = mPendingUploads.remove(buildRemoteName(account, file));
+ }
+ if (upload != null) {
+ upload.cancel();
+ }
+ }
+
+
+ /**
+ * Returns True when the file described by 'file' is being uploaded to the ownCloud account 'account' or waiting for it
+ *
+ * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting to download.
+ *
+ * @param account Owncloud account where the remote file will be stored.
+ * @param file A file that could be in the queue of pending uploads
+ */
+ public boolean isUploading(Account account, OCFile file) {
+ String targetKey = buildRemoteName(account, file);
+ synchronized (mPendingUploads) {
+ if (file.isDirectory()) {
+ // this can be slow if there are many downloads :(
+ Iterator<String> it = mPendingUploads.keySet().iterator();
+ boolean found = false;
+ while (it.hasNext() && !found) {
+ found = it.next().startsWith(targetKey);
+ }
+ return found;
+ } else {
+ return (mPendingUploads.containsKey(targetKey));
+ }
+ }
+ }
+ }
+
+
+