diff options
Diffstat (limited to 'ui/glide')
-rw-r--r-- | ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApGlideModule.java | 2 | ||||
-rw-r--r-- | ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java | 42 |
2 files changed, 32 insertions, 12 deletions
diff --git a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApGlideModule.java b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApGlideModule.java index 132ed4901..69294ff41 100644 --- a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApGlideModule.java +++ b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApGlideModule.java @@ -49,6 +49,6 @@ public class ApGlideModule extends AppGlideModule { registry.append(String.class, InputStream.class, new ApOkHttpUrlLoader.Factory()); registry.append(String.class, InputStream.class, new NoHttpStringLoader.StreamFactory()); - registry.append(EmbeddedChapterImage.class, ByteBuffer.class, new ChapterImageModelLoader.Factory()); + registry.append(EmbeddedChapterImage.class, ByteBuffer.class, new ChapterImageModelLoader.Factory(context)); } } diff --git a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java index 3f6aa7c48..84e1d07a6 100644 --- a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java +++ b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java @@ -1,5 +1,8 @@ package de.danoeh.antennapod.ui.glide; +import android.content.ContentResolver; +import android.content.Context; +import android.net.Uri; import androidx.annotation.NonNull; import com.bumptech.glide.Priority; import com.bumptech.glide.load.DataSource; @@ -22,12 +25,17 @@ import okhttp3.Response; import org.apache.commons.io.IOUtils; public final class ChapterImageModelLoader implements ModelLoader<EmbeddedChapterImage, ByteBuffer> { - public static class Factory implements ModelLoaderFactory<EmbeddedChapterImage, ByteBuffer> { + private final Context context; + + public Factory(Context context) { + this.context = context; + } + @NonNull @Override public ModelLoader<EmbeddedChapterImage, ByteBuffer> build(@NonNull MultiModelLoaderFactory unused) { - return new ChapterImageModelLoader(); + return new ChapterImageModelLoader(context); } @Override @@ -36,12 +44,16 @@ public final class ChapterImageModelLoader implements ModelLoader<EmbeddedChapte } } + private final Context context; + + public ChapterImageModelLoader(Context context) { + this.context = context; + } + @Override - public LoadData<ByteBuffer> buildLoadData(@NonNull EmbeddedChapterImage model, - int width, - int height, - @NonNull Options options) { - return new LoadData<>(new ObjectKey(model), new EmbeddedImageFetcher(model)); + public LoadData<ByteBuffer> buildLoadData(@NonNull EmbeddedChapterImage model, int width, + int height, @NonNull Options options) { + return new LoadData<>(new ObjectKey(model), new EmbeddedImageFetcher(model, context)); } @Override @@ -51,9 +63,11 @@ public final class ChapterImageModelLoader implements ModelLoader<EmbeddedChapte static class EmbeddedImageFetcher implements DataFetcher<ByteBuffer> { private final EmbeddedChapterImage image; + private final Context context; - public EmbeddedImageFetcher(EmbeddedChapterImage image) { + public EmbeddedImageFetcher(EmbeddedChapterImage image, Context context) { this.image = image; + this.context = context; } @Override @@ -61,9 +75,15 @@ public final class ChapterImageModelLoader implements ModelLoader<EmbeddedChapte BufferedInputStream stream = null; try { - if (image.getMedia().localFileAvailable()) { - File localFile = new File(image.getMedia().getLocalMediaUrl()); - stream = new BufferedInputStream(new FileInputStream(localFile)); + boolean isLocalFeed = image.getMedia().getStreamUrl().startsWith(ContentResolver.SCHEME_CONTENT); + if (isLocalFeed || image.getMedia().localFileAvailable()) { + if (isLocalFeed) { + Uri uri = Uri.parse(image.getMedia().getStreamUrl()); + stream = new BufferedInputStream(context.getContentResolver().openInputStream(uri)); + } else { + File localFile = new File(image.getMedia().getLocalMediaUrl()); + stream = new BufferedInputStream(new FileInputStream(localFile)); + } IOUtils.skip(stream, image.getPosition()); byte[] imageContent = new byte[image.getLength()]; IOUtils.read(stream, imageContent, 0, image.getLength()); |