diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-10-29 11:54:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-29 11:54:50 +0200 |
commit | e260056f08e979cac2846851f32dc7db30ac0e0c (patch) | |
tree | 7f4d41c5a72a84213398c26b462883efd21ec7d6 | |
parent | a87d660698a6bd8e966e5f58640e042ccc884082 (diff) | |
parent | edcf8313465df39e2cb9236658d1f962ad14255c (diff) | |
download | AntennaPod-e260056f08e979cac2846851f32dc7db30ac0e0c.zip |
Merge pull request #6166 from ByteHamster/less-noisy-glide
Do not print stacktrace for image loading errors
4 files changed, 17 insertions, 9 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java index 09b0e978a..3dfbb6f03 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java @@ -32,6 +32,7 @@ public class ApGlideModule extends AppGlideModule { @Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { builder.setDefaultRequestOptions(RequestOptions.formatOf(DecodeFormat.PREFER_ARGB_8888)); + builder.setLogLevel(Log.WARN); @SuppressLint("UsableSpace") long spaceAvailable = context.getCacheDir().getUsableSpace(); long imageCacheSize = (spaceAvailable > 2 * GIGABYTES) ? (250 * MEGABYTES) : (50 * MEGABYTES); diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java index a0ec16578..bab50a7b4 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java @@ -12,6 +12,8 @@ import com.bumptech.glide.load.model.MultiModelLoaderFactory; import com.bumptech.glide.signature.ObjectKey; import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.model.feed.Feed; +import de.danoeh.antennapod.model.feed.FeedMedia; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Protocol; @@ -81,8 +83,11 @@ class ApOkHttpUrlLoader implements ModelLoader<String, InputStream> { @Override public boolean handles(@NonNull String model) { - // Leave content URIs to Glide's default loaders return !TextUtils.isEmpty(model) + // If the other loaders fail, do not attempt to load as web resource + && !model.startsWith(Feed.PREFIX_GENERATIVE_COVER) + && !model.startsWith(FeedMedia.FILENAME_PREFIX_EMBEDDED_COVER) + // Leave content URIs to Glide's default loaders && !model.startsWith(ContentResolver.SCHEME_CONTENT) && !model.startsWith(ContentResolver.SCHEME_ANDROID_RESOURCE); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/AudioCoverFetcher.java b/core/src/main/java/de/danoeh/antennapod/core/glide/AudioCoverFetcher.java index 9d270360a..2fffad108 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/AudioCoverFetcher.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/AudioCoverFetcher.java @@ -11,7 +11,6 @@ import com.bumptech.glide.load.DataSource; 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 @@ -26,8 +25,7 @@ class AudioCoverFetcher implements DataFetcher<InputStream> { @Override public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) { - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - try { + try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) { if (path.startsWith(ContentResolver.SCHEME_CONTENT)) { retriever.setDataSource(context, Uri.parse(path)); } else { @@ -36,12 +34,10 @@ class AudioCoverFetcher implements DataFetcher<InputStream> { byte[] picture = retriever.getEmbeddedPicture(); if (picture != null) { callback.onDataReady(new ByteArrayInputStream(picture)); - return; } - } finally { - retriever.release(); + } catch (Exception e) { + callback.onLoadFailed(e); } - callback.onLoadFailed(new IOException("Loading embedded cover did not work")); } @Override public void cleanup() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/NoHttpStringLoader.java b/core/src/main/java/de/danoeh/antennapod/core/glide/NoHttpStringLoader.java index 9cda3b1aa..fab470984 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/NoHttpStringLoader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/NoHttpStringLoader.java @@ -6,6 +6,8 @@ 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 de.danoeh.antennapod.model.feed.Feed; +import de.danoeh.antennapod.model.feed.FeedMedia; import java.io.InputStream; @@ -34,6 +36,10 @@ public final class NoHttpStringLoader extends StringLoader<InputStream> { @Override public boolean handles(@NonNull String model) { - return !model.startsWith("http") && super.handles(model); + return !model.startsWith("http") + // If the custom loaders fail, do not attempt to load with Glide internal loaders + && !model.startsWith(Feed.PREFIX_GENERATIVE_COVER) + && !model.startsWith(FeedMedia.FILENAME_PREFIX_EMBEDDED_COVER) + && super.handles(model); } } |