Merge pull request #6166 from ByteHamster/less-noisy-glide
Do not print stacktrace for image loading errors
This commit is contained in:
commit
e260056f08
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue