parent
8dc740bb8f
commit
b69bd01fe7
|
@ -18,8 +18,20 @@ public interface PicassoImageResource {
|
||||||
*/
|
*/
|
||||||
public static final String SCHEME_MEDIA = "media";
|
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.
|
* 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();
|
public Uri getImageUri();
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,14 +127,22 @@ public class PicassoProvider {
|
||||||
mmr.setDataSource(uri.getPath());
|
mmr.setDataSource(uri.getPath());
|
||||||
byte[] data = mmr.getEmbeddedPicture();
|
byte[] data = mmr.getEmbeddedPicture();
|
||||||
mmr.release();
|
mmr.release();
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
return new Response(new ByteArrayInputStream(data), true, data.length);
|
return new Response(new ByteArrayInputStream(data), true, data.length);
|
||||||
} else {
|
} 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);
|
return okHttpDownloader.load(uri, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,9 +386,23 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri getImageUri() {
|
public Uri getImageUri() {
|
||||||
|
final Uri feedImgUri = getFeedImageUri();
|
||||||
|
|
||||||
if (localFileAvailable()) {
|
if (localFileAvailable()) {
|
||||||
return new Uri.Builder().scheme(SCHEME_MEDIA).encodedPath(getLocalMediaUrl()).build();
|
Uri.Builder builder = new Uri.Builder();
|
||||||
} else if (item != null && item.getFeed() != null) {
|
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();
|
return item.getFeed().getImageUri();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue