\r
import java.io.File;\r
import java.io.IOException;\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
private long mTotalDownloadSize;\r
private long mCurrentDownlodSize;\r
private Notification mNotification;\r
+ \r
+ /**\r
+ * Static map with the files being download and the path to the temporal file were are download\r
+ */\r
+ private static Map<String, String> mDownloadsInProgress = Collections.synchronizedMap(new HashMap<String, String>());\r
+ \r
+ /**\r
+ * Returns True when the file referred by 'remotePath' in the ownCloud account 'account' is downloading\r
+ */\r
+ public static boolean isDownloading(Account account, String remotePath) {\r
+ return (mDownloadsInProgress.get(buildRemoteName(account.name, remotePath)) != null);\r
+ }\r
+ \r
+ /**\r
+ * Builds a key for mDownloadsInProgress from the accountName and remotePath\r
+ */\r
+ private static String buildRemoteName(String accountName, String remotePath) {\r
+ return accountName + remotePath;\r
+ }\r
\r
+ \r
private final class ServiceHandler extends Handler {\r
public ServiceHandler(Looper looper) {\r
super(looper);\r
// download in a temporal file\r
File tmpFile = new File(getTemporalPath() + mAccount.name + mFilePath);\r
tmpFile.getParentFile().mkdirs();\r
+ mDownloadsInProgress.put(buildRemoteName(mAccount.name, mRemotePath), tmpFile.getAbsolutePath());\r
\r
boolean download_result = false;\r
File newFile = null;\r
}\r
}\r
\r
+ mDownloadsInProgress.remove(buildRemoteName(mAccount.name, mRemotePath));\r
+ \r
mNotificationMngr.cancel(1);\r
Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);\r
end.putExtra(EXTRA_DOWNLOAD_RESULT, download_result);\r