Merge pull request #5506 from ByteHamster/fix-cover-mobile
Fix loading cover images on mobile when not allowed
This commit is contained in:
commit
47034dfbab
|
@ -11,7 +11,6 @@ import com.bumptech.glide.Registry;
|
||||||
import com.bumptech.glide.annotation.GlideModule;
|
import com.bumptech.glide.annotation.GlideModule;
|
||||||
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.StringLoader;
|
|
||||||
import com.bumptech.glide.module.AppGlideModule;
|
import com.bumptech.glide.module.AppGlideModule;
|
||||||
|
|
||||||
import de.danoeh.antennapod.model.feed.EmbeddedChapterImage;
|
import de.danoeh.antennapod.model.feed.EmbeddedChapterImage;
|
||||||
|
@ -43,7 +42,7 @@ public class ApGlideModule extends AppGlideModule {
|
||||||
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
|
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
|
||||||
registry.replace(String.class, InputStream.class, new MetadataRetrieverLoader.Factory(context));
|
registry.replace(String.class, InputStream.class, new MetadataRetrieverLoader.Factory(context));
|
||||||
registry.append(String.class, InputStream.class, new ApOkHttpUrlLoader.Factory());
|
registry.append(String.class, InputStream.class, new ApOkHttpUrlLoader.Factory());
|
||||||
registry.append(String.class, InputStream.class, new StringLoader.StreamFactory());
|
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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package de.danoeh.antennapod.core.glide;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import com.bumptech.glide.load.model.ModelLoader;
|
||||||
|
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||||
|
import com.bumptech.glide.load.model.MultiModelLoaderFactory;
|
||||||
|
import com.bumptech.glide.load.model.StringLoader;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StringLoader that does not handle http/https urls. Used to avoid fallback to StringLoader when
|
||||||
|
* AntennaPod blocks mobile image loading.
|
||||||
|
*/
|
||||||
|
public final class NoHttpStringLoader extends StringLoader<InputStream> {
|
||||||
|
|
||||||
|
public static class StreamFactory implements ModelLoaderFactory<String, InputStream> {
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ModelLoader<String, InputStream> build(@NonNull MultiModelLoaderFactory multiFactory) {
|
||||||
|
return new NoHttpStringLoader(multiFactory.build(Uri.class, InputStream.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void teardown() {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoHttpStringLoader(ModelLoader<Uri, InputStream> uriLoader) {
|
||||||
|
super(uriLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handles(@NonNull String model) {
|
||||||
|
return !model.startsWith("http") && super.handles(model);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue