diff options
| author | Aleksandr Granin <aleksandr@mullvad.net> | 2021-03-17 10:21:44 +0100 |
|---|---|---|
| committer | Aleksandr Granin <aleksandr@mullvad.net> | 2021-03-19 14:42:20 +0100 |
| commit | 39b568e1f27e6284b878de5fe2d58804bf9df7f8 (patch) | |
| tree | 91cbc28ae05868a2af28c6073fe1f2c4c35ca470 /android/src | |
| parent | 0bbffe3fb1c04c181dfc0ac8e6391e444e363ac2 (diff) | |
| download | mullvadvpn-39b568e1f27e6284b878de5fe2d58804bf9df7f8.tar.xz mullvadvpn-39b568e1f27e6284b878de5fe2d58804bf9df7f8.zip | |
Add stable id provider
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemsAdapter.kt | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemsAdapter.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemsAdapter.kt index b69d2b22b9..bb30626cb7 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemsAdapter.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemsAdapter.kt @@ -6,6 +6,7 @@ import androidx.recyclerview.widget.AsyncListDiffer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListUpdateCallback import androidx.recyclerview.widget.RecyclerView +import java.util.concurrent.atomic.AtomicLong import net.mullvad.mullvadvpn.model.ListItemData import net.mullvad.mullvadvpn.ui.listitemview.ActionListItemView import net.mullvad.mullvadvpn.ui.listitemview.DividerGroupListItemView @@ -54,7 +55,7 @@ class ListItemsAdapter : RecyclerView.Adapter<ListItemsAdapter.ViewHolder>() { @ListItemData.ItemType override fun getItemViewType(position: Int): Int = getItem(position).type - override fun getItemId(position: Int): Long = getItem(position).identifier.hashCode().toLong() + override fun getItemId(position: Int): Long = getId(getItem(position).identifier) private fun getItem(position: Int): ListItemData = listDiffer.currentList[position] @@ -101,5 +102,14 @@ class ListItemsAdapter : RecyclerView.Adapter<ListItemsAdapter.ViewHolder>() { } inner class ViewHolder(view: ListItemView) : RecyclerView.ViewHolder(view) + + companion object StableIdProvider { + private val idCounter = AtomicLong(0) + private val mapIds = hashMapOf<String, Long>() + + internal fun getId(stringId: String): Long = mapIds.computeIfAbsent(stringId) { + idCounter.decrementAndGet() + } + } } typealias DiffCallback = DiffUtil.ItemCallback<ListItemData> |
