Re-enable embedded images
This commit is contained in:
parent
92d63a6570
commit
26cd3faffc
|
@ -4,7 +4,6 @@ import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.media.MediaMetadataRetriever;
|
import android.media.MediaMetadataRetriever;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
@ -321,12 +320,10 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEmbeddedPicture() {
|
public boolean hasEmbeddedPicture() {
|
||||||
return false;
|
if(hasEmbeddedPicture == null) {
|
||||||
// TODO: reenable!
|
checkEmbeddedPicture();
|
||||||
//if(hasEmbeddedPicture == null) {
|
}
|
||||||
// checkEmbeddedPicture();
|
return hasEmbeddedPicture;
|
||||||
//}
|
|
||||||
//return hasEmbeddedPicture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -514,20 +511,11 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri getImageUri() {
|
public String getImageLocation() {
|
||||||
if (hasEmbeddedPicture()) {
|
if (hasEmbeddedPicture()) {
|
||||||
Uri.Builder builder = new Uri.Builder();
|
return getLocalMediaUrl();
|
||||||
builder.scheme(SCHEME_MEDIA).encodedPath(getLocalMediaUrl());
|
|
||||||
|
|
||||||
if (item != null && item.getFeed() != null) {
|
|
||||||
final Uri feedImgUri = item.getFeed().getImageUri();
|
|
||||||
if (feedImgUri != null) {
|
|
||||||
builder.appendQueryParameter(PARAM_FALLBACK, feedImgUri.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
} else if(item != null) {
|
} else if(item != null) {
|
||||||
return item.getImageUri();
|
return item.getImageLocation();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -550,7 +538,7 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||||
super.setFile_url(file_url);
|
super.setFile_url(file_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEmbeddedPicture() {
|
public void checkEmbeddedPicture() {
|
||||||
if (!localFileAvailable()) {
|
if (!localFileAvailable()) {
|
||||||
hasEmbeddedPicture = Boolean.FALSE;
|
hasEmbeddedPicture = Boolean.FALSE;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.GlideBuilder;
|
import com.bumptech.glide.GlideBuilder;
|
||||||
import com.bumptech.glide.load.DecodeFormat;
|
import com.bumptech.glide.load.DecodeFormat;
|
||||||
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
|
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
|
||||||
import com.bumptech.glide.load.model.GlideUrl;
|
|
||||||
import com.bumptech.glide.module.GlideModule;
|
import com.bumptech.glide.module.GlideModule;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -27,7 +26,7 @@ public class ApGlideModule implements GlideModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerComponents(Context context, Glide glide) {
|
public void registerComponents(Context context, Glide glide) {
|
||||||
glide.register(GlideUrl.class, InputStream.class, new ApOkHttpUrlLoader.Factory());
|
glide.register(String.class, InputStream.class, new ApOkHttpUrlLoader.Factory());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,14 @@ import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
/**
|
/**
|
||||||
* @see com.bumptech.glide.integration.okhttp.OkHttpUrlLoader
|
* @see com.bumptech.glide.integration.okhttp.OkHttpUrlLoader
|
||||||
*/
|
*/
|
||||||
public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
|
public class ApOkHttpUrlLoader implements ModelLoader<String, InputStream> {
|
||||||
|
|
||||||
private static final String TAG = ApOkHttpUrlLoader.class.getSimpleName();
|
private static final String TAG = ApOkHttpUrlLoader.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default factory for {@link ApOkHttpUrlLoader}s.
|
* The default factory for {@link ApOkHttpUrlLoader}s.
|
||||||
*/
|
*/
|
||||||
public static class Factory implements ModelLoaderFactory<GlideUrl, InputStream> {
|
public static class Factory implements ModelLoaderFactory<String, InputStream> {
|
||||||
|
|
||||||
private static volatile OkHttpClient internalClient;
|
private static volatile OkHttpClient internalClient;
|
||||||
private OkHttpClient client;
|
private OkHttpClient client;
|
||||||
|
@ -66,7 +66,7 @@ public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelLoader<GlideUrl, InputStream> build(Context context, GenericLoaderFactory factories) {
|
public ModelLoader<String, InputStream> build(Context context, GenericLoaderFactory factories) {
|
||||||
return new ApOkHttpUrlLoader(client);
|
return new ApOkHttpUrlLoader(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +83,15 @@ public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataFetcher<InputStream> getResourceFetcher(GlideUrl model, int width, int height) {
|
public DataFetcher<InputStream> getResourceFetcher(String model, int width, int height) {
|
||||||
return new OkHttpStreamFetcher(client, model);
|
Log.d(TAG, "getResourceFetcher() called with: " + "model = [" + model + "], width = ["
|
||||||
|
+ width + "], height = [" + height + "]");
|
||||||
|
if(model.startsWith("/")) {
|
||||||
|
return new AudioCoverFetcher(model);
|
||||||
|
} else {
|
||||||
|
GlideUrl url = new GlideUrl(model);
|
||||||
|
return new OkHttpStreamFetcher(client, url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NetworkAllowanceInterceptor implements Interceptor {
|
private static class NetworkAllowanceInterceptor implements Interceptor {
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package de.danoeh.antennapod.core.glide;
|
||||||
|
|
||||||
|
import android.media.MediaMetadataRetriever;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Priority;
|
||||||
|
import com.bumptech.glide.load.data.DataFetcher;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
// see https://github.com/bumptech/glide/issues/699
|
||||||
|
class AudioCoverFetcher implements DataFetcher<InputStream> {
|
||||||
|
|
||||||
|
private static final String TAG = "AudioCoverFetcher";
|
||||||
|
|
||||||
|
private final String path;
|
||||||
|
|
||||||
|
public AudioCoverFetcher(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getId() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public InputStream loadData(Priority priority) throws Exception {
|
||||||
|
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
||||||
|
try {
|
||||||
|
retriever.setDataSource(path);
|
||||||
|
byte[] picture = retriever.getEmbeddedPicture();
|
||||||
|
if (picture != null) {
|
||||||
|
return new ByteArrayInputStream(picture);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
retriever.release();
|
||||||
|
}
|
||||||
|
throw new IOException("Loading embedded cover did not work");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void cleanup() {
|
||||||
|
// nothing to clean up
|
||||||
|
}
|
||||||
|
@Override public void cancel() {
|
||||||
|
// cannot cancel
|
||||||
|
}
|
||||||
|
}
|
|
@ -1009,7 +1009,7 @@ public class DownloadService extends Service {
|
||||||
}
|
}
|
||||||
media.setDownloaded(true);
|
media.setDownloaded(true);
|
||||||
media.setFile_url(request.getDestination());
|
media.setFile_url(request.getDestination());
|
||||||
media.setHasEmbeddedPicture(null);
|
media.checkEmbeddedPicture(); // enforce check
|
||||||
|
|
||||||
// check if file has chapters
|
// check if file has chapters
|
||||||
ChapterUtils.loadChaptersFromFileUrl(media);
|
ChapterUtils.loadChaptersFromFileUrl(media);
|
||||||
|
|
Loading…
Reference in New Issue