X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/9d3208ea0372294f606df5ddb543b2062d1eacac..a238d0635ad16d6adc97d08ef0fa89b8afb18b46:/src/eu/alefzero/owncloud/files/services/FileDownloader.java diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java index e5316b3e..c147c9d2 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/src/eu/alefzero/owncloud/files/services/FileDownloader.java @@ -2,6 +2,9 @@ package eu.alefzero.owncloud.files.services; import java.io.File; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import android.accounts.Account; import android.accounts.AccountManager; @@ -48,7 +51,27 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis private long mTotalDownloadSize; private long mCurrentDownlodSize; private Notification mNotification; + + /** + * Static map with the files being download and the path to the temporal file were are download + */ + private static Map mDownloadsInProgress = Collections.synchronizedMap(new HashMap()); + + /** + * Returns True when the file referred by 'remotePath' in the ownCloud account 'account' is downloading + */ + public static boolean isDownloading(Account account, String remotePath) { + return (mDownloadsInProgress.get(buildRemoteName(account.name, remotePath)) != null); + } + + /** + * Builds a key for mDownloadsInProgress from the accountName and remotePath + */ + private static String buildRemoteName(String accountName, String remotePath) { + return accountName + remotePath; + } + private final class ServiceHandler extends Handler { public ServiceHandler(Looper looper) { super(looper); @@ -141,6 +164,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis // download in a temporal file File tmpFile = new File(getTemporalPath() + mAccount.name + mFilePath); tmpFile.getParentFile().mkdirs(); + mDownloadsInProgress.put(buildRemoteName(mAccount.name, mRemotePath), tmpFile.getAbsolutePath()); boolean download_result = false; File newFile = null; @@ -164,6 +188,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } } + mDownloadsInProgress.remove(buildRemoteName(mAccount.name, mRemotePath)); + mNotificationMngr.cancel(1); Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE); end.putExtra(EXTRA_DOWNLOAD_RESULT, download_result);