From f6f1c7e6291edf9aa5e240773daf4235eaf9ecb2 Mon Sep 17 00:00:00 2001 From: jabarros Date: Thu, 11 Dec 2014 18:18:23 +0100 Subject: [PATCH] Add call to OperationService for canceling transference of downloading a folder --- .../android/files/FileOperationsHelper.java | 39 ++++++++++++++-------- .../android/services/OperationsService.java | 5 ++- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index bbef1f83..61094d12 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -278,23 +278,34 @@ public class FileOperationsHelper { mFileActivity.showLoadingDialog(); } - + /** + * Cancel the transference in downloads (files/folders) and file uploads + * @param file OCFile + */ public void cancelTransference(OCFile file) { Account account = mFileActivity.getAccount(); - FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder(); - FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder(); - if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) { - // Remove etag for parent, if file is a keep_in_sync - if (file.keepInSync()) { - OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId()); - parent.setEtag(""); - mFileActivity.getStorageManager().saveFile(parent); + if (!file.isFolder()) { + FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder(); + if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) { + // Remove etag for parent, if file is a keep_in_sync + if (file.keepInSync()) { + OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId()); + parent.setEtag(""); + mFileActivity.getStorageManager().saveFile(parent); + } + + downloaderBinder.cancel(account, file); + + } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) { + uploaderBinder.cancel(account, file); } - - downloaderBinder.cancel(account, file); - - } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) { - uploaderBinder.cancel(account, file); + } else { + Intent intent = new Intent(mFileActivity, OperationsService.class); + intent.setAction(OperationsService.ACTION_CANCEL_SYNC_FOLDER); + intent.putExtra(OperationsService.EXTRA_ACCOUNT, account); + intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + mFileActivity.startService(intent); } } diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 02462df4..2538be6b 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -101,6 +101,7 @@ public class OperationsService extends Service { public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER"; public static final String ACTION_SYNC_FILE = "SYNC_FILE"; public static final String ACTION_SYNC_FOLDER = "SYNC_FOLDER"; // for the moment, just to download + public static final String ACTION_CANCEL_SYNC_FOLDER = "CANCEL_SYNC_FOLDER"; // for the moment, just to download public static final String ACTION_MOVE_FILE = "MOVE_FILE"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; @@ -172,7 +173,9 @@ public class OperationsService extends Service { msg.arg1 = startId; mSyncFolderHandler.sendMessage(msg); } - + + } else if (ACTION_CANCEL_SYNC_FOLDER.equals(intent.getAction())) { + } else { Message msg = mOperationsHandler.obtainMessage(); msg.arg1 = startId; -- 2.11.0