Fixed ClassCastingException
[pub/Android/ownCloud.git] / src / com / owncloud / android / files / services / FileDownloader.java
index b01d61e..5fd6665 100644 (file)
@@ -49,6 +49,7 @@ import android.os.Looper;
 import android.os.Message;\r
 import android.os.Process;\r
 import android.util.Log;\r
+import android.widget.ProgressBar;\r
 import android.widget.RemoteViews;\r
 \r
 import com.owncloud.android.R;\r
@@ -198,6 +199,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
          * @param file          A file that could be in the queue of downloads.\r
          */\r
         public boolean isDownloading(Account account, OCFile file) {\r
+            if (account == null || file == null) return false;\r
             String targetKey = buildRemoteName(account, file);\r
             synchronized (mPendingDownloads) {\r
                 if (file.isDirectory()) {\r
@@ -213,6 +215,55 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
                 }\r
             }\r
         }\r
+\r
+        \r
+        /**\r
+         * Adds a listener interested in the progress of the download for a concrete file.\r
+         * \r
+         * @param listener      Object to notify about progress of transfer.    \r
+         * @param account       ownCloud account holding the file of interest.\r
+         * @param file          {@link OCfile} of interest for listener. \r
+         */\r
+        public void addDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {\r
+            if (account == null || file == null) return;\r
+            String targetKey = buildRemoteName(account, file);\r
+            DownloadFileOperation target = null;\r
+            synchronized (mPendingDownloads) {\r
+                if (!file.isDirectory()) {\r
+                    target = mPendingDownloads.get(targetKey);\r
+                } else {\r
+                    // nothing to do for directories, right now\r
+                }\r
+            }\r
+            if (target != null) {\r
+                target.addDatatransferProgressListener(listener);\r
+            }\r
+        }\r
+        \r
+        \r
+        /**\r
+         * Removes a listener interested in the progress of the download for a concrete file.\r
+         * \r
+         * @param listener      Object to notify about progress of transfer.    \r
+         * @param account       ownCloud account holding the file of interest.\r
+         * @param file          {@link OCfile} of interest for listener. \r
+         */\r
+        public void removeDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {\r
+            if (account == null || file == null) return;\r
+            String targetKey = buildRemoteName(account, file);\r
+            DownloadFileOperation target = null;\r
+            synchronized (mPendingDownloads) {\r
+                if (!file.isDirectory()) {\r
+                    target = mPendingDownloads.get(targetKey);\r
+                } else {\r
+                    // nothing to do for directories, right now\r
+                }\r
+            }\r
+            if (target != null) {\r
+                target.removeDatatransferProgressListener(listener);\r
+            }\r
+        }\r
+        \r
     }\r
     \r
     \r