X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c301865c351da2c46c82cca268c0d7e32bc2fd83..fb8194b7ebcc386a6749bf81ec498445ef851f13:/src/com/owncloud/android/files/services/FileDownloader.java diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 51b8406a..5fd6665a 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -49,6 +49,7 @@ import android.os.Looper; import android.os.Message; import android.os.Process; import android.util.Log; +import android.widget.ProgressBar; import android.widget.RemoteViews; import com.owncloud.android.R; @@ -190,16 +191,79 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis /** - * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download + * 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 in the queue of downloads. */ public boolean isDownloading(Account account, OCFile file) { + if (account == null || file == null) return false; + String targetKey = buildRemoteName(account, file); + synchronized (mPendingDownloads) { + if (file.isDirectory()) { + // this can be slow if there are many downloads :( + Iterator it = mPendingDownloads.keySet().iterator(); + boolean found = false; + while (it.hasNext() && !found) { + found = it.next().startsWith(targetKey); + } + return found; + } else { + return (mPendingDownloads.containsKey(targetKey)); + } + } + } + + + /** + * Adds a listener interested in the progress of the download for a concrete file. + * + * @param listener Object to notify about progress of transfer. + * @param account ownCloud account holding the file of interest. + * @param file {@link OCfile} of interest for listener. + */ + public void addDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) { + if (account == null || file == null) return; + String targetKey = buildRemoteName(account, file); + DownloadFileOperation target = null; + synchronized (mPendingDownloads) { + if (!file.isDirectory()) { + target = mPendingDownloads.get(targetKey); + } else { + // nothing to do for directories, right now + } + } + if (target != null) { + target.addDatatransferProgressListener(listener); + } + } + + + /** + * Removes a listener interested in the progress of the download for a concrete file. + * + * @param listener Object to notify about progress of transfer. + * @param account ownCloud account holding the file of interest. + * @param file {@link OCfile} of interest for listener. + */ + public void removeDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) { + if (account == null || file == null) return; + String targetKey = buildRemoteName(account, file); + DownloadFileOperation target = null; synchronized (mPendingDownloads) { - return (mPendingDownloads.containsKey(buildRemoteName(account, file))); + if (!file.isDirectory()) { + target = mPendingDownloads.get(targetKey); + } else { + // nothing to do for directories, right now + } + } + if (target != null) { + target.removeDatatransferProgressListener(listener); } } + } @@ -288,6 +352,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis file.setLastSyncDateForProperties(syncDate); file.setLastSyncDateForData(syncDate); file.setModificationTimestamp(mCurrentDownload.getModificationTimestamp()); + file.setModificationTimestampAtLastSyncForData(mCurrentDownload.getModificationTimestamp()); // file.setEtag(mCurrentDownload.getEtag()); // TODO Etag, where available file.setMimetype(mCurrentDownload.getMimeType()); file.setStoragePath(mCurrentDownload.getSavePath()); @@ -380,7 +445,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis end.putExtra(ACCOUNT_NAME, download.getAccount().name); end.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath()); end.putExtra(EXTRA_FILE_PATH, download.getSavePath()); - sendBroadcast(end); + sendStickyBroadcast(end); } @@ -390,11 +455,11 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis * @param download Added download operation */ private void sendBroadcastNewDownload(DownloadFileOperation download) { - Intent end = new Intent(DOWNLOAD_ADDED_MESSAGE); - /*end.putExtra(ACCOUNT_NAME, download.getAccount().name); - end.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());*/ - end.putExtra(EXTRA_FILE_PATH, download.getSavePath()); - sendBroadcast(end); + Intent added = new Intent(DOWNLOAD_ADDED_MESSAGE); + /*added.putExtra(ACCOUNT_NAME, download.getAccount().name); + added.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());*/ + added.putExtra(EXTRA_FILE_PATH, download.getSavePath()); + sendStickyBroadcast(added); } }