Search in sources :

Example 1 with OnRemoteOperationListener

use of com.owncloud.android.lib.common.operations.OnRemoteOperationListener in project android by owncloud.

the class OperationsService method dispatchResultToOperationListeners.

/**
     * Notifies the currently subscribed listeners about the end of an operation.
     *
     * @param operation         Finished operation.
     * @param result            Result of the operation.
     */
protected void dispatchResultToOperationListeners(final RemoteOperation operation, final RemoteOperationResult result) {
    int count = 0;
    Iterator<OnRemoteOperationListener> listeners = mOperationsBinder.mBoundListeners.keySet().iterator();
    while (listeners.hasNext()) {
        final OnRemoteOperationListener listener = listeners.next();
        final Handler handler = mOperationsBinder.mBoundListeners.get(listener);
        if (handler != null) {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    listener.onRemoteOperationFinish(operation, result);
                }
            });
            count += 1;
        }
    }
    if (count == 0) {
        Pair<RemoteOperation, RemoteOperationResult> undispatched = new Pair<RemoteOperation, RemoteOperationResult>(operation, result);
        mUndispatchedFinishedOperations.put(((Runnable) operation).hashCode(), undispatched);
    }
    Log_OC.d(TAG, "Called " + count + " listeners");
}
Also used : RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OnRemoteOperationListener(com.owncloud.android.lib.common.operations.OnRemoteOperationListener) Handler(android.os.Handler) Pair(android.util.Pair)

Aggregations

Handler (android.os.Handler)1 Pair (android.util.Pair)1 OnRemoteOperationListener (com.owncloud.android.lib.common.operations.OnRemoteOperationListener)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1