X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ab8bf56a15193f69169d284876ac6bbd80ff2150..2a02a08d52656ce3259939e2448800388675a0c5:/src/com/owncloud/android/files/services/FileUploader.java diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index f9c57ccf..0859cf9a 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -327,7 +327,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe return false; // not accepting rebinding (default behaviour) } - /** * Binder to let client components to perform operations on the queue of * uploads. @@ -357,15 +356,42 @@ public class FileUploader extends Service implements OnDatatransferProgressListe } } + /** + * Cancels a pending or current upload for an account + * + * @param account Owncloud accountName where the remote file will be stored. + */ + public void cancel(Account account) { + Log_OC.d(TAG, "Account= " + account.name); + if (mCurrentUpload != null) { + Log_OC.d(TAG, "Current Upload Account= " + mCurrentUpload.getAccount().name); + if (mCurrentUpload.getAccount().name == account.name) { + mCurrentUpload.cancel(); + } + } + // Cancel pending uploads + Iterator it = mPendingUploads.keySet().iterator(); + Log_OC.d(TAG, "Number of pending updloads= " + mPendingUploads.size()); + while (it.hasNext()) { + String key = it.next(); + Log_OC.d(TAG, "mPendingUploads CANCELLED " + key); + if (key.startsWith(account.name)) { + UploadFileOperation upload; + synchronized (mPendingUploads) { + upload = mPendingUploads.remove(key); + } + if (upload != null) { + upload.cancel(); + } + } + } + } public void clearListeners() { mBoundListeners.clear(); } - - - /** * Returns True when the file described by 'file' is being uploaded to * the ownCloud account 'account' or waiting for it @@ -548,6 +574,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe } else { // Cancel the transfer Log_OC.d(TAG, "Account " + mCurrentUpload.getAccount().toString() + " doesn't exist"); + cancelUploadForAccount(mCurrentUpload.getAccount().name); + } } @@ -887,4 +915,22 @@ public class FileUploader extends Service implements OnDatatransferProgressListe !localPath.endsWith(FILE_EXTENSION_PDF); } + /** + * Remove uploads of an account + * @param accountName + */ + private void cancelUploadForAccount(String accountName){ + // this can be slow if there are many uploads :( + Iterator it = mPendingUploads.keySet().iterator(); + Log_OC.d(TAG, "Number of pending updloads= " + mPendingUploads.size()); + while (it.hasNext()) { + String key = it.next(); + Log_OC.d(TAG, "mPendingUploads CANCELLED " + key); + if (key.startsWith(accountName)) { + synchronized (mPendingUploads) { + mPendingUploads.remove(key); + } + } + } + } }