This file contains 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 characters
class PhonesHomeAdapter( | |
private val phonesHomeList: List<Phone>?, | |
private val listener: (String) -> Unit | |
) : RecyclerView.Adapter<PhonesHomeAdapter.ViewHolder>() { | |
private lateinit var binding: ItemPhoneHomeBinding | |
class ViewHolder(private val binding: ItemPhoneHomeBinding) : | |
RecyclerView.ViewHolder(binding.root) { | |
fun bind(phone: Phone?, listener: (String) -> Unit) { | |
binding.apply { | |
Glide.with(image.context) | |
.load(phone?.image) | |
.into(image) | |
name.text = phone?.name | |
root.setOnClickListener { | |
listener(phone!!.slug) | |
} | |
} | |
} | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
binding = ItemPhoneHomeBinding.inflate( | |
LayoutInflater.from(parent.context), parent, false | |
) | |
return ViewHolder(binding) | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.bind(phonesHomeList?.get(position), listener) | |
} | |
override fun getItemCount() = phonesHomeList!!.size | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment