From: David A. Velasco Date: Thu, 22 Jan 2015 19:01:25 +0000 (+0100) Subject: Added cancelation for subtrees X-Git-Tag: oc-android-1.7.0_signed~23^2~6 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/265e32dee6f3d92dfde7ede23e3baa2d831923b3?ds=inline;hp=--cc Added cancelation for subtrees --- 265e32dee6f3d92dfde7ede23e3baa2d831923b3 diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 47e44728..35b69247 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -284,30 +284,32 @@ public class FileOperationsHelper { */ public void cancelTransference(OCFile file) { Account account = mFileActivity.getAccount(); - if (!file.isFolder()) { - FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder(); - FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder(); - //if (downloaderBinder != null && file.isDownloading()) { - 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); - } - } else { + if (file.isFolder()) { + // this goes to the queue!! :S Intent intent = new Intent(mFileActivity, OperationsService.class); intent.setAction(OperationsService.ACTION_CANCEL_SYNC_FOLDER); intent.putExtra(OperationsService.EXTRA_ACCOUNT, account); intent.putExtra(OperationsService.EXTRA_FILE, file); mFileActivity.startService(intent); + } + + // for both files and folders + FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder(); + //if (downloaderBinder != null && file.isDownloading()) { + if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) { + downloaderBinder.cancel(account, file); + + // TODO - review why is this here, and solve in a better way + // 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); + } + } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) { + uploaderBinder.cancel(account, file); } } diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 2b70606c..5299b626 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -223,7 +223,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis /** * Cancels a pending or current download of a remote file. * - * @param account Owncloud account where the remote file is stored. + * @param account ownCloud account where the remote file is stored. * @param file A file in the queue of pending downloads */ public void cancel(Account account, OCFile file) { @@ -231,6 +231,12 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis download = mPendingDownloads.remove(account, file.getRemotePath()); if (download != null) { download.cancel(); + } else { + // TODO synchronize + if (mCurrentDownload.getRemotePath().startsWith(file.getRemotePath()) && + account.name.equals(mLastAccount)) { + mCurrentDownload.cancel(); + } } } diff --git a/src/com/owncloud/android/files/services/IndexedForest.java b/src/com/owncloud/android/files/services/IndexedForest.java index daf46a56..52482993 100644 --- a/src/com/owncloud/android/files/services/IndexedForest.java +++ b/src/com/owncloud/android/files/services/IndexedForest.java @@ -23,6 +23,7 @@ import com.owncloud.android.datamodel.OCFile; import java.io.File; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -128,6 +129,10 @@ public class IndexedForest { Node firstRemoved = mMap.remove(targetKey); if (firstRemoved != null) { + /// remove children + removeDescendants(firstRemoved); + + /// remove ancestors if only here due to firstRemoved Node removed = firstRemoved; Node parent = removed.getParent(); while (parent != null) { @@ -149,6 +154,16 @@ public class IndexedForest { } + private void removeDescendants(Node removed) { + Iterator> childrenIt = removed.getChildren().iterator(); + Node child = null; + while (childrenIt.hasNext()) { + child = childrenIt.next(); + mMap.remove(child.getKey()); + removeDescendants(child); + } + } + public boolean contains(Account account, String remotePath) { String targetKey = buildKey(account, remotePath); return mMap.containsKey(targetKey); diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 5e038f14..8d13ae2d 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -172,6 +172,7 @@ public class OperationsService extends Service { // WIP: for the moment, only SYNC_FOLDER and CANCEL_SYNC_FOLDER is expected here; // the rest of the operations are requested through the Binder if (ACTION_SYNC_FOLDER.equals(intent.getAction())) { + if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) { Log_OC.e(TAG, "Not enough information provided in intent"); return START_NOT_STICKY; @@ -190,6 +191,7 @@ public class OperationsService extends Service { msg.obj = itemSyncKey; mSyncFolderHandler.sendMessage(msg); } + } else if (ACTION_CANCEL_SYNC_FOLDER.equals(intent.getAction())) { if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) { Log_OC.e(TAG, "Not enough information provided in intent"); @@ -536,14 +538,6 @@ public class OperationsService extends Service { } //sendBroadcastFinishedSyncFolder(account, file.getRemotePath()); - - /// cancellation of download needs to be done separately in any case; a SynchronizeFolderOperation - // may finish much sooner than the real download of the files in the folder - Intent intent = new Intent(mService, FileDownloader.class); - intent.setAction(FileDownloader.ACTION_CANCEL_FILE_DOWNLOAD); - intent.putExtra(FileDownloader.EXTRA_ACCOUNT, account); - intent.putExtra(FileDownloader.EXTRA_FILE, file); - mService.startService(intent); } /**