From 955d296638b240d8bbf4be8cce4b27485ac4c517 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 25 Feb 2013 10:47:37 +0100 Subject: Implemented EventDistributor --- .../service/download/DownloadService.java | 36 +++++----------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'src/de/danoeh/antennapod/service/download/DownloadService.java') diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index d42e7ebc0..712c15a77 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -51,6 +51,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.DownloadActivity; import de.danoeh.antennapod.activity.DownloadLogActivity; import de.danoeh.antennapod.asynctask.DownloadStatus; +import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.feed.FeedFile; import de.danoeh.antennapod.feed.FeedImage; @@ -77,7 +78,6 @@ public class DownloadService extends Service { /** Extra for ACTION_CANCEL_DOWNLOAD */ public static final String EXTRA_DOWNLOAD_URL = "downloadUrl"; - public static final String ACTION_DOWNLOAD_HANDLED = "action.de.danoeh.antennapod.service.download_handled"; /** * Sent by the DownloadService when the content of the downloads list * changes. @@ -89,12 +89,6 @@ public class DownloadService extends Service { /** Extra for ACTION_ENQUEUE_DOWNLOAD intent. */ public static final String EXTRA_REQUEST = "request"; - // Download types for ACTION_DOWNLOAD_HANDLED - public static final String EXTRA_DOWNLOAD_TYPE = "extra.de.danoeh.antennapod.service.downloadType"; - public static final int DOWNLOAD_TYPE_FEED = 1; - public static final int DOWNLOAD_TYPE_MEDIA = 2; - public static final int DOWNLOAD_TYPE_IMAGE = 3; - private CopyOnWriteArrayList completedDownloads; private ExecutorService syncExecutor; @@ -462,7 +456,7 @@ public class DownloadService extends Service { Log.e(TAG, "Download failed"); saveDownloadStatus(status); } - sendDownloadHandledIntent(getDownloadType(download)); + sendDownloadHandledIntent(); downloadsBeingHandled -= 1; } } @@ -504,24 +498,8 @@ public class DownloadService extends Service { manager.addDownloadStatus(this, status); } - /** Returns correct value for EXTRA_DOWNLOAD_TYPE. */ - private int getDownloadType(FeedFile f) { - if (f.getClass() == Feed.class) { - return DOWNLOAD_TYPE_FEED; - } else if (f.getClass() == FeedImage.class) { - return DOWNLOAD_TYPE_IMAGE; - } else if (f.getClass() == FeedMedia.class) { - return DOWNLOAD_TYPE_MEDIA; - } else { - return 0; - } - } - - private void sendDownloadHandledIntent(int type) { - Intent intent = new Intent(ACTION_DOWNLOAD_HANDLED); - intent.putExtra(EXTRA_DOWNLOAD_TYPE, type); - - sendBroadcast(intent); + private void sendDownloadHandledIntent() { + EventDistributor.getInstance().sendDownloadHandledBroadcast(); } /** @@ -726,7 +704,7 @@ public class DownloadService extends Service { saveDownloadStatus(new DownloadStatus(savedFeed, savedFeed.getHumanReadableIdentifier(), reason, successful, reasonDetailed)); - sendDownloadHandledIntent(DOWNLOAD_TYPE_FEED); + sendDownloadHandledIntent(); downloadsBeingHandled -= 1; handler.post(new Runnable() { @@ -803,7 +781,7 @@ public class DownloadService extends Service { image.setDownloaded(true); saveDownloadStatus(status); - sendDownloadHandledIntent(DOWNLOAD_TYPE_IMAGE); + sendDownloadHandledIntent(); manager.setFeedImage(DownloadService.this, image); if (image.getFeed() != null) { manager.setFeed(DownloadService.this, image.getFeed()); @@ -867,7 +845,7 @@ public class DownloadService extends Service { } saveDownloadStatus(status); - sendDownloadHandledIntent(DOWNLOAD_TYPE_MEDIA); + sendDownloadHandledIntent(); if (chaptersRead) { manager.setFeedItem(DownloadService.this, media.getItem()); } else { -- cgit v1.2.3