Merge pull request #866 from owncloud/download_folder
[pub/Android/ownCloud.git] / src / com / owncloud / android / services / OperationsService.java
index db30355..2e57ada 100644 (file)
@@ -103,7 +103,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_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";
@@ -169,6 +169,8 @@ public class OperationsService extends Service {
         // the rest of the operations are requested through the Binder
         if (ACTION_SYNC_FOLDER.equals(intent.getAction())) {
 
+            /*Log_OC.v("NOW " + TAG + ", thread " + Thread.currentThread().getName(), "Received request to sync folder");*/
+
             if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
                 Log_OC.e(TAG, "Not enough information provided in intent");
                 return START_NOT_STICKY;
@@ -184,24 +186,13 @@ public class OperationsService extends Service {
                 Message msg = mSyncFolderHandler.obtainMessage();
                 msg.arg1 = startId;
                 msg.obj = itemSyncKey;
+                /*Log_OC.v(
+                        "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+                        "Sync folder " + remotePath + " added to queue"
+                );*/
                 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");
-                return START_NOT_STICKY;
-            }
-            final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
-            final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
-            // Cancel operation
-            new Thread(new Runnable() {
-                public void run() {
-                    // Cancel the download
-                    mSyncFolderHandler.cancel(account,file);
-                }
-            }).start();
-
         } else {
             Message msg = mOperationsHandler.obtainMessage();
             msg.arg1 = startId;
@@ -230,7 +221,7 @@ public class OperationsService extends Service {
             e.printStackTrace();
         }
         
-        //Log_OC.wtf(TAG, "Clear mUndispatchedFinisiedOperations" );
+        //Log_OC.wtf(TAG, "Clear mUndispatchedFinishedOperations" );
         mUndispatchedFinishedOperations.clear();
         
         //Log_OC.wtf(TAG, "onDestroy end" );
@@ -272,23 +263,27 @@ public class OperationsService extends Service {
                 new ConcurrentHashMap<OnRemoteOperationListener, Handler>();
         
         private ServiceHandler mServiceHandler = null;   
-        
-        
+
         public OperationsServiceBinder(ServiceHandler serviceHandler) {
             mServiceHandler = serviceHandler;
         }
 
 
         /**
-         * Cancels an operation
+         * Cancels a pending or current synchronization.
          *
-         * TODO
+         * @param account       ownCloud account where the remote folder is stored.
+         * @param file          A folder in the queue of pending synchronizations
          */
-        public void cancel() {
-            // TODO
+        public void cancel(Account account, OCFile file) {
+            /*Log_OC.v(
+                    "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+                    "Received request to cancel folder " + file.getRemotePath()
+            );*/
+            mSyncFolderHandler.cancel(account, file);
         }
-        
-        
+
+
         public void clearListeners() {
             
             mBoundListeners.clear();