From defe460a0a8df947a8fec55bfa6b132ecc19f66d Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 4 Jul 2015 23:30:54 +0100 Subject: [PATCH 1/2] Allow asynchronous execution without handler --- .../common/operations/RemoteOperation.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java index c5aaeb14..6d95801c 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -254,6 +254,34 @@ public abstract class RemoteOperation implements Runnable { runnerThread.start(); return runnerThread; } + + /** + * Asynchronously executes the remote operation without a handler + * + * @param client Client object to reach an ownCloud server + * during the execution of the operation. + * @param listener Listener to be notified about the execution of the operation. + * @return Thread were the remote operation is executed. + */ + public Thread execute(OwnCloudClient client, + OnRemoteOperationListener listener) { + if (client == null) { + throw new IllegalArgumentException + ("Trying to execute a remote operation with a NULL OwnCloudClient"); + } + mClient = client; + + if (listener == null) { + throw new IllegalArgumentException + ("Trying to execute a remote operation asynchronously " + + "without a listener to notiy the result"); + } + mListener = listener; + + Thread runnerThread = new Thread(this); + runnerThread.start(); + return runnerThread; + } /** * Asynchronous execution of the operation @@ -346,6 +374,9 @@ public abstract class RemoteOperation implements Runnable { } }); } + else if(mListener != null) { + mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend); + } } From 59af0394ece0341e533a69d7f3442c1ac2e5cdc8 Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 30 Jan 2016 09:26:15 +0000 Subject: [PATCH 2/2] Allow asynchronous execution without handler --- .../common/operations/RemoteOperation.java | 37 ++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java index 83298f39..777d268f 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -224,7 +224,7 @@ public abstract class RemoteOperation implements Runnable { * @param client Client object to reach an ownCloud server * during the execution of the operation. * @param listener Listener to be notified about the execution of the operation. - * @param listenerHandler Handler associated to the thread where the methods of + * @param listenerHandler Handler, if passed in, associated to the thread where the methods of * the listener objects must be called. * @return Thread were the remote operation is executed. */ @@ -243,46 +243,17 @@ public abstract class RemoteOperation implements Runnable { } mListener = listener; - if (listenerHandler == null) { - throw new IllegalArgumentException - ("Trying to execute a remote operation asynchronously " + - "without a handler to the listener's thread"); + if (listenerHandler != null) { + mListenerHandler = listenerHandler; } - mListenerHandler = listenerHandler; + Thread runnerThread = new Thread(this); runnerThread.start(); return runnerThread; } - /** - * Asynchronously executes the remote operation without a handler - * - * @param client Client object to reach an ownCloud server - * during the execution of the operation. - * @param listener Listener to be notified about the execution of the operation. - * @return Thread were the remote operation is executed. - */ - public Thread execute(OwnCloudClient client, - OnRemoteOperationListener listener) { - if (client == null) { - throw new IllegalArgumentException - ("Trying to execute a remote operation with a NULL OwnCloudClient"); - } - mClient = client; - if (listener == null) { - throw new IllegalArgumentException - ("Trying to execute a remote operation asynchronously " + - "without a listener to notiy the result"); - } - mListener = listener; - - Thread runnerThread = new Thread(this); - runnerThread.start(); - return runnerThread; - } - /** * Asynchronous execution of the operation * started by {@link RemoteOperation#execute(OwnCloudClient,