diff options
Diffstat (limited to 'src/de/podfetcher/storage')
-rw-r--r-- | src/de/podfetcher/storage/DownloadReceiver.java | 24 | ||||
-rw-r--r-- | src/de/podfetcher/storage/DownloadRequester.java | 10 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/de/podfetcher/storage/DownloadReceiver.java b/src/de/podfetcher/storage/DownloadReceiver.java index 1d06b51f7..872f539ed 100644 --- a/src/de/podfetcher/storage/DownloadReceiver.java +++ b/src/de/podfetcher/storage/DownloadReceiver.java @@ -7,15 +7,18 @@ import android.content.Context; import android.content.Intent; public class DownloadReceiver extends BroadcastReceiver { + private DownloadRequester requester; + private FeedManager manager; @Override public void onReceive(Context context, Intent intent) { long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); - DownloadRequester requester = DownloadRequester.getInstance(); + requester = DownloadRequester.getInstance(); + manager = FeedManager.getInstance(); Intent item_intent = requester.getItemIntent(id); String action = item_intent.getAction(); if(action.equals(DownloadRequester.ACTION_FEED_DOWNLOAD_COMPLETED)) { - requester.removeFeedByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1)); + handleCompletedFeedDownload(context, intent); } else if(action.equals(DownloadRequester.ACTION_MEDIA_DOWNLOAD_COMPLETED)) { requester.removeMediaByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1)); } else if(action.equals(DownloadRequester.ACTION_IMAGE_DOWNLOAD_COMPLETED)) { @@ -24,4 +27,21 @@ public class DownloadReceiver extends BroadcastReceiver { PodcastApp.getInstance().getApplicationContext().sendBroadcast(item_intent); } + /** Is called whenever a Feed is Downloaded */ + private void handleCompletedFeedDownload(Context context, Intent intent) { + RSSHandler handler = new RSSHandler(); + + requester.removeFeedByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1)); + // Get Feed Information + Feed feed = manager.getFeed(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1)); + feed.file_url = DownloadRequester.getFeedfilePath() + DownloadRequester.getFeedfileName(feed.id); + feed = handler.parseFeed(feed); + // Download Feed Image if provided + if(feed.image != null) { + requester.downloadImage(context, feed.image); + } + // Update Information in Database + manager.setFeed(feed); + } + } diff --git a/src/de/podfetcher/storage/DownloadRequester.java b/src/de/podfetcher/storage/DownloadRequester.java index 6161e7ac3..407555ee0 100644 --- a/src/de/podfetcher/storage/DownloadRequester.java +++ b/src/de/podfetcher/storage/DownloadRequester.java @@ -63,7 +63,7 @@ public class DownloadRequester { } public void downloadFeed(Context context, Feed feed) { download(context, feeds, feed.download_url, - new File(context.getExternalFilesDir(FEED_DOWNLOADPATH), "feed-" + feed.id), + new File(getFeedfilePath(id), getFeedfileName(id)), true, ACTION_FEED_DOWNLOAD_COMPLETED, feed.id); } @@ -128,4 +128,12 @@ public class DownloadRequester { } return null; } + + public String getFeedfilePath() { + return context.getExternalFilesDir(FEED_DOWNLOADPATH); + } + + public String getFeedfileName(long id) { + return "feed-" + id; + } } |