Show the download-in-progress icon in the folder as soon as the SynchronizeFolderOper...
authorDavid A. Velasco <dvelasco@solidgear.es>
Tue, 16 Dec 2014 09:42:55 +0000 (10:42 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Tue, 16 Dec 2014 09:42:55 +0000 (10:42 +0100)
src/com/owncloud/android/services/OperationsService.java
src/com/owncloud/android/ui/activity/ComponentsGetter.java
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

index eef9362..6e70a8c 100644 (file)
@@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentMap;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.services.FileDownloader;
 import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
@@ -51,6 +51,7 @@ import com.owncloud.android.operations.RenameFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.operations.SynchronizeFolderOperation;
 import com.owncloud.android.operations.UnshareLinkOperation;
+import com.owncloud.android.utils.FileStorageUtils;
 
 import android.accounts.Account;
 import android.accounts.AccountsException;
@@ -179,6 +180,7 @@ public class OperationsService extends Service {
             Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
             if (itemToQueue != null) {
                 mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation)itemToQueue.second);
+                sendBroadcastNewSyncFolder(account, remotePath);
                 Message msg = mSyncFolderHandler.obtainMessage();
                 msg.arg1 = startId;
                 msg.obj = itemSyncKey;
@@ -203,6 +205,19 @@ public class OperationsService extends Service {
         return START_NOT_STICKY;
     }
 
+    /**
+     * TODO remove this method when "folder synchronization" replaces "folder download"; this is a fast and ugly 
+     * patch. 
+     */
+    private void sendBroadcastNewSyncFolder(Account account, String remotePath) {
+        Intent added = new Intent(FileDownloader.getDownloadAddedMessage());
+        added.putExtra(FileDownloader.ACCOUNT_NAME, account.name);
+        added.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath);
+        added.putExtra(FileDownloader.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath);
+        sendStickyBroadcast(added);
+    }
+
+
     @Override
     public void onDestroy() {
         //Log_OC.wtf(TAG, "onDestroy init" );
@@ -359,6 +374,19 @@ public class OperationsService extends Service {
                 //Log_OC.wtf(TAG, "Not finished yet");
             }
         }
+        
+        
+        /**
+         * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download.
+         * 
+         * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting to download. 
+         * 
+         * @param account       ownCloud account where the remote file is stored.
+         * @param file          A file that could be affected 
+         */
+        public boolean isSynchronizing(Account account, String remotePath) {
+            return mSyncFolderHandler.isSynchronizing(account, remotePath);
+        }
 
     }
 
@@ -389,6 +417,16 @@ public class OperationsService extends Service {
             mService = service;
         }
 
+        
+        public boolean isSynchronizing(Account account, String remotePath) {
+            if (account == null || remotePath == null) return false;
+            String targetKey = buildRemoteName(account, remotePath);
+            synchronized (mPendingOperations) {
+                return (mPendingOperations.containsKey(targetKey));
+            }
+        }
+        
+
         @Override
         public void handleMessage(Message msg) {
             Pair<Account, String> itemSyncKey = (Pair<Account, String>) msg.obj;
index 076a6cb..2916ac3 100644 (file)
@@ -22,28 +22,31 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.files.FileOperationsHelper;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
+import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
 
 public interface ComponentsGetter {
 
     /**
-     * Callback method invoked when the parent activity is fully created to get a reference to the FileDownloader service API.
-     * 
-     * @return  Directory to list firstly. Can be NULL.
+     * To be invoked when the parent activity is fully created to get a reference  to the FileDownloader service API.
      */
     public FileDownloaderBinder getFileDownloaderBinder();
 
     
     /**
-     * Callback method invoked when the parent activity is fully created to get a reference to the FileUploader service API.
-     * 
-     * @return  Directory to list firstly. Can be NULL.
+     * To be invoked when the parent activity is fully created to get a reference to the FileUploader service API.
      */
     public FileUploaderBinder getFileUploaderBinder();
 
     
+    /**
+     * To be invoked when the parent activity is fully created to get a reference to the OperationsSerivce service API.
+     */
+    public OperationsServiceBinder getOperationsServiceBinder();
+
     
     public FileDataStorageManager getStorageManager();
     
     public FileOperationsHelper getFileOperationsHelper();
 
+
 }
index 1df1211..c89ef3b 100644 (file)
@@ -47,6 +47,7 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;\r
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
+import com.owncloud.android.services.OperationsService.OperationsServiceBinder;\r
 import com.owncloud.android.ui.activity.ComponentsGetter;\r
 import com.owncloud.android.utils.DisplayUtils;\r
 import com.owncloud.android.utils.FileStorageUtils;\r
@@ -163,7 +164,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
             FileDownloaderBinder downloaderBinder = \r
                     mTransferServiceGetter.getFileDownloaderBinder();\r
             FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();\r
-            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {\r
+            OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder();\r
+            if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) ||\r
+                 (opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath()))) {\r
                 localStateView.setImageResource(R.drawable.downloading_file_indicator);\r
                 localStateView.setVisibility(View.VISIBLE);\r
             } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {\r