A sample of DiffUtil written in Kotlin.
- Subscribe to state changes. (MainActivity.onStart)
- When notified state changes, set new state to adapter. (MainActivity.onStart)
- Transform new state to item list and set to
items
. (MainAdapter.state) - Calculate item list differences and dispatch updates to adapter. (MainAdapter.items)
Diffable
is an interface for simplify use DiffUtil.Callback
.
Diffable.isTheSame
returns true if this
and other
has same id.
Default implementation returns equals
.
data class
should override this.
like this:
override fun isTheSame(other: Diffable) = (id == (other as? Repo)?.id)
Diffable.isContentsTheSame
returns true if this
equals to other
.
Default implementation returns equals
.