summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/storage/DownloadRequester.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-24 17:59:04 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-24 17:59:04 +0200
commitb51aaf2a921bbb6446f55067d706d72087d466d2 (patch)
treeffd2941a33623781cca26ce1265e2798f9045281 /src/de/danoeh/antennapod/storage/DownloadRequester.java
parent7d990317066d102aa0bbad17361b23c2273dee17 (diff)
downloadAntennaPod-b51aaf2a921bbb6446f55067d706d72087d466d2.zip
fixed nullpointer exception
Diffstat (limited to 'src/de/danoeh/antennapod/storage/DownloadRequester.java')
-rw-r--r--src/de/danoeh/antennapod/storage/DownloadRequester.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java
index 356201a2d..90c481ebb 100644
--- a/src/de/danoeh/antennapod/storage/DownloadRequester.java
+++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java
@@ -57,16 +57,20 @@ public class DownloadRequester {// TODO handle externalstorage missing
private long download(Context context, FeedFile item, File dest) {
if (!isDownloadingFile(item)) {
if (dest.exists()) {
- if (AppConfig.DEBUG) Log.d(TAG, "File already exists. Deleting !");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "File already exists. Deleting !");
dest.delete();
}
- if (AppConfig.DEBUG) Log.d(TAG, "Requesting download of url " + item.getDownload_url());
+ if (AppConfig.DEBUG)
+ Log.d(TAG,
+ "Requesting download of url " + item.getDownload_url());
downloads.add(item);
item.setDownload_url(URLChecker.prepareURL(item.getDownload_url()));
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(item.getDownload_url())).setDestinationUri(Uri
.fromFile(dest));
- if (AppConfig.DEBUG) Log.d(TAG, "Version is " + currentApi);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Version is " + currentApi);
if (currentApi >= 11) {
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
} else {
@@ -85,7 +89,8 @@ public class DownloadRequester {// TODO handle externalstorage missing
context.sendBroadcast(new Intent(ACTION_DOWNLOAD_QUEUED));
return downloadId;
} else {
- Log.e(TAG, "URL " + item.getDownload_url() + " is already being downloaded");
+ Log.e(TAG, "URL " + item.getDownload_url()
+ + " is already being downloaded");
return 0;
}
}
@@ -115,7 +120,8 @@ public class DownloadRequester {// TODO handle externalstorage missing
* ID of the download to cancel
* */
public void cancelDownload(final Context context, final long id) {
- if (AppConfig.DEBUG) Log.d(TAG, "Cancelling download with id " + id);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Cancelling download with id " + id);
DownloadManager dm = (DownloadManager) context
.getSystemService(Context.DOWNLOAD_SERVICE);
int removed = dm.remove(id);
@@ -132,7 +138,8 @@ public class DownloadRequester {// TODO handle externalstorage missing
/** Cancels all running downloads */
public void cancelAllDownloads(Context context) {
- if (AppConfig.DEBUG) Log.d(TAG, "Cancelling all running downloads");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Cancelling all running downloads");
DownloadManager dm = (DownloadManager) context
.getSystemService(Context.DOWNLOAD_SERVICE);
for (FeedFile f : downloads) {
@@ -173,11 +180,11 @@ public class DownloadRequester {// TODO handle externalstorage missing
}
return false;
}
-
+
public boolean hasNoDownloads() {
return downloads.isEmpty();
}
-
+
public FeedFile getDownloadAt(int index) {
return downloads.get(index);
}
@@ -235,9 +242,12 @@ public class DownloadRequester {// TODO handle externalstorage missing
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
mService = ((DownloadService.LocalBinder) service).getService();
- if (AppConfig.DEBUG) Log.d(TAG, "Connection to service established");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Connection to service established");
mService.queryDownloads();
- mContext.unbindService(mConnection);
+ if (mContext != null) {
+ mContext.unbindService(mConnection);
+ }
}
public void onServiceDisconnected(ComponentName className) {
@@ -250,9 +260,9 @@ public class DownloadRequester {// TODO handle externalstorage missing
/** Notifies the DownloadService to check if there are any Downloads left */
public void notifyDownloadService(Context context) {
+ mContext = context;
context.bindService(new Intent(context, DownloadService.class),
mConnection, Context.BIND_AUTO_CREATE);
- mContext = context;
mIsBound = true;
}
}