Last active
June 17, 2020 08:46
-
-
Save mrahimygk/6e361ffe5dee739160795056e40663b7 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
abstract class BaseAdapter<T>( | |
private var itemSimilarityPredicate: (T, T) -> Boolean, | |
private var contentSimilarityPredicate: (T, T) -> Boolean | |
) : ListAdapter<T, BaseAdapter<T>.DataBindingViewHolder>(object : DiffUtil.ItemCallback<T>() { | |
override fun areContentsTheSame( | |
oldItem: T, | |
newItem: T | |
) = contentSimilarityPredicate.invoke(oldItem, newItem) | |
override fun areItemsTheSame( | |
oldItem: T, | |
newItem: T | |
) = itemSimilarityPredicate.invoke(oldItem, newItem) | |
}) { | |
} |
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 PeopleAdapter : BaseAdapter<Person>( | |
{ oldItem, newItem -> oldItem == newItem }, | |
{ oldItem, newItem -> | |
oldItem.firstName == newItem.firstName && oldItem.lastName == newItem.lastName | |
}) { | |
override fun getItemViewType(position: Int): Int { | |
return R.layout.item_person | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment