summaryrefslogtreecommitdiff
path: root/src/de/danoeh
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/danoeh')
-rw-r--r--src/de/danoeh/antennapod/storage/DownloadRequester.java58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java
index 508df0a8c..e5a980f22 100644
--- a/src/de/danoeh/antennapod/storage/DownloadRequester.java
+++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java
@@ -58,33 +58,38 @@ public class DownloadRequester {// TODO handle externalstorage missing
@SuppressLint("NewApi")
private long download(Context context, FeedFile item, File dest) {
- if (dest.exists()) {
- Log.d(TAG, "File already exists. Deleting !");
- dest.delete();
- }
- Log.d(TAG, "Requesting download of url " + item.getDownload_url());
- downloads.add(item);
- DownloadManager.Request request = new DownloadManager.Request(
- Uri.parse(item.getDownload_url())).setDestinationUri(Uri
- .fromFile(dest));
- Log.d(TAG, "Version is " + currentApi);
- if (currentApi >= 11) {
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
- } else {
- request.setVisibleInDownloadsUi(false);
- request.setShowRunningNotification(false);
- }
+ if (!isDownloadingFile(item)) {
+ if (dest.exists()) {
+ Log.d(TAG, "File already exists. Deleting !");
+ dest.delete();
+ }
+ Log.d(TAG, "Requesting download of url " + item.getDownload_url());
+ downloads.add(item);
+ DownloadManager.Request request = new DownloadManager.Request(
+ Uri.parse(item.getDownload_url())).setDestinationUri(Uri
+ .fromFile(dest));
+ Log.d(TAG, "Version is " + currentApi);
+ if (currentApi >= 11) {
+ request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
+ } else {
+ request.setVisibleInDownloadsUi(false);
+ request.setShowRunningNotification(false);
+ }
- // TODO Set Allowed Network Types
- DownloadManager manager = (DownloadManager) context
- .getSystemService(Context.DOWNLOAD_SERVICE);
+ // TODO Set Allowed Network Types
+ DownloadManager manager = (DownloadManager) context
+ .getSystemService(Context.DOWNLOAD_SERVICE);
- long downloadId = manager.enqueue(request);
- item.setDownloadId(downloadId);
- item.setFile_url(dest.toString());
- context.startService(new Intent(context, DownloadService.class));
- context.sendBroadcast(new Intent(ACTION_DOWNLOAD_QUEUED));
- return downloadId;
+ long downloadId = manager.enqueue(request);
+ item.setDownloadId(downloadId);
+ item.setFile_url(dest.toString());
+ context.startService(new Intent(context, DownloadService.class));
+ context.sendBroadcast(new Intent(ACTION_DOWNLOAD_QUEUED));
+ return downloadId;
+ } else {
+ Log.e(TAG, "URL " + item.getDownload_url() + " is already being downloaded");
+ return 0;
+ }
}
public long downloadFeed(Context context, Feed feed) {
@@ -203,7 +208,8 @@ public class DownloadRequester {// TODO handle externalstorage missing
public String getMediafilePath(Context context, FeedMedia media) {
File externalStorage = context.getExternalFilesDir(MEDIA_DOWNLOADPATH
- + NumberGenerator.generateLong(media.getItem().getFeed().getTitle()) + "/");
+ + NumberGenerator.generateLong(media.getItem().getFeed()
+ .getTitle()) + "/");
return externalStorage.toString();
}