summaryrefslogtreecommitdiff
path: root/src/de/podfetcher/service
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/service
parent95a7a11fa3a2b16bb0f8c164f10bc5cec885c78a (diff)
downloadAntennaPod-d7e3bfc930b62be373d6dab12257300ce6e148e7.zip
Improvements to download requester
Diffstat (limited to 'src/de/podfetcher/service')
-rw-r--r--src/de/podfetcher/service/DownloadService.java49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/de/podfetcher/service/DownloadService.java b/src/de/podfetcher/service/DownloadService.java
index 78c972fb1..bbd64d420 100644
--- a/src/de/podfetcher/service/DownloadService.java
+++ b/src/de/podfetcher/service/DownloadService.java
@@ -14,9 +14,11 @@ import java.util.concurrent.TimeUnit;
import de.podfetcher.activity.DownloadActivity;
import de.podfetcher.activity.MediaplayerActivity;
import de.podfetcher.feed.*;
+import de.podfetcher.service.PlaybackService.LocalBinder;
import de.podfetcher.storage.DownloadRequester;
import de.podfetcher.syndication.handler.FeedHandler;
import android.R;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.app.DownloadManager;
@@ -31,6 +33,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
+import android.os.Binder;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
@@ -49,14 +52,16 @@ public class DownloadService extends Service {
/** Needed to determine the duration of a media file */
private MediaPlayer mediaplayer;
private DownloadManager downloadManager;
-
+
private volatile boolean shutdownInitiated = false;
- // Objects for communication
- private final Messenger mMessenger = new Messenger(new IncomingHandler());
+ private final IBinder mBinder = new LocalBinder();
- // Message codes
- public static final int MSG_QUERY_DOWNLOADS_LEFT = 1;
+ public class LocalBinder extends Binder {
+ public DownloadService getService() {
+ return DownloadService.this;
+ }
+ }
@Override
public void onCreate() {
@@ -72,7 +77,7 @@ public class DownloadService extends Service {
@Override
public IBinder onBind(Intent intent) {
- return mMessenger.getBinder();
+ return mBinder;
}
@Override
@@ -165,22 +170,28 @@ public class DownloadService extends Service {
}
queryDownloads();
} else if (status == DownloadManager.STATUS_FAILED) {
- int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
+ int reason = c.getInt(c
+ .getColumnIndex(DownloadManager.COLUMN_REASON));
Log.d(TAG, "reason code is " + reason);
-
+
}
-
+
c.close();
}
-
};
/** Check if there's something else to download, otherwise stop */
- private synchronized void queryDownloads() {
- if (!shutdownInitiated && requester.getNumberOfDownloads() == 0) {
+ public synchronized void queryDownloads() {
+ int numOfDownloads = requester.getNumberOfDownloads();
+ if (!shutdownInitiated && numOfDownloads == 0) {
shutdownInitiated = true;
initiateShutdown();
+ } else {
+ // update notification
+ notificationBuilder.setContentText(numOfDownloads + " Downloads left");
+ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ nm.notify(NOTIFICATION_ID, notificationBuilder.getNotification());
}
}
@@ -204,20 +215,6 @@ public class DownloadService extends Service {
syncExecutor.execute(new MediaHandlerThread(media, this));
}
- class IncomingHandler extends Handler {
- @Override
- public void handleMessage(Message msg) {
- Log.d(TAG, "Received new Message.");
- switch (msg.what) {
- case MSG_QUERY_DOWNLOADS_LEFT:
- queryDownloads();
- break;
- default:
- super.handleMessage(msg);
- }
- }
- }
-
/**
* Takes a single Feed, parses the corresponding file and refreshes
* information in the manager