Added Image Download

This commit is contained in:
Daniel Oeh 2012-04-11 14:04:31 +02:00
parent d2468c5862
commit 09c7a5c7db
3 changed files with 25 additions and 15 deletions

View File

@ -118,6 +118,12 @@ public class FeedManager {
PodDBAdapter adapter = new PodDBAdapter(context);
return adapter.setFeedItem(item);
}
/** Updates information of an existing FeedImage */
public long setFeedImage(Context context, FeedImage image) {
PodDBAdapter adapter = new PodDBAdapter(context);
return adapter.setImage(image);
}
/** Get a Feed by its id */
public Feed getFeed(long id) {

View File

@ -103,23 +103,20 @@ public class DownloadService extends Service {
/** Is called whenever a Feed is downloaded */
private void handleCompletedFeedDownload(Context context, Feed feed) {
requester.removeFeed(feed);
Log.d(this.toString(), "Handling completed Feed Download");
// Get Feed Information
feed.setFile_url((new File(requester.getFeedfilePath(context), requester.getFeedfileName(feed.getId()))).toString());
// Download Feed Image if provided
if(feed.getImage() != null) {
Log.d(this.toString(), "Feed has image; Downloading....");
requester.downloadImage(context, feed.getImage());
}
syncExecutor.execute(new FeedSyncThread(feed, this));
syncExecutor.execute(new FeedSyncThread(feed, this, requester));
}
/** Is called whenever a Feed-Image is downloaded */
private void handleCompletedImageDownload(Context context, FeedImage image) {
Log.d(this.toString(), "Handling completed Image Download");
requester.removeFeedImage(image);
image.setFile_url(requester.getImagefilePath(context) + requester.getImagefileName(image.getId()));
manager.setFeedImage(this, image);
}
/** Takes a single Feed, parses the corresponding file and refreshes information in the manager */
@ -127,10 +124,12 @@ public class DownloadService extends Service {
private Feed feed;
private DownloadService service;
private DownloadRequester requester;
public FeedSyncThread(Feed feed, DownloadService service) {
public FeedSyncThread(Feed feed, DownloadService service, DownloadRequester requester) {
this.feed = feed;
this.service = service;
this.requester = requester;
}
public void run() {
@ -139,6 +138,12 @@ public class DownloadService extends Service {
feed = handler.parseFeed(feed);
Log.d(this.toString(), feed.getTitle() + " parsed");
// Download Feed Image if provided
if(feed.getImage() != null) {
Log.d(this.toString(), "Feed has image; Downloading....");
requester.downloadImage(service, feed.getImage());
}
requester.removeFeed(feed);
// Save information of feed in DB
manager.updateFeed(service, feed);
Log.d(this.toString(), "Walking through " + feed.getItems().size() + " feeditems");

View File

@ -48,6 +48,7 @@ public class DownloadRequester {
}
private void download(Context context, ArrayList<FeedFile> type, FeedFile item, File dest, boolean visibleInUI) {
type.add(item);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(item.getDownload_url()));
//request.allowScanningByMediaScanner();
@ -56,25 +57,23 @@ public class DownloadRequester {
// TODO Set Allowed Network Types
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
context.startService(new Intent(context, DownloadService.class));
item.setDownloadId(manager.enqueue(request));
type.add(item);
item.setDownloadId(manager.enqueue(request));
}
public void downloadFeed(Context context, Feed feed) {
download(context, feeds, feed,
new File(getFeedfilePath(context), getFeedfileName(feed.getId())),
new File(getFeedfilePath(context), getFeedfileName(feeds.size())),
true);
}
public void downloadImage(Context context, FeedImage image) {
download(context, images, image,
new File(getImagefilePath(context), getImagefileName(image.getId())),
new File(getImagefilePath(context), getImagefileName(images.size())),
true);
}
public void downloadMedia(Context context, FeedMedia feedmedia) {
download(context, media, feedmedia,
new File(context.getExternalFilesDir(MEDIA_DOWNLOADPATH), "media-" + feedmedia.getId()),
new File(context.getExternalFilesDir(MEDIA_DOWNLOADPATH), "media-" + media.size()),
true);
}