Last active
July 31, 2019 08:36
-
-
Save Jericho2Code/bcc0760afd701ee07fa665fad9854b34 to your computer and use it in GitHub Desktop.
Simple implementation of DiffUtil.ItemCallback uses Kotlin
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 BaseDiffCallback<T>( | |
val isItemsSame: (old: T, new: T) -> Boolean, | |
val isContentsSame: (old: T, new: T) -> Boolean = { old, new -> old == new } | |
) : DiffUtil.ItemCallback<T>() { | |
override fun areItemsTheSame(old: T, new: T): Boolean = isItemsSame(old, new) | |
override fun areContentsTheSame(old: T, new: T): Boolean = isContentsSame(old, new) | |
} | |
//sample | |
data class Item(val id: Long, val data: String) | |
fun test() { | |
val callback = BaseDiffCallback<Item>({ old, new -> old.id == new.id }) | |
//use of callback | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment