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 de000570b..ce8d384dd 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -1,70 +1,106 @@ package de.danoeh.antennapod.adapter; import android.content.Context; +import android.net.Uri; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +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 de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.view.SubscriptionViewItem; +import de.danoeh.antennapod.core.glide.ApGlideSettings; /** * Adapter for subscriptions */ public class SubscriptionsAdapter extends BaseAdapter { - private NavListAdapter.ItemAccess mItemAccess; + private NavListAdapter.ItemAccess itemAccess; - private Context mContext; + private final Context context; public SubscriptionsAdapter(Context context, NavListAdapter.ItemAccess itemAccess) { - mItemAccess = itemAccess; - mContext = context; + this.itemAccess = itemAccess; + this.context = context; } public void setItemAccess(NavListAdapter.ItemAccess itemAccess) { - mItemAccess = itemAccess; + this.itemAccess = itemAccess; } @Override public int getCount() { - return mItemAccess.getCount(); + return itemAccess.getCount(); } @Override public Object getItem(int position) { - return mItemAccess.getItem(position); + return itemAccess.getItem(position); } @Override public long getItemId(int position) { - return mItemAccess.getItem(position).getId(); + return itemAccess.getItem(position).getId(); } @Override public View getView(int position, View convertView, ViewGroup parent) { Holder holder; - final Feed item = (Feed) getItem(position); - if (item == null) return null; + final Feed feed = (Feed) getItem(position); + if (feed == null) return null; if (convertView == null) { holder = new Holder(); - LayoutInflater inflater = - (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.subscription_item, parent, false); - holder.itemView = (SubscriptionViewItem) convertView.findViewById(R.id.subscription_item); + + LayoutInflater layoutInflater = + (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = layoutInflater.inflate(R.layout.subscription_item, parent, false); + holder.feedTitle = (TextView) convertView.findViewById(R.id.txtvTitle); + holder.imageView = (ImageView) convertView.findViewById(R.id.imgvCover); + + convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); } - holder.itemView.setFeed(item); + holder.feedTitle.setVisibility(View.VISIBLE); + holder.feedTitle.setText(feed.getTitle()); + Glide.with(context) + .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.GONE); + holder.imageView.setVisibility(View.VISIBLE); + return false; + } + }) + .into(holder.imageView); + return convertView; } static class Holder { - SubscriptionViewItem itemView; + public TextView feedTitle; + public ImageView imageView; } } diff --git a/app/src/main/java/de/danoeh/antennapod/view/SubscriptionViewItem.java b/app/src/main/java/de/danoeh/antennapod/view/SubscriptionViewItem.java deleted file mode 100644 index 67973a7ef..000000000 --- a/app/src/main/java/de/danoeh/antennapod/view/SubscriptionViewItem.java +++ /dev/null @@ -1,83 +0,0 @@ -package de.danoeh.antennapod.view; - -import android.content.Context; -import android.net.Uri; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.ImageView; -import android.widget.RelativeLayout; -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 de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.feed.Feed; - -/** - * Custom view for handling feed item. - */ -public class SubscriptionViewItem extends RelativeLayout { - - private ImageView mImageView; - private TextView mTextTime; - private TextView mFeedTitle; - private Context mContext; - - public SubscriptionViewItem(Context context) { - super(context); - init(context); - } - - public SubscriptionViewItem(Context context, AttributeSet attrs) { - super(context, attrs); - init(context); - } - - public SubscriptionViewItem(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(context); - } - - @Override - public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, widthMeasureSpec); - } - - private void init(Context context) { - mContext = context; - LayoutInflater mLayoutInflater = - (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View view = mLayoutInflater.inflate(R.layout.subscription_view, this); - mTextTime = (TextView) view.findViewById(R.id.txtvTime); - mFeedTitle = (TextView) view.findViewById(R.id.txtvTitle); - mImageView = (ImageView) view.findViewById(R.id.imgvCover); - } - - public void setFeed(Feed feed) { - mFeedTitle.setVisibility(VISIBLE); - mFeedTitle.setText(feed.getTitle()); - Glide.with(mContext) - .load(feed.getImageUri()) - .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) { - mFeedTitle.setVisibility(INVISIBLE); - return false; - } - }) - .centerCrop() - .into(mImageView); - - mTextTime.setVisibility(GONE); - } - -} diff --git a/app/src/main/res/layout/subscription_item.xml b/app/src/main/res/layout/subscription_item.xml index cee37f7aa..c23d05bd4 100644 --- a/app/src/main/res/layout/subscription_item.xml +++ b/app/src/main/res/layout/subscription_item.xml @@ -1,12 +1,29 @@ - + - + - + + + diff --git a/app/src/main/res/layout/subscription_view.xml b/app/src/main/res/layout/subscription_view.xml deleted file mode 100644 index 629d9a492..000000000 --- a/app/src/main/res/layout/subscription_view.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - -