优化
This commit is contained in:
1 parent
8d66baa055
commit
00ec4372d2
5 files changed
+22
-17
No files matched your search
@@ -5,16 +5,15 @@ import android.content.Context
|
||||
import android.util.SparseArray
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.postDelayed
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.utils.buildMainHandler
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import splitties.views.onLongClick
|
||||
import java.util.*
|
||||
import java.util.Collections
|
||||
|
||||
/**
|
||||
* Created by Invincible on 2017/11/24.
|
||||
@@ -152,9 +151,16 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
||||
}
|
||||
diffJob?.cancel()
|
||||
diffJob = Coroutine.async {
|
||||
val diffResult = DiffUtil.calculateDiff(callback)
|
||||
ensureActive()
|
||||
val diffResult = if (skipDiff) withTimeoutOrNull(500L) {
|
||||
DiffUtil.calculateDiff(callback)
|
||||
} else {
|
||||
DiffUtil.calculateDiff(callback)
|
||||
}
|
||||
handler.post {
|
||||
if (diffResult == null) {
|
||||
setItems(items)
|
||||
return@post
|
||||
}
|
||||
if (this@RecyclerAdapter.items.isNotEmpty()) {
|
||||
this@RecyclerAdapter.items.clear()
|
||||
}
|
||||
@@ -165,12 +171,6 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
||||
onCurrentListChanged()
|
||||
}
|
||||
}
|
||||
if (skipDiff) handler.postDelayed(500) {
|
||||
if (diffJob?.isCompleted == false) {
|
||||
diffJob?.cancel()
|
||||
setItems(items)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import io.legado.app.data.entities.Book
|
||||
abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
|
||||
DiffRecyclerAdapter<Book, VB>(context) {
|
||||
|
||||
override val diffItemCallback: DiffUtil.ItemCallback< | ||||