X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/4c50eb4d2dd1fba177d743315ae52223430db8cb..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 5e80f5d3..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; @@ -198,6 +199,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis * @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()) { @@ -213,6 +215,55 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } } } + + + /** + * 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) { + if (!file.isDirectory()) { + target = mPendingDownloads.get(targetKey); + } else { + // nothing to do for directories, right now + } + } + if (target != null) { + target.removeDatatransferProgressListener(listener); + } + } + } @@ -301,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());