diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-03-28 20:17:15 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-03-28 20:17:15 +0100 |
commit | ae09dbffb6746641a5658750085af08f5ff60e47 (patch) | |
tree | 846820ec7b94abb70b698fa93999f127466e4275 | |
parent | 2c68f8197b6c3048bf460df9c02eae11aabb6184 (diff) | |
download | AntennaPod-ae09dbffb6746641a5658750085af08f5ff60e47.zip |
Fixed image loading bugs
- If a feed contained items with non-unique image URLs, those images were not displayed
- Images in a list were not loaded correctly if the list contained entries without an image
-rw-r--r-- | src/de/danoeh/antennapod/asynctask/ImageLoader.java | 8 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/feed/FeedItem.java | 4 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/service/download/DownloadService.java | 57 |
3 files changed, 41 insertions, 28 deletions
diff --git a/src/de/danoeh/antennapod/asynctask/ImageLoader.java b/src/de/danoeh/antennapod/asynctask/ImageLoader.java index c49d7549b..b50502ea8 100644 --- a/src/de/danoeh/antennapod/asynctask/ImageLoader.java +++ b/src/de/danoeh/antennapod/asynctask/ImageLoader.java @@ -26,6 +26,12 @@ public class ImageLoader { public static final int IMAGE_TYPE_THUMBNAIL = 0; public static final int IMAGE_TYPE_COVER = 1; + /** + * Used by loadThumbnailBitmap and loadCoverBitmap to denote an ImageView that displays the default image resource. + * This is the case if the given source to load the image from was null or did not return any image data. + */ + private static final Object DEFAULT_IMAGE_RESOURCE_TAG = new Object(); + private Handler handler; private ExecutorService executor; @@ -122,6 +128,7 @@ public class ImageLoader { } } else { target.setImageResource(defaultCoverResource); + target.setTag(R.id.imageloader_key, DEFAULT_IMAGE_RESOURCE_TAG); } } @@ -163,6 +170,7 @@ public class ImageLoader { } } else { target.setImageResource(defaultCoverResource); + target.setTag(R.id.imageloader_key, DEFAULT_IMAGE_RESOURCE_TAG); } } diff --git a/src/de/danoeh/antennapod/feed/FeedItem.java b/src/de/danoeh/antennapod/feed/FeedItem.java index 0d46cef48..27fd0dc2c 100644 --- a/src/de/danoeh/antennapod/feed/FeedItem.java +++ b/src/de/danoeh/antennapod/feed/FeedItem.java @@ -335,7 +335,9 @@ public class FeedItem extends FeedComponent implements public void setImage(FeedImage image) { this.image = image; - image.setOwner(this); + if (image != null) { + image.setOwner(this); + } } /** diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index fbf7be071..d08c4ab6d 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -648,6 +648,9 @@ public class DownloadService extends Service { if (checkFeedData(feed) == false) { throw new InvalidFeedException(); } + + removeDuplicateImages(feed); // duplicate images have to removed because the DownloadRequester does not accept two downloads with the same download URL yet. + // Save information of feed in DB savedFeed = DBTasks.updateFeed(DownloadService.this, feed); // Download Feed Image if provided and not downloaded @@ -675,33 +678,32 @@ public class DownloadService extends Service { ); } } - if (!hasDuplicateImages(savedFeed)) { - // download FeedItem images if provided and not downloaded - for (FeedItem item : savedFeed.getItems()) { - if (item.hasItemImage() && (!item.getImage().isDownloaded())) { - if (AppConfig.DEBUG) - Log.d(TAG, "Item has image; Downloading...."); - try { - requester.downloadImage(DownloadService.this, - item.getImage()); - } catch (DownloadRequestException e) { - e.printStackTrace(); - DBWriter.addDownloadStatus( - DownloadService.this, - new DownloadStatus( - item.getImage(), - item - .getImage() - .getHumanReadableIdentifier(), - DownloadError.ERROR_REQUEST_ERROR, - false, e.getMessage() - ) - ); - } + // download FeedItem images if provided and not downloaded + for (FeedItem item : savedFeed.getItems()) { + if (item.hasItemImage() && (!item.getImage().isDownloaded())) { + if (AppConfig.DEBUG) + Log.d(TAG, "Item has image; Downloading...."); + try { + requester.downloadImage(DownloadService.this, + item.getImage()); + } catch (DownloadRequestException e) { + e.printStackTrace(); + DBWriter.addDownloadStatus( + DownloadService.this, + new DownloadStatus( + item.getImage(), + item + .getImage() + .getHumanReadableIdentifier(), + DownloadError.ERROR_REQUEST_ERROR, + false, e.getMessage() + ) + ); } } } + } catch (SAXException e) { successful = false; e.printStackTrace(); @@ -761,21 +763,22 @@ public class DownloadService extends Service { /** * Checks if the FeedItems of this feed have images that point - * to the same URL. + * to the same URL. If two FeedItems have an image that points to + * the same URL, the reference of the second item is removed, so that every image + * reference is unique. */ - private boolean hasDuplicateImages(Feed feed) { + private void removeDuplicateImages(Feed feed) { for (int x = 0; x < feed.getItems().size(); x++) { for (int y = x + 1; y < feed.getItems().size(); y++) { FeedItem item1 = feed.getItems().get(x); FeedItem item2 = feed.getItems().get(y); if (item1.hasItemImage() && item2.hasItemImage()) { if (StringUtils.equals(item1.getImage().getDownload_url(), item2.getImage().getDownload_url())) { - return true; + item2.setImage(null); } } } } - return false; } private boolean hasValidFeedItems(Feed feed) { |