summaryrefslogtreecommitdiff
path: root/src/de/podfetcher/storage/DownloadRequester.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-06-15 18:30:12 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-06-15 18:30:12 +0200
commitd7e3bfc930b62be373d6dab12257300ce6e148e7 (patch)
treea5652e8c08c42fb169dbea563210771e6a5602e0 /src/de/podfetcher/storage/DownloadRequester.java
parent95a7a11fa3a2b16bb0f8c164f10bc5cec885c78a (diff)
downloadAntennaPod-d7e3bfc930b62be373d6dab12257300ce6e148e7.zip
Improvements to download requester
Diffstat (limited to 'src/de/podfetcher/storage/DownloadRequester.java')
-rw-r--r--src/de/podfetcher/storage/DownloadRequester.java23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/de/podfetcher/storage/DownloadRequester.java b/src/de/podfetcher/storage/DownloadRequester.java
index 14849515e..4fcc710c0 100644
--- a/src/de/podfetcher/storage/DownloadRequester.java
+++ b/src/de/podfetcher/storage/DownloadRequester.java
@@ -62,6 +62,10 @@ public class DownloadRequester {
private long download(Context context, ArrayList<FeedFile> type,
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());
type.add(item);
DownloadManager.Request request = new DownloadManager.Request(
@@ -82,6 +86,8 @@ public class DownloadRequester {
long downloadId = manager.enqueue(request);
item.setDownloadId(downloadId);
item.setFile_url(dest.toString());
+
+ notifyDownloadService(context);
return downloadId;
}
@@ -245,22 +251,14 @@ public class DownloadRequester {
* ------------ Methods for communicating with the DownloadService
* -------------
*/
- private Messenger mService = null;
+ private DownloadService mService = null;
boolean mIsBound;
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
- mService = new Messenger(service);
-
- try {
- Message msg = Message.obtain(null,
- DownloadService.MSG_QUERY_DOWNLOADS_LEFT);
- Log.d(TAG, "Sending message to DownloadService.");
- mService.send(msg);
- } catch (RemoteException e) {
- Log.e(TAG,
- "An Exception happened while communication with the DownloadService");
- }
+ mService = ((DownloadService.LocalBinder)service).getService();
+ Log.d(TAG, "Connection to service established");
+ mService.queryDownloads();
}
public void onServiceDisconnected(ComponentName className) {
@@ -274,6 +272,7 @@ public class DownloadRequester {
context.bindService(new Intent(context, DownloadService.class),
mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
+
context.unbindService(mConnection);
mIsBound = false;
}