Try loading the episode cover first; if that fails, try to load the podcast's cover

This commit is contained in:
Martin Fietz 2015-08-02 17:50:51 +02:00
parent 0824af6325
commit 2bc1183e45
4 changed files with 77 additions and 39 deletions

View File

@ -1,6 +1,8 @@
package de.danoeh.antennapod.adapter; package de.danoeh.antennapod.adapter;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -78,7 +80,7 @@ public class AllEpisodesListAdapter extends BaseAdapter {
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.new_episodes_listitem, convertView = inflater.inflate(R.layout.new_episodes_listitem,
parent, false); 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.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.pubDate = (TextView) convertView holder.pubDate = (TextView) convertView
.findViewById(R.id.txtvPublished); .findViewById(R.id.txtvPublished);
@ -89,15 +91,15 @@ public class AllEpisodesListAdapter extends BaseAdapter {
.findViewById(R.id.imgvInPlaylist); .findViewById(R.id.imgvInPlaylist);
holder.progress = (ProgressBar) convertView holder.progress = (ProgressBar) convertView
.findViewById(R.id.pbar_progress); .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); holder.txtvDuration = (TextView) convertView.findViewById(R.id.txtvDuration);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();
} }
holder.feed.setVisibility(View.VISIBLE); holder.placeholder.setVisibility(View.VISIBLE);
holder.feed.setText(item.getFeed().getTitle()); holder.placeholder.setText(item.getFeed().getTitle());
holder.title.setText(item.getTitle()); holder.title.setText(item.getTitle());
holder.pubDate.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL)); holder.pubDate.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL));
if (showOnlyNewEpisodes || false == item.isNew()) { if (showOnlyNewEpisodes || false == item.isNew()) {
@ -155,24 +157,40 @@ public class AllEpisodesListAdapter extends BaseAdapter {
.diskCacheStrategy(DiskCacheStrategy.SOURCE) .diskCacheStrategy(DiskCacheStrategy.SOURCE)
.fitCenter() .fitCenter()
.dontAnimate() .dontAnimate()
.into(new CustomTarget(holder.feed, holder.imageView)); .into(new CoverTarget(item.getFeed().getImageUri(), holder.placeholder, holder.cover));
return convertView; return convertView;
} }
private class CustomTarget extends GlideDrawableImageViewTarget { private class CoverTarget extends GlideDrawableImageViewTarget {
private final WeakReference<TextView> mPlaceholder; private final WeakReference<Uri> fallback;
private final WeakReference<TextView> placeholder;
private final WeakReference<ImageView> cover;
public CustomTarget(TextView placeholder, ImageView imageView) { public CoverTarget(Uri fallbackUri, TextView txtvPlaceholder, ImageView imgvCover) {
super(imageView); super(imgvCover);
mPlaceholder = new WeakReference<TextView>(placeholder); 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 @Override
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
super.onResourceReady(drawable, anim); super.onResourceReady(drawable, anim);
TextView txtvPlaceholder = mPlaceholder.get(); TextView txtvPlaceholder = placeholder.get();
if(txtvPlaceholder != null) { if(txtvPlaceholder != null) {
txtvPlaceholder.setVisibility(View.INVISIBLE); txtvPlaceholder.setVisibility(View.INVISIBLE);
} }
@ -189,12 +207,12 @@ public class AllEpisodesListAdapter extends BaseAdapter {
static class Holder { static class Holder {
TextView feed; TextView placeholder;
TextView title; TextView title;
TextView pubDate; TextView pubDate;
View statusUnread; View statusUnread;
ImageView queueStatus; ImageView queueStatus;
ImageView imageView; ImageView cover;
ProgressBar progress; ProgressBar progress;
TextView txtvDuration; TextView txtvDuration;
ImageButton butSecondary; ImageButton butSecondary;

View File

@ -1,7 +1,10 @@
package de.danoeh.antennapod.adapter; package de.danoeh.antennapod.adapter;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -31,6 +34,7 @@ import de.danoeh.antennapod.core.util.Converter;
*/ */
public class QueueListAdapter extends BaseAdapter { public class QueueListAdapter extends BaseAdapter {
private static final String TAG = QueueListAdapter.class.getSimpleName();
private final Context context; private final Context context;
private final ItemAccess itemAccess; private final ItemAccess itemAccess;
@ -82,8 +86,8 @@ public class QueueListAdapter extends BaseAdapter {
convertView = inflater.inflate(R.layout.queue_listitem, convertView = inflater.inflate(R.layout.queue_listitem,
parent, false); parent, false);
holder.dragHandle = (ImageView) convertView.findViewById(R.id.drag_handle); holder.dragHandle = (ImageView) convertView.findViewById(R.id.drag_handle);
holder.feed = (TextView) convertView.findViewById(R.id.txtvImage); holder.placeholder = (TextView) convertView.findViewById(R.id.txtvPlaceholder);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage); holder.cover = (ImageView) convertView.findViewById(R.id.imgvCover);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.pubDate = (TextView) convertView.findViewById(R.id.txtvPubDate); holder.pubDate = (TextView) convertView.findViewById(R.id.txtvPubDate);
holder.progressLeft = (TextView) convertView.findViewById(R.id.txtvProgressLeft); holder.progressLeft = (TextView) convertView.findViewById(R.id.txtvProgressLeft);
@ -93,7 +97,6 @@ public class QueueListAdapter extends BaseAdapter {
.findViewById(R.id.butSecondaryAction); .findViewById(R.id.butSecondaryAction);
holder.progress = (ProgressBar) convertView holder.progress = (ProgressBar) convertView
.findViewById(R.id.progressBar); .findViewById(R.id.progressBar);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();
@ -105,7 +108,7 @@ public class QueueListAdapter extends BaseAdapter {
holder.dragHandle.setVisibility(View.VISIBLE); holder.dragHandle.setVisibility(View.VISIBLE);
} }
holder.feed.setText(item.getFeed().getTitle()); holder.placeholder.setText(item.getFeed().getTitle());
holder.title.setText(item.getTitle()); holder.title.setText(item.getTitle());
FeedMedia media = item.getMedia(); FeedMedia media = item.getMedia();
@ -152,29 +155,47 @@ public class QueueListAdapter extends BaseAdapter {
holder.butSecondary.setTag(item); holder.butSecondary.setTag(item);
holder.butSecondary.setOnClickListener(secondaryActionListener); holder.butSecondary.setOnClickListener(secondaryActionListener);
Log.d(TAG, item.getFeed().getImageUri().toString());
Glide.with(context) Glide.with(context)
.load(item.getImageUri()) .load(item.getImageUri())
.diskCacheStrategy(DiskCacheStrategy.SOURCE) .diskCacheStrategy(DiskCacheStrategy.SOURCE)
.fitCenter() .fitCenter()
.dontAnimate() .dontAnimate()
.into(new CustomTarget(holder.feed, holder.imageView)); .into(new CoverTarget(item.getFeed().getImageUri(), holder.placeholder, holder.cover));
return convertView; return convertView;
} }
private class CustomTarget extends GlideDrawableImageViewTarget { private class CoverTarget extends GlideDrawableImageViewTarget {
private final WeakReference<TextView> mPlaceholder; private final WeakReference<Uri> fallback;
private final WeakReference<TextView> placeholder;
private final WeakReference<ImageView> cover;
public CustomTarget(TextView placeholder, ImageView imageView) { public CoverTarget(Uri fallbackUri, TextView txtvPlaceholder, ImageView imgvCover) {
super(imageView); super(imgvCover);
mPlaceholder = new WeakReference<TextView>(placeholder); 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 @Override
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
super.onResourceReady(drawable, anim); super.onResourceReady(drawable, anim);
TextView txtvPlaceholder = mPlaceholder.get(); TextView txtvPlaceholder = placeholder.get();
if(txtvPlaceholder != null) { if(txtvPlaceholder != null) {
txtvPlaceholder.setVisibility(View.INVISIBLE); txtvPlaceholder.setVisibility(View.INVISIBLE);
} }
@ -189,11 +210,10 @@ public class QueueListAdapter extends BaseAdapter {
} }
}; };
static class Holder { static class Holder {
ImageView dragHandle; ImageView dragHandle;
ImageView imageView; ImageView cover;
TextView feed; TextView placeholder;
TextView title; TextView title;
TextView pubDate; TextView pubDate;
TextView progressLeft; TextView progressLeft;

View File

@ -12,7 +12,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/txtvImage" android:id="@+id/txtvPlaceholder"
android:layout_width="@dimen/thumbnail_length_itemlist" android:layout_width="@dimen/thumbnail_length_itemlist"
android:layout_height="@dimen/thumbnail_length_itemlist" android:layout_height="@dimen/thumbnail_length_itemlist"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
@ -25,13 +25,13 @@
android:gravity="center"/> android:gravity="center"/>
<ImageView <ImageView
android:id="@+id/imgvImage" android:id="@+id/imgvCover"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_alignLeft="@+id/txtvImage" android:layout_alignLeft="@id/txtvPlaceholder"
android:layout_alignTop="@+id/txtvImage" android:layout_alignTop="@id/txtvPlaceholder"
android:layout_alignRight="@+id/txtvImage" android:layout_alignRight="@id/txtvPlaceholder"
android:layout_alignBottom="@+id/txtvImage" android:layout_alignBottom="@id/txtvPlaceholder"
android:contentDescription="@string/cover_label" android:contentDescription="@string/cover_label"
tools:src="@drawable/ic_stat_antenna_default" tools:src="@drawable/ic_stat_antenna_default"
tools:background="@android:color/holo_green_dark" /> tools:background="@android:color/holo_green_dark" />

View File

@ -25,7 +25,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/txtvImage" android:id="@+id/txtvPlaceholder"
android:layout_width="@dimen/thumbnail_length_queue_item" android:layout_width="@dimen/thumbnail_length_queue_item"
android:layout_height="@dimen/thumbnail_length_queue_item" android:layout_height="@dimen/thumbnail_length_queue_item"
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding" android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
@ -36,13 +36,13 @@
android:maxLines="3" android:maxLines="3"
android:ellipsize="end"/> android:ellipsize="end"/>
<ImageView <ImageView
android:id="@+id/imgvImage" android:id="@+id/imgvCover"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtvImage" android:layout_alignLeft="@id/txtvPlaceholder"
android:layout_alignTop="@+id/txtvImage" android:layout_alignTop="@id/txtvPlaceholder"
android:layout_alignRight="@+id/txtvImage" android:layout_alignRight="@id/txtvPlaceholder"
android:layout_alignBottom="@+id/txtvImage" android:layout_alignBottom="@id/txtvPlaceholder"
android:contentDescription="@string/cover_label" android:contentDescription="@string/cover_label"
tools:src="@drawable/ic_stat_antenna_default" tools:src="@drawable/ic_stat_antenna_default"
tools:background="@android:color/holo_green_dark"/> tools:background="@android:color/holo_green_dark"/>