From 2bc1183e45ac0608acbdb6968c603804d7bd0664 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sun, 2 Aug 2015 17:50:51 +0200 Subject: [PATCH] Try loading the episode cover first; if that fails, try to load the podcast's cover --- .../adapter/AllEpisodesListAdapter.java | 44 ++++++++++++----- .../antennapod/adapter/QueueListAdapter.java | 48 +++++++++++++------ .../main/res/layout/new_episodes_listitem.xml | 12 ++--- app/src/main/res/layout/queue_listitem.xml | 12 ++--- 4 files changed, 77 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesListAdapter.java index f67bb9d7e..a167f7c54 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesListAdapter.java @@ -1,6 +1,8 @@ package de.danoeh.antennapod.adapter; import android.content.Context; +import android.graphics.drawable.Drawable; +import android.net.Uri; import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; @@ -78,7 +80,7 @@ public class AllEpisodesListAdapter extends BaseAdapter { .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.new_episodes_listitem, parent, false); - holder.feed = (TextView) convertView.findViewById(R.id.txtvImage); + holder.placeholder = (TextView) convertView.findViewById(R.id.txtvPlaceholder); holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); holder.pubDate = (TextView) convertView .findViewById(R.id.txtvPublished); @@ -89,15 +91,15 @@ public class AllEpisodesListAdapter extends BaseAdapter { .findViewById(R.id.imgvInPlaylist); holder.progress = (ProgressBar) convertView .findViewById(R.id.pbar_progress); - holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage); + holder.cover = (ImageView) convertView.findViewById(R.id.imgvCover); holder.txtvDuration = (TextView) convertView.findViewById(R.id.txtvDuration); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); } - holder.feed.setVisibility(View.VISIBLE); - holder.feed.setText(item.getFeed().getTitle()); + holder.placeholder.setVisibility(View.VISIBLE); + holder.placeholder.setText(item.getFeed().getTitle()); holder.title.setText(item.getTitle()); holder.pubDate.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL)); if (showOnlyNewEpisodes || false == item.isNew()) { @@ -155,24 +157,40 @@ public class AllEpisodesListAdapter extends BaseAdapter { .diskCacheStrategy(DiskCacheStrategy.SOURCE) .fitCenter() .dontAnimate() - .into(new CustomTarget(holder.feed, holder.imageView)); + .into(new CoverTarget(item.getFeed().getImageUri(), holder.placeholder, holder.cover)); return convertView; } - private class CustomTarget extends GlideDrawableImageViewTarget { + private class CoverTarget extends GlideDrawableImageViewTarget { - private final WeakReference mPlaceholder; + private final WeakReference fallback; + private final WeakReference placeholder; + private final WeakReference cover; - public CustomTarget(TextView placeholder, ImageView imageView) { - super(imageView); - mPlaceholder = new WeakReference(placeholder); + 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) { + if(fallback.get() != null && placeholder.get() != null && cover.get() != null) { + Glide.with(context) + .load(fallback.get()) + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .fitCenter() + .dontAnimate() + .into(new CoverTarget(null, placeholder.get(), cover.get())); + } } @Override public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { super.onResourceReady(drawable, anim); - TextView txtvPlaceholder = mPlaceholder.get(); + TextView txtvPlaceholder = placeholder.get(); if(txtvPlaceholder != null) { txtvPlaceholder.setVisibility(View.INVISIBLE); } @@ -189,12 +207,12 @@ public class AllEpisodesListAdapter extends BaseAdapter { static class Holder { - TextView feed; + TextView placeholder; TextView title; TextView pubDate; View statusUnread; ImageView queueStatus; - ImageView imageView; + ImageView cover; ProgressBar progress; TextView txtvDuration; ImageButton butSecondary; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java index 51a4112ce..6cc62390f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java @@ -1,7 +1,10 @@ package de.danoeh.antennapod.adapter; import android.content.Context; +import android.graphics.drawable.Drawable; +import android.net.Uri; import android.text.format.DateUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -31,6 +34,7 @@ import de.danoeh.antennapod.core.util.Converter; */ public class QueueListAdapter extends BaseAdapter { + private static final String TAG = QueueListAdapter.class.getSimpleName(); private final Context context; private final ItemAccess itemAccess; @@ -82,8 +86,8 @@ public class QueueListAdapter extends BaseAdapter { convertView = inflater.inflate(R.layout.queue_listitem, parent, false); holder.dragHandle = (ImageView) convertView.findViewById(R.id.drag_handle); - holder.feed = (TextView) convertView.findViewById(R.id.txtvImage); - holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage); + holder.placeholder = (TextView) convertView.findViewById(R.id.txtvPlaceholder); + holder.cover = (ImageView) convertView.findViewById(R.id.imgvCover); holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); holder.pubDate = (TextView) convertView.findViewById(R.id.txtvPubDate); holder.progressLeft = (TextView) convertView.findViewById(R.id.txtvProgressLeft); @@ -93,7 +97,6 @@ public class QueueListAdapter extends BaseAdapter { .findViewById(R.id.butSecondaryAction); holder.progress = (ProgressBar) convertView .findViewById(R.id.progressBar); - holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); @@ -105,7 +108,7 @@ public class QueueListAdapter extends BaseAdapter { holder.dragHandle.setVisibility(View.VISIBLE); } - holder.feed.setText(item.getFeed().getTitle()); + holder.placeholder.setText(item.getFeed().getTitle()); holder.title.setText(item.getTitle()); FeedMedia media = item.getMedia(); @@ -152,29 +155,47 @@ public class QueueListAdapter extends BaseAdapter { holder.butSecondary.setTag(item); holder.butSecondary.setOnClickListener(secondaryActionListener); + Log.d(TAG, item.getFeed().getImageUri().toString()); + Glide.with(context) .load(item.getImageUri()) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .fitCenter() .dontAnimate() - .into(new CustomTarget(holder.feed, holder.imageView)); + .into(new CoverTarget(item.getFeed().getImageUri(), holder.placeholder, holder.cover)); return convertView; } - private class CustomTarget extends GlideDrawableImageViewTarget { + private class CoverTarget extends GlideDrawableImageViewTarget { - private final WeakReference mPlaceholder; + private final WeakReference fallback; + private final WeakReference placeholder; + private final WeakReference cover; - public CustomTarget(TextView placeholder, ImageView imageView) { - super(imageView); - mPlaceholder = new WeakReference(placeholder); + 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) { + if(fallback.get() != null && placeholder.get() != null && cover.get() != null) { + Glide.with(context) + .load(fallback.get()) + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .fitCenter() + .dontAnimate() + .into(new CoverTarget(null, placeholder.get(), cover.get())); + } } @Override public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { super.onResourceReady(drawable, anim); - TextView txtvPlaceholder = mPlaceholder.get(); + TextView txtvPlaceholder = placeholder.get(); if(txtvPlaceholder != null) { txtvPlaceholder.setVisibility(View.INVISIBLE); } @@ -189,11 +210,10 @@ public class QueueListAdapter extends BaseAdapter { } }; - static class Holder { ImageView dragHandle; - ImageView imageView; - TextView feed; + ImageView cover; + TextView placeholder; TextView title; TextView pubDate; TextView progressLeft; diff --git a/app/src/main/res/layout/new_episodes_listitem.xml b/app/src/main/res/layout/new_episodes_listitem.xml index ec68c6d72..ec5ab1e6a 100644 --- a/app/src/main/res/layout/new_episodes_listitem.xml +++ b/app/src/main/res/layout/new_episodes_listitem.xml @@ -12,7 +12,7 @@ android:layout_height="wrap_content"> diff --git a/app/src/main/res/layout/queue_listitem.xml b/app/src/main/res/layout/queue_listitem.xml index ffd65acae..38076ff51 100644 --- a/app/src/main/res/layout/queue_listitem.xml +++ b/app/src/main/res/layout/queue_listitem.xml @@ -25,7 +25,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content">