|
|
|
@ -8,8 +8,6 @@ import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import androidx.viewbinding.ViewBinding |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
import splitties.views.onLongClick |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -48,9 +46,7 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context |
|
|
|
|
recyclerView.adapter = this |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
suspend fun setItems(items: List<ITEM>?) { |
|
|
|
|
withContext(Dispatchers.Default) { |
|
|
|
|
synchronized(asyncListDiffer) { |
|
|
|
|
fun setItems(items: List<ITEM>?) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
if (items == null) { |
|
|
|
|
asyncListDiffer.submitList(null) |
|
|
|
@ -59,20 +55,15 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun setItem(position: Int, item: ITEM) { |
|
|
|
|
synchronized(asyncListDiffer) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
asyncListDiffer.currentList[position] = item |
|
|
|
|
notifyItemChanged(position) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun updateItem(item: ITEM) { |
|
|
|
|
synchronized(asyncListDiffer) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
val index = asyncListDiffer.currentList.indexOf(item) |
|
|
|
|
if (index >= 0) { |
|
|
|
@ -81,10 +72,8 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun updateItem(position: Int, payload: Any) { |
|
|
|
|
synchronized(asyncListDiffer) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
val size = itemCount |
|
|
|
|
if (position in 0 until size) { |
|
|
|
@ -92,10 +81,8 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun updateItems(fromPosition: Int, toPosition: Int, payloads: Any) { |
|
|
|
|
synchronized(asyncListDiffer) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
val size = itemCount |
|
|
|
|
if (fromPosition in 0 until size && toPosition in 0 until size) { |
|
|
|
@ -107,7 +94,6 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun isEmpty() = asyncListDiffer.currentList.isEmpty() |
|
|
|
|
|
|
|
|
|