AbstractList<String> requestedDownloads = new Vector<String>(); // dvelasco: now this always contains just one element, but that can change in a near future (download of multiple selection)
String downloadKey = buildRemoteName(account, file);
try {
- DownloadFileOperation newDownload = new DownloadFileOperation(account, file, (FileDownloaderBinder) mBinder);
+ DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
mPendingDownloads.putIfAbsent(downloadKey, newDownload);
+ newDownload.addDatatransferProgressListener(this);
+ newDownload.addDatatransferProgressListener((FileDownloaderBinder)mBinder);
requestedDownloads.add(downloadKey);
sendBroadcastNewDownload(newDownload);
public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
int percent = (int)(100.0*((double)totalTransferredSoFar)/((double)totalToTransfer));
if (percent != mLastPercent) {
- mNotification.contentView.setProgressBar(R.id.status_progress, 100, percent, totalToTransfer < 0);
- String text = String.format(getString(R.string.downloader_download_in_progress_content), percent, fileName);
- mNotification.contentView.setTextViewText(R.id.status_text, text);
- mNotificationManager.notify(R.string.downloader_download_in_progress_ticker, mNotification);
+ mNotification.contentView.setProgressBar(R.id.status_progress, 100, percent, totalToTransfer < 0);
+ String text = String.format(getString(R.string.downloader_download_in_progress_content), percent, fileName);
+ mNotification.contentView.setTextViewText(R.id.status_text, text);
+ mNotificationManager.notify(R.string.downloader_download_in_progress_ticker, mNotification);
}
mLastPercent = percent;
}
package com.owncloud.android.operations;
import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.oc_framework.network.webdav.OnDatatransferProgressListener;
private Account mAccount;
private OCFile mFile;
- private OnDatatransferProgressListener mDatatransferProgressListener;
+ private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private long mModificationTimestamp = 0;
private DownloadRemoteFileOperation mDownloadOperation;
- public DownloadFileOperation(Account account, OCFile file, OnDatatransferProgressListener listener) {
+ public DownloadFileOperation(Account account, OCFile file) {
if (account == null)
throw new IllegalArgumentException("Illegal null account in DownloadFileOperation creation");
if (file == null)
mAccount = account;
mFile = file;
- mDatatransferProgressListener = listener;
}
/// perform the download
mDownloadOperation = new DownloadRemoteFileOperation(remoteFile, tmpFolder);
- mDownloadOperation.addDatatransferProgressListener(mDatatransferProgressListener);
+ Iterator<OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
+ while (listener.hasNext()) {
+ mDownloadOperation.addDatatransferProgressListener(listener.next());
+ }
result = mDownloadOperation.execute(client);
if (result.isSuccess()) {
}
+ public void addDatatransferProgressListener (OnDatatransferProgressListener listener) {
+ synchronized (mDataTransferListeners) {
+ mDataTransferListeners.add(listener);
+ }
+ }
+
+ public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) {
+ synchronized (mDataTransferListeners) {
+ mDataTransferListeners.remove(listener);
+ }
+ }
+
}