parent
8dc740bb8f
commit
b69bd01fe7
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue