Skip to content

Instantly share code, notes, and snippets.

@UzBestDeveloper
Created April 19, 2021 10:55
Show Gist options
  • Save UzBestDeveloper/5839a18d0ffd5a0d9f45749cc5d632f0 to your computer and use it in GitHub Desktop.
Save UzBestDeveloper/5839a18d0ffd5a0d9f45749cc5d632f0 to your computer and use it in GitHub Desktop.
class ClassStudentListAdapter : PagingDataAdapter<ClassStudentObject, ClassStudentListAdapter.ViewHolder>(DiffClassStudentCallback()) {
class ViewHolder private constructor(binding: ItemStudentsModuleListBinding) : RecyclerView.ViewHolder(
binding.root
){
fun bind(item: ClassStudentObject?) {
setData(item!!)
}
private fun setData(item: ClassStudentObject ) {
}
companion object {
fun from(parent: ViewGroup): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = ItemStudentsModuleListBinding.inflate(layoutInflater, parent, false)
return ViewHolder(binding)
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder.from(parent)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = getItem(position)
item?.let { holder.bind(it) }
}
}
class DiffClassStudentCallback : DiffUtil.ItemCallback<ClassStudentObject>() {
override fun areItemsTheSame(oldItem: ClassStudentObject, newItem: ClassStudentObject): Boolean {
return oldItem.personid == newItem.personid
}
@SuppressLint("DiffUtilEquals")
override fun areContentsTheSame(oldItem: ClassStudentObject, newItem: ClassStudentObject): Boolean {
return oldItem == newItem
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment