diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index d141e0239..1f95b22c6 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -1,7 +1,5 @@ package de.danoeh.antennapod.adapter; -import android.graphics.drawable.Drawable; -import android.net.Uri; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; @@ -19,9 +17,6 @@ import android.widget.ProgressBar; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.animation.GlideAnimation; -import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; import com.joanzapata.iconify.Iconify; import com.nineoldandroids.view.ViewHelper; @@ -197,7 +192,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter fallback; - private final WeakReference placeholder; - private final WeakReference cover; - - public CoverTarget(Uri fallbackUri, TextView txtvPlaceholder, ImageView imgvCover) { - super(imgvCover); - fallback = new WeakReference<>(fallbackUri); - placeholder = new WeakReference<>(txtvPlaceholder); - cover = new WeakReference<>(imgvCover); - } - - @Override - public void onLoadFailed(Exception e, Drawable errorDrawable) { - Uri fallbackUri = fallback.get(); - TextView txtvPlaceholder = placeholder.get(); - ImageView imgvCover = cover.get(); - if(fallbackUri != null && txtvPlaceholder != null && imgvCover != null) { - Glide.with(mainActivityRef.get()) - .load(fallbackUri) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) - .fitCenter() - .dontAnimate() - .into(new CoverTarget(null, txtvPlaceholder, imgvCover)); - } - } - - @Override - public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { - super.onResourceReady(drawable, anim); - TextView txtvPlaceholder = placeholder.get(); - if(txtvPlaceholder != null) { - txtvPlaceholder.setVisibility(View.INVISIBLE); - } - } - } - private View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/CoverTarget.java b/app/src/main/java/de/danoeh/antennapod/adapter/CoverTarget.java new file mode 100644 index 000000000..ba7175a9b --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/adapter/CoverTarget.java @@ -0,0 +1,61 @@ +package de.danoeh.antennapod.adapter; + +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; + +import java.lang.ref.WeakReference; + +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.core.glide.ApGlideSettings; + +/** + * Created by Tom on 3/29/16. + */ +class CoverTarget extends GlideDrawableImageViewTarget { + + private final WeakReference fallback; + private final WeakReference placeholder; + private final WeakReference cover; + private final WeakReference mainActivity; + + public CoverTarget(Uri fallbackUri, TextView txtvPlaceholder, ImageView imgvCover, MainActivity activity) { + super(imgvCover); + fallback = new WeakReference<>(fallbackUri); + placeholder = new WeakReference<>(txtvPlaceholder); + cover = new WeakReference<>(imgvCover); + mainActivity = new WeakReference<>(activity); + } + + @Override + public void onLoadFailed(Exception e, Drawable errorDrawable) { + Uri fallbackUri = fallback.get(); + TextView txtvPlaceholder = placeholder.get(); + ImageView imgvCover = cover.get(); + if (fallbackUri != null && txtvPlaceholder != null && imgvCover != null) { + MainActivity activity = mainActivity.get(); + Glide.with(activity) + .load(fallbackUri) + .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) + .fitCenter() + .dontAnimate() + .into(new CoverTarget(null, txtvPlaceholder, imgvCover, activity)); + } + } + + @Override + public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { + super.onResourceReady(drawable, anim); + TextView txtvPlaceholder = placeholder.get(); + if (txtvPlaceholder != null) { + txtvPlaceholder.setVisibility(View.INVISIBLE); + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index 981d7563a..b6e3a3d82 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -1,7 +1,5 @@ package de.danoeh.antennapod.adapter; -import android.graphics.drawable.Drawable; -import android.net.Uri; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v4.view.MotionEventCompat; @@ -23,9 +21,6 @@ import android.widget.ProgressBar; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.animation.GlideAnimation; -import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; import com.joanzapata.iconify.Iconify; import com.nineoldandroids.view.ViewHelper; @@ -297,49 +292,10 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter fallback; - private final WeakReference placeholder; - private final WeakReference cover; - - public CoverTarget(Uri fallbackUri, TextView txtvPlaceholder, ImageView imgvCover) { - super(imgvCover); - fallback = new WeakReference<>(fallbackUri); - placeholder = new WeakReference<>(txtvPlaceholder); - cover = new WeakReference<>(imgvCover); - } - - @Override - public void onLoadFailed(Exception e, Drawable errorDrawable) { - Uri fallbackUri = fallback.get(); - TextView txtvPlaceholder = placeholder.get(); - ImageView imgvCover = cover.get(); - if(fallbackUri != null && txtvPlaceholder != null && imgvCover != null) { - Glide.with(mainActivity.get()) - .load(fallbackUri) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) - .fitCenter() - .dontAnimate() - .into(new CoverTarget(null, txtvPlaceholder, imgvCover)); - } - } - - @Override - public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { - super.onResourceReady(drawable, anim); - TextView txtvPlaceholder = placeholder.get(); - if(txtvPlaceholder != null) { - txtvPlaceholder.setVisibility(View.INVISIBLE); - } - } - } private View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java index d10674819..1e90fe74a 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.adapter; import android.content.Context; -import android.net.Uri; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; @@ -12,9 +11,6 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.Target; import java.lang.ref.WeakReference; @@ -113,24 +109,11 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI holder.count.setPrimaryText(String.valueOf(itemAccess.getFeedCounter(feed.getId()))); Glide.with(mainActivityRef.get()) .load(feed.getImageUri()) - .placeholder(R.color.light_gray) .error(R.color.light_gray) .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .fitCenter() .dontAnimate() - .listener(new RequestListener() { - @Override - public boolean onException(Exception e, Uri model, Target target, boolean isFirstResource) { - return false; - } - - @Override - public boolean onResourceReady(GlideDrawable resource, Uri model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { - holder.feedTitle.setVisibility(View.INVISIBLE); - return false; - } - }) - .into(holder.imageView); + .into(new CoverTarget(feed.getImageUri(), holder.feedTitle, holder.imageView, mainActivityRef.get())); return convertView; } diff --git a/app/src/main/res/layout/subscription_item.xml b/app/src/main/res/layout/subscription_item.xml index ffbcc33f1..b468d44e9 100644 --- a/app/src/main/res/layout/subscription_item.xml +++ b/app/src/main/res/layout/subscription_item.xml @@ -18,16 +18,11 @@