summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/asynctask
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2014-04-01 22:53:18 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2014-04-01 22:53:18 +0200
commitc37b67172e929289ffb8fe5e901661f4456abaae (patch)
tree0825759715295085832c52c798fd345e55229e35 /src/de/danoeh/antennapod/asynctask
parent9abf27ca2f32240206d1dae3c55d2046372abf3f (diff)
downloadAntennaPod-c37b67172e929289ffb8fe5e901661f4456abaae.zip
Added navigation drawer + new episodes fragment
Diffstat (limited to 'src/de/danoeh/antennapod/asynctask')
-rw-r--r--src/de/danoeh/antennapod/asynctask/DownloadObserver.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/de/danoeh/antennapod/asynctask/DownloadObserver.java b/src/de/danoeh/antennapod/asynctask/DownloadObserver.java
index 40388cde5..adcac1569 100644
--- a/src/de/danoeh/antennapod/asynctask/DownloadObserver.java
+++ b/src/de/danoeh/antennapod/asynctask/DownloadObserver.java
@@ -25,7 +25,7 @@ public class DownloadObserver {
*/
public static final int WAITING_INTERVAL_MS = 1000;
- private final Activity activity;
+ private volatile Activity activity;
private final Handler handler;
private final Callback callback;
@@ -57,12 +57,16 @@ public class DownloadObserver {
public void onResume() {
if (BuildConfig.DEBUG) Log.d(TAG, "DownloadObserver resumed");
activity.registerReceiver(contentChangedReceiver, new IntentFilter(DownloadService.ACTION_DOWNLOADS_CONTENT_CHANGED));
- activity.bindService(new Intent(activity, DownloadService.class), mConnection, 0);
+ connectToDownloadService();
}
public void onPause() {
if (BuildConfig.DEBUG) Log.d(TAG, "DownloadObserver paused");
- activity.unregisterReceiver(contentChangedReceiver);
+ try {
+ activity.unregisterReceiver(contentChangedReceiver);
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ }
activity.unbindService(mConnection);
stopRefresher();
}
@@ -70,6 +74,10 @@ public class DownloadObserver {
private BroadcastReceiver contentChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
+ // reconnect to DownloadService if connection has been closed
+ if (downloadService == null) {
+ connectToDownloadService();
+ }
callback.onContentChanged();
startRefresher();
}
@@ -81,6 +89,10 @@ public class DownloadObserver {
void onDownloadDataAvailable(List<Downloader> downloaderList);
}
+ private void connectToDownloadService() {
+ activity.bindService(new Intent(activity, DownloadService.class), mConnection, 0);
+ }
+
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName className) {
downloadService = null;
@@ -138,13 +150,21 @@ public class DownloadObserver {
@Override
public void run() {
callback.onContentChanged();
- List<Downloader> downloaderList = downloadService.getDownloads();
- if (downloaderList == null || downloaderList.isEmpty()) {
- Thread.currentThread().interrupt();
+ if (downloadService != null) {
+ List<Downloader> downloaderList = downloadService.getDownloads();
+ if (downloaderList == null || downloaderList.isEmpty()) {
+ Thread.currentThread().interrupt();
+ }
}
}
});
}
}
+ public void setActivity(Activity activity) {
+ if (activity == null) throw new IllegalArgumentException("activity = null");
+ this.activity = activity;
+ }
+
}
+