From: David A. Velasco Date: Tue, 11 Feb 2014 10:08:44 +0000 (+0100) Subject: Merge pull request #398 from owncloud/share_link__unshare_file__share_in_operation_se... X-Git-Tag: oc-android-1.5.5~48^2~13 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b015886bd2ccfcc61ab94ef9eefbc30c6485840a?ds=inline;hp=-c Merge pull request #398 from owncloud/share_link__unshare_file__share_in_operation_service Share link unshare file share in operation service --- b015886bd2ccfcc61ab94ef9eefbc30c6485840a diff --combined src/com/owncloud/android/services/OperationsService.java index fe1aed41,40e65002..6925cb0f --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@@ -18,21 -18,19 +18,24 @@@ package com.owncloud.android.services; import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import com.owncloud.android.datamodel.FileDataStorageManager; +import com.owncloud.android.lib.network.OnDatatransferProgressListener; import com.owncloud.android.lib.network.OwnCloudClientFactory; import com.owncloud.android.lib.network.OwnCloudClient; + import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.GetSharesOperation; + import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.common.SyncOperation; +import com.owncloud.android.lib.operations.common.OnRemoteOperationListener; import com.owncloud.android.lib.operations.common.RemoteOperation; import com.owncloud.android.lib.operations.common.RemoteOperationResult; + import com.owncloud.android.lib.operations.common.ShareType; import com.owncloud.android.utils.Log_OC; import android.accounts.Account; @@@ -56,7 -54,12 +59,12 @@@ public class OperationsService extends public static final String EXTRA_ACCOUNT = "ACCOUNT"; public static final String EXTRA_SERVER_URL = "SERVER_URL"; - public static final String EXTRA_RESULT = "RESULT"; + public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH"; + public static final String EXTRA_SEND_INTENT = "SEND_INTENT"; + public static final String EXTRA_RESULT = "RESULT"; + + public static final String ACTION_CREATE_SHARE = "CREATE_SHARE"; + public static final String ACTION_UNSHARE = "UNSHARE"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED"; @@@ -74,7 -77,7 +82,7 @@@ private Looper mServiceLooper; private ServiceHandler mServiceHandler; - private IBinder mBinder; + private OperationsServiceBinder mBinder; private OwnCloudClient mOwnCloudClient = null; private Target mLastTarget = null; private FileDataStorageManager mStorageManager; @@@ -112,8 -115,27 +120,27 @@@ try { Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); String serverUrl = intent.getStringExtra(EXTRA_SERVER_URL); + Target target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl)); - GetSharesOperation operation = new GetSharesOperation(); + RemoteOperation operation = null; + + String action = intent.getAction(); + if (action == ACTION_CREATE_SHARE) { // Create Share + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); + Intent sendIntent = intent.getParcelableExtra(EXTRA_SEND_INTENT); + if (remotePath.length() > 0) { + operation = new CreateShareOperation(remotePath, ShareType.PUBLIC_LINK, + "", false, "", 1, sendIntent); + } + } else if (action == ACTION_UNSHARE) { // Unshare file + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); + if (remotePath.length() > 0) { + operation = new UnshareLinkOperation(remotePath, this.getApplicationContext()); + } + } else { + operation = new GetSharesOperation(); + } + mPendingOperations.add(new Pair(target, operation)); sendBroadcastNewOperation(target, operation); @@@ -155,57 -177,8 +182,57 @@@ * * It provides by itself the available operations. */ - public class OperationsServiceBinder extends Binder { - // TODO + public class OperationsServiceBinder extends Binder /* implements OnRemoteOperationListener */ { + + /** + * Map of listeners that will be reported about the end of operations from a {@link OperationsServiceBinder} instance + */ + private Set mBoundListeners = new HashSet(); + + /** + * Cancels an operation + * + * TODO + */ + public void cancel() { + // TODO + } + + + public void clearListeners() { + mBoundListeners.clear(); + } + + + /** + * Adds a listener interested in being reported about the end of operations. + * + * @param listener Object to notify about the end of operations. + */ + public void addOperationListener (OnRemoteOperationListener listener) { + mBoundListeners.add(listener); + } + + + /** + * Removes a listener from the list of objects interested in the being reported about the end of operations. + * + * @param listener Object to notify about progress of transfer. + */ + public void removeOperationListener (OnRemoteOperationListener listener) { + mBoundListeners.remove(listener); + } + + + /** + * TODO - IMPORTANT: update implementation when more operations are moved into the service + * + * @return 'True' when an operation that enforces the user to wait for completion is in process. + */ + public boolean isPerformingBlockingOperation() { + return (mPendingOperations.size() > 0); + } + } @@@ -297,15 -270,14 +324,15 @@@ } sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result); + callbackOperationListeners(mLastTarget, mCurrentOperation, result); } } /** - * Sends a LOCAL broadcast when a new operation is added to the queue. + * Sends a broadcast when a new operation is added to the queue. * - * Local broadcasts are only delivered to activities in the same process. + * Local broadcasts are only delivered to activities in the same process, but can't be done sticky :\ * * @param target Account or URL pointing to an OC server. * @param operation Added operation. @@@ -346,21 -318,6 +373,21 @@@ //lbm.sendBroadcast(intent); sendStickyBroadcast(intent); } + + /** + * Notifies the currently subscribed listeners about the end of an operation. + * + * @param target Account or URL pointing to an OC server. + * @param operation Finished operation. + * @param result Result of the operation. + */ + private void callbackOperationListeners(Target target, RemoteOperation operation, RemoteOperationResult result) { + Iterator it = mBinder.mBoundListeners.iterator(); + while (it.hasNext()) { + it.next().onRemoteOperationFinish(operation, result); + } + } + }