diff options
author | ByteHamster <info@bytehamster.com> | 2019-01-03 15:09:30 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-01-03 15:09:30 +0100 |
commit | e360aa04efb2a1e66a65ea3d40720f190a70f2f9 (patch) | |
tree | 03c72efb2cd794e7f4e3f3c19204393014b3d175 /app/src/main | |
parent | c05f81a9f1a39b1cf9b116fffb17befa03b6b08b (diff) | |
download | AntennaPod-e360aa04efb2a1e66a65ea3d40720f190a70f2f9.zip |
Fixed flickering caused by handler
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java b/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java index 7d8ff2897..54ecdae77 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java @@ -66,42 +66,32 @@ public class CoverLoader { options = options.error(errorResource); } - Glide.with(activity) + RequestBuilder builder = Glide.with(activity) .load(uri) - .apply(options) - .into(new CoverTarget(fallbackUri, txtvPlaceholder, imgvCover, activity)); + .apply(options); + + if (fallbackUri != null && txtvPlaceholder != null && imgvCover != null) { + builder = builder.error(Glide.with(activity) + .load(fallbackUri) + .apply(options)); + } + + builder.into(new CoverTarget(txtvPlaceholder, imgvCover)); } class CoverTarget extends CustomViewTarget<ImageView, Drawable> { - - private final WeakReference<String> fallback; private final WeakReference<TextView> placeholder; private final WeakReference<ImageView> cover; - private final WeakReference<MainActivity> mainActivity; - public CoverTarget(String fallbackUri, TextView txtvPlaceholder, ImageView imgvCover, MainActivity activity) { + public CoverTarget(TextView txtvPlaceholder, ImageView imgvCover) { super(imgvCover); - fallback = new WeakReference<>(fallbackUri); placeholder = new WeakReference<>(txtvPlaceholder); cover = new WeakReference<>(imgvCover); - mainActivity = new WeakReference<>(activity); } @Override public void onLoadFailed(Drawable errorDrawable) { - String fallbackUri = fallback.get(); - TextView txtvPlaceholder = placeholder.get(); - ImageView imgvCover = cover.get(); - if (fallbackUri != null && txtvPlaceholder != null && imgvCover != null) { - MainActivity activity = mainActivity.get(); - new Handler().post(() -> Glide.with(activity) - .load(fallbackUri) - .apply(new RequestOptions() - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) - .fitCenter() - .dontAnimate()) - .into(new CoverTarget(null, txtvPlaceholder, imgvCover, activity))); - } + } @Override |