summaryrefslogtreecommitdiff
path: root/ui/glide
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-03-22 22:12:36 +0100
committerGitHub <noreply@github.com>2024-03-22 22:12:36 +0100
commit376c83d200859ef562d6e3de02602ef18de3e7de (patch)
tree3569dfcf309e3dc9641ea504788ef8ca630ce533 /ui/glide
parent69f0daa2e88b5ead63a95c8b6cb2e33696cd1c24 (diff)
downloadAntennaPod-376c83d200859ef562d6e3de02602ef18de3e7de.zip
Fix loading chapter images in local feeds (#7016)
Diffstat (limited to 'ui/glide')
-rw-r--r--ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApGlideModule.java2
-rw-r--r--ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java42
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());