Created
April 19, 2021 10:55
-
-
Save UzBestDeveloper/5839a18d0ffd5a0d9f45749cc5d632f0 to your computer and use it in GitHub Desktop.
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 characters
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