Created
May 17, 2020 16:14
-
-
Save AravinthVelusamy/1c33af068752839e9191bc2677c4426d to your computer and use it in GitHub Desktop.
Revisions
-
Aravinth Velusamy created this gist
May 17, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ 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) } }