package com.looker.droidify.widget import androidx.recyclerview.widget.RecyclerView abstract class StableRecyclerAdapter, VH : RecyclerView.ViewHolder> : EnumRecyclerAdapter() { private var nextId = 1L private val descriptorToId = mutableMapOf() 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 }