This commit is contained in:
Felitendo
2025-05-20 15:17:20 +02:00
parent 034f1210fb
commit c24d95627e
399 changed files with 35059 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
package com.looker.droidify.widget
import androidx.recyclerview.widget.RecyclerView
abstract class StableRecyclerAdapter<VT : Enum<VT>, VH : RecyclerView.ViewHolder> :
EnumRecyclerAdapter<VT, VH>() {
private var nextId = 1L
private val descriptorToId = mutableMapOf<String, Long>()
init {
super.setHasStableIds(true)
}
final override fun setHasStableIds(hasStableIds: Boolean) {
throw UnsupportedOperationException()
}
override fun getItemId(position: Int): Long {
val descriptor = getItemDescriptor(position)
return descriptorToId[descriptor] ?: run {
val id = nextId++
descriptorToId[descriptor] = id
id
}
}
abstract fun getItemDescriptor(position: Int): String
}