Skip to content

Commit

Permalink
optimal adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanganhtuan95ptit committed Feb 26, 2023
1 parent d4ab2a5 commit 76d6d44
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.annotation.Keep
import androidx.recyclerview.widget.*
import androidx.viewbinding.ViewBinding
import com.one.coreapp.App
import com.one.coreapp.TRANSITION

abstract class BaseAsyncAdapter<T : ViewItemCloneable, B : ViewBinding>(
itemCallback: DiffUtil.ItemCallback<T>? = null,
Expand Down Expand Up @@ -100,11 +99,23 @@ class BaseBindingViewHolder<B : ViewBinding>(val binding: B, val viewType: Int)
class DefaultItemCallback<T : ViewItem> : DiffUtil.ItemCallback<T>() {

override fun areItemsTheSame(oldItem: T, newItem: T): Boolean {

return oldItem.areItemsTheSame() == newItem.areItemsTheSame()
}

override fun areContentsTheSame(oldItem: T, newItem: T): Boolean {
return false

val payloads = ArrayList<Any>()

val oldItemCompare = oldItem.getContentsCompare()
val newItemCompare = newItem.getContentsCompare()

oldItemCompare.forEachIndexed { index, pair ->

if (pair.first != newItemCompare.getOrNull(index)?.first) payloads.add(pair.second)
}

return payloads.isEmpty()
}

override fun getChangePayload(oldItem: T, newItem: T): Any? {
Expand Down

0 comments on commit 76d6d44

Please sign in to comment.