public static Drawable getTintedIcon( @NonNull Context context, @DrawableRes int drawable, @ColorInt int color) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return getTintedIcon(ContextCompat.getDrawable(context, drawable), color); } else { Drawable icon = VectorDrawableCompat.create(context.getResources(), drawable, null); return getTintedIcon(icon, color); } } catch (Resources.NotFoundException ex) { return getTintedIcon(ContextCompat.getDrawable(context, R.drawable.iconshowcase_logo), color); } }
public void setItem(I item) { // Overview (Title/Author, Status/Deadline) if (item.getTitle() != null && item.getAuthor() != null) { tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { tvTitleAndAuthor.setText(item.getTitle()); } else { setTextOrHide(item.getAuthor(), tvTitleAndAuthor); } if (coversHidden) { ivMediaType.setVisibility(View.GONE); ivCover.setVisibility(View.GONE); } else { if (item.getCover() != null) { ivCover.setVisibility(View.VISIBLE); ivMediaType.setVisibility(View.GONE); Drawable loading = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_loading, null); Glide.with(context) .using(new ISBNToolsUrlLoader(context)) .load(item.getCover()) .placeholder(loading) .crossFade() .into(ivCover); } else { ivCover.setVisibility(View.GONE); Glide.clear(ivCover); if (item.getMediaType() != null) { ivMediaType.setImageResource( ResultsAdapter.getResourceByMediaType(item.getMediaType())); ivMediaType.setContentDescription(sp.getMediaTypeName(item.getMediaType())); ivMediaType.setVisibility(View.VISIBLE); } else { ivMediaType.setVisibility(View.INVISIBLE); } } } }