Downloadrequester will now no longer queue downloads which are already

running
This commit is contained in:
daniel oeh 2012-07-19 14:36:40 +02:00
parent 936aea9fc9
commit dbf16830fa

View File

@ -58,33 +58,38 @@ public class DownloadRequester {// TODO handle externalstorage missing
@SuppressLint("NewApi") @SuppressLint("NewApi")
private long download(Context context, FeedFile item, File dest) { private long download(Context context, FeedFile item, File dest) {
if (dest.exists()) { if (!isDownloadingFile(item)) {
Log.d(TAG, "File already exists. Deleting !"); if (dest.exists()) {
dest.delete(); Log.d(TAG, "File already exists. Deleting !");
} dest.delete();
Log.d(TAG, "Requesting download of url " + item.getDownload_url()); }
downloads.add(item); Log.d(TAG, "Requesting download of url " + item.getDownload_url());
DownloadManager.Request request = new DownloadManager.Request( downloads.add(item);
Uri.parse(item.getDownload_url())).setDestinationUri(Uri DownloadManager.Request request = new DownloadManager.Request(
.fromFile(dest)); Uri.parse(item.getDownload_url())).setDestinationUri(Uri
Log.d(TAG, "Version is " + currentApi); .fromFile(dest));
if (currentApi >= 11) { Log.d(TAG, "Version is " + currentApi);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); 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);
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 { } else {
request.setVisibleInDownloadsUi(false); Log.e(TAG, "URL " + item.getDownload_url() + " is already being downloaded");
request.setShowRunningNotification(false); return 0;
} }
// 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;
} }
public long downloadFeed(Context context, Feed feed) { 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) { public String getMediafilePath(Context context, FeedMedia media) {
File externalStorage = context.getExternalFilesDir(MEDIA_DOWNLOADPATH File externalStorage = context.getExternalFilesDir(MEDIA_DOWNLOADPATH
+ NumberGenerator.generateLong(media.getItem().getFeed().getTitle()) + "/"); + NumberGenerator.generateLong(media.getItem().getFeed()
.getTitle()) + "/");
return externalStorage.toString(); return externalStorage.toString();
} }