优化
This commit is contained in:
@@ -114,6 +114,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
|||||||
) {
|
) {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
val oldItems = this.items.toList()
|
val oldItems = this.items.toList()
|
||||||
|
val itemsSize = items?.size ?: 0
|
||||||
val callback = object : DiffUtil.Callback() {
|
val callback = object : DiffUtil.Callback() {
|
||||||
override fun getOldListSize(): Int {
|
override fun getOldListSize(): Int {
|
||||||
return itemCount
|
return itemCount
|
||||||
@@ -153,9 +154,9 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
|||||||
diffJob?.cancel()
|
diffJob?.cancel()
|
||||||
diffJob = Coroutine.async {
|
diffJob = Coroutine.async {
|
||||||
val diffResult = if (skipDiff) withTimeoutOrNullAsync(500L) {
|
val diffResult = if (skipDiff) withTimeoutOrNullAsync(500L) {
|
||||||
DiffUtil.calculateDiff(callback)
|
DiffUtil.calculateDiff(callback, itemsSize < 2000)
|
||||||
} else {
|
} else {
|
||||||
DiffUtil.calculateDiff(callback)
|
DiffUtil.calculateDiff(callback, itemsSize < 2000)
|
||||||
}
|
}
|
||||||
ensureActive()
|
ensureActive()
|
||||||
handler.post {
|
handler.post {
|
||||||
|
|||||||
Reference in New Issue
Block a user