Skip to content

Instantly share code, notes, and snippets.

@AravinthVelusamy
Created May 17, 2020 16:14
Show Gist options
  • Select an option

  • Save AravinthVelusamy/1c33af068752839e9191bc2677c4426d to your computer and use it in GitHub Desktop.

Select an option

Save AravinthVelusamy/1c33af068752839e9191bc2677c4426d to your computer and use it in GitHub Desktop.
class NewClubAdapter() : ListAdapter<ClubEntity, ClubViewHolder>(AddClubsDiffUtils()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClubViewHolder {
return ClubViewHolder.from(parent)
}
override fun onBindViewHolder(holder: ClubViewHolder, position: Int) {
holder.bind(getItem(position))
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getItemViewType(position: Int): Int {
return position
}
}
class ClubViewHolder constructor(val binding: ItemClubAddBinding) : RecyclerView.ViewHolder(binding.root) {
companion object {
fun from(parent: ViewGroup): ClubViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = ItemClubAddBinding.inflate(layoutInflater, parent, false)
return ClubViewHolder(binding)
}
}
fun bind(club: ClubEntity) {
Timber.d(" ${club.clubName} following is ${club.following}")
setImage(club.clubIcon)
setClubName(club.clubName)
}
private fun setClubName(title: String?) {
binding.clubName.text = title
binding.buttonRemove.visibility = View.GONE
}
fun setImage(name: String?) {
Glide.with(binding.root.context)
.load(name)
.apply(RequestOptions()
.placeholder(R.drawable.ic_image_white_24dp)
.override(100, 100)
.diskCacheStrategy(DiskCacheStrategy.ALL))
.into(binding.clubIcon)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment