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;
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<TextView> mPlaceholder;
private final WeakReference<Uri> fallback;
private final WeakReference<TextView> placeholder;
private final WeakReference<ImageView> cover;
public CustomTarget(TextView placeholder, ImageView imageView) {
super(imageView);
mPlaceholder = new WeakReference<TextView>(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;

View File

@ -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<TextView> mPlaceholder;
private final WeakReference<Uri> fallback;
private final WeakReference<TextView> placeholder;
private final WeakReference<ImageView> cover;
public CustomTarget(TextView placeholder, ImageView imageView) {
super(imageView);
mPlaceholder = new WeakReference<TextView>(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;

View File

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

View File

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