diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-08-08 16:04:42 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-08-08 16:04:42 +0200 |
commit | b69bd01fe752839b4e0f2e7a5ef9822324d6955d (patch) | |
tree | 98eaba3af1a1477777bbc7941ae5485957d0c149 /src/de | |
parent | 8dc740bb8f5b6149d6d0c70a00d4f4831f33a427 (diff) | |
download | AntennaPod-b69bd01fe752839b4e0f2e7a5ef9822324d6955d.zip |
Use feed image if media file has no image
closes #484
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/danoeh/antennapod/asynctask/PicassoImageResource.java | 12 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/asynctask/PicassoProvider.java | 12 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/feed/FeedMedia.java | 18 |
3 files changed, 38 insertions, 4 deletions
diff --git a/src/de/danoeh/antennapod/asynctask/PicassoImageResource.java b/src/de/danoeh/antennapod/asynctask/PicassoImageResource.java index 84179cfcb..26f9d9278 100644 --- a/src/de/danoeh/antennapod/asynctask/PicassoImageResource.java +++ b/src/de/danoeh/antennapod/asynctask/PicassoImageResource.java @@ -18,8 +18,20 @@ public interface PicassoImageResource { */ public static final String SCHEME_MEDIA = "media"; + + /** + * Parameter key for an encoded fallback Uri. This Uri MUST point to a local image file + */ + public static final String PARAM_FALLBACK = "fallback"; + /** * Returns a Uri to the image or null if no image is available. + * <p/> + * The Uri can either be an HTTP-URL, a URL pointing to a local image file or + * a non-image file (see SCHEME_MEDIA for more details). + * <p/> + * The Uri can also have an optional fallback-URL if loading the default URL + * failed (see PARAM_FALLBACK). */ public Uri getImageUri(); } diff --git a/src/de/danoeh/antennapod/asynctask/PicassoProvider.java b/src/de/danoeh/antennapod/asynctask/PicassoProvider.java index 9ecf87023..54aa3178c 100644 --- a/src/de/danoeh/antennapod/asynctask/PicassoProvider.java +++ b/src/de/danoeh/antennapod/asynctask/PicassoProvider.java @@ -127,14 +127,22 @@ public class PicassoProvider { mmr.setDataSource(uri.getPath()); byte[] data = mmr.getEmbeddedPicture(); mmr.release(); + if (data != null) { return new Response(new ByteArrayInputStream(data), true, data.length); } else { - return null; + + // check for fallback Uri + String fallback = Uri.decode(Uri.parse(uri.getQueryParameter(PicassoImageResource.PARAM_FALLBACK)).getPath()); + if (fallback != null) { + File imageFile = new File(fallback); + return new Response(new BufferedInputStream(new FileInputStream(imageFile)), true, imageFile.length()); + } else { + return null; + } } } } - return okHttpDownloader.load(uri, b); } } diff --git a/src/de/danoeh/antennapod/feed/FeedMedia.java b/src/de/danoeh/antennapod/feed/FeedMedia.java index f555654d0..9298ebe8a 100644 --- a/src/de/danoeh/antennapod/feed/FeedMedia.java +++ b/src/de/danoeh/antennapod/feed/FeedMedia.java @@ -386,9 +386,23 @@ public class FeedMedia extends FeedFile implements Playable { @Override public Uri getImageUri() { + final Uri feedImgUri = getFeedImageUri(); + if (localFileAvailable()) { - return new Uri.Builder().scheme(SCHEME_MEDIA).encodedPath(getLocalMediaUrl()).build(); - } else if (item != null && item.getFeed() != null) { + Uri.Builder builder = new Uri.Builder(); + builder.scheme(SCHEME_MEDIA) + .encodedPath(getLocalMediaUrl()); + if (feedImgUri != null) { + builder.appendQueryParameter(PARAM_FALLBACK, feedImgUri.toString()); + } + return builder.build(); + } else { + return feedImgUri; + } + } + + private Uri getFeedImageUri() { + if (item != null && item.getFeed() != null) { return item.getFeed().getImageUri(); } else { return null; |