Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Some Kitsu UI stuff to display it properly
class KitsuViewHolder(parent :ViewGroup) : RecyclerView.ViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.kitsu_item, parent, false)) {
var item : KitsuItem? = null
fun bindTo(item : KitsuItem?) {
this.item = item
itemView.itemTypeView.text = item?.type?.capitalize()
?: "Ouhh..."
itemView.itemSubtypeView.text = item?.attributes?.subtype?.capitalize()
?: "Ouhhhhh..."
itemView.itemNameView.text = item?.attributes?.titles?.en_jp?.capitalize()
?: "Ouhhhhhhhh..."
itemView.itemSynopsisView.text = item?.attributes?.synopsis?.capitalize()
?: "Ouhhhhhhhhhhh...\nYou know what?\nThe quick brown fox jumps over the lazy dog!"
val imageUrl = item?.attributes?.posterImage?.small
if (null != imageUrl) {
itemView.itemCoverView.visibility = View.VISIBLE
Glide.with(itemView.context)
.load(imageUrl)
.apply(RequestOptions().placeholder(R.drawable.empty_placeholder))
.transition(DrawableTransitionOptions.withCrossFade())
.into(itemView.itemCoverView)
} else {
Glide.with(itemView.context).clear(itemView.itemCoverView)
itemView.itemCoverView.setImageResource(R.drawable.empty_placeholder)
}
}
}
class KitsuPagedListAdapter : PagedListAdapter<KitsuItem, KitsuViewHolder>(diffCallback) {
override fun onBindViewHolder(holder: KitsuViewHolder, position: Int) {
holder.bindTo(getItem(position))
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KitsuViewHolder = KitsuViewHolder(parent)
companion object {
private val diffCallback = object : DiffCallback<KitsuItem>() {
override fun areItemsTheSame(oldItem: KitsuItem, newItem: KitsuItem): Boolean = oldItem.id == newItem.id
override fun areContentsTheSame(oldItem: KitsuItem, newItem: KitsuItem): Boolean = oldItem == newItem
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment