Coherent item cover order

This commit is contained in:
Martin Fietz 2015-04-12 13:44:00 +02:00
parent e5c03079b6
commit 15d09932da
3 changed files with 47 additions and 39 deletions

View File

@ -162,13 +162,7 @@ public class PicassoProvider {
}
if (bitmap == null) {
// check for fallback Uri
String fallbackParam = data.uri.getQueryParameter(PicassoImageResource.PARAM_FALLBACK);
if (fallbackParam != null) {
Uri fallback = Uri.parse(fallbackParam);
bitmap = decodeStreamFromFile(data, fallback);
}
Log.wtf(TAG, "THIS SHOULD NEVER EVER HAPPEN!!");
}
return new Result(bitmap, Picasso.LoadedFrom.DISK);

View File

@ -315,10 +315,10 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
@Override
public Uri getImageUri() {
if (hasItemImageDownloaded()) {
return image.getImageUri();
} else if (hasMedia()) {
if(media.hasEmbeddedPicture()) {
return media.getImageUri();
} else if (hasItemImageDownloaded()) {
return image.getImageUri();
} else if (feed != null) {
return feed.getImageUri();
} else {

View File

@ -2,9 +2,11 @@ package de.danoeh.antennapod.core.feed;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import java.util.Date;
import java.util.List;
@ -34,6 +36,7 @@ public class FeedMedia extends FeedFile implements Playable {
private String mime_type;
private volatile FeedItem item;
private Date playbackCompletionDate;
private boolean hasEmbeddedPicture;
/* Used for loading item when restoring from parcel. */
private long itemID;
@ -50,6 +53,7 @@ public class FeedMedia extends FeedFile implements Playable {
long size, String mime_type, String file_url, String download_url,
boolean downloaded, Date playbackCompletionDate, int played_duration) {
super(file_url, download_url, downloaded);
checkEmbeddedPicture();
this.id = id;
this.item = item;
this.duration = duration;
@ -61,12 +65,6 @@ public class FeedMedia extends FeedFile implements Playable {
? null : (Date) playbackCompletionDate.clone();
}
public FeedMedia(long id, FeedItem item) {
super();
this.id = id;
this.item = item;
}
@Override
public String getHumanReadableIdentifier() {
if (item != null && item.getTitle() != null) {
@ -227,18 +225,16 @@ public class FeedMedia extends FeedFile implements Playable {
return (this.position > 0);
}
public FeedImage getImage() {
if (item != null) {
return (item.hasItemImageDownloaded()) ? item.getImage() : item.getFeed().getImage();
}
return null;
}
@Override
public int describeContents() {
return 0;
}
public boolean hasEmbeddedPicture() {
Log.d(TAG, "hasEmbeddedPicture() -> " + hasEmbeddedPicture);
return this.hasEmbeddedPicture;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
@ -415,28 +411,46 @@ public class FeedMedia extends FeedFile implements Playable {
@Override
public Uri getImageUri() {
final Uri feedImgUri = getFeedImageUri();
if (localFileAvailable()) {
if (hasEmbeddedPicture) {
Uri.Builder builder = new Uri.Builder();
builder.scheme(SCHEME_MEDIA)
.encodedPath(getLocalMediaUrl());
if (feedImgUri != null) {
builder.appendQueryParameter(PARAM_FALLBACK, feedImgUri.toString());
}
builder.scheme(SCHEME_MEDIA).encodedPath(getLocalMediaUrl());
return builder.build();
} else if (item.hasItemImageDownloaded()) {
return item.getImage().getImageUri();
} else {
return feedImgUri;
return item.getImageUri();
}
}
private Uri getFeedImageUri() {
if (item != null && item.getFeed() != null) {
return item.getFeed().getImageUri();
} else {
return null;
@Override
public void setDownloaded(boolean downloaded) {
super.setDownloaded(downloaded);
checkEmbeddedPicture();
}
@Override
public void setFile_url(String file_url) {
super.setFile_url(file_url);
checkEmbeddedPicture();
}
private void checkEmbeddedPicture() {
Log.d(TAG, "checkEmbeddedPicture()");
if (!localFileAvailable()) {
hasEmbeddedPicture = false;
return;
}
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
try {
mmr.setDataSource(getLocalMediaUrl());
byte[] image = mmr.getEmbeddedPicture();
if(image != null) {
hasEmbeddedPicture = true;
}
else {
hasEmbeddedPicture = false;
}
} catch (Exception e) {
e.printStackTrace();
hasEmbeddedPicture = false;
}
}
}