mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Fix design assumption invalidated crash in MediaPreviewAdapter.
This commit is contained in:
@@ -11,6 +11,7 @@ import org.thoughtcrime.securesms.util.adapter.StableIdGenerator
|
||||
class MediaPreviewV2Adapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
private var items: List<Attachment> = listOf()
|
||||
private val stableIdGenerator = StableIdGenerator<Attachment>()
|
||||
private val currentIdSet: HashSet<Long> = HashSet()
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return items.count()
|
||||
@@ -44,6 +45,10 @@ class MediaPreviewV2Adapter(fragment: Fragment) : FragmentStateAdapter(fragment)
|
||||
return fragment
|
||||
}
|
||||
|
||||
override fun containsItem(itemId: Long): Boolean {
|
||||
return currentIdSet.contains(itemId)
|
||||
}
|
||||
|
||||
fun getFragmentTag(position: Int): String? {
|
||||
if (items.isEmpty() || position < 0 || position > itemCount) {
|
||||
return null
|
||||
@@ -59,6 +64,10 @@ class MediaPreviewV2Adapter(fragment: Fragment) : FragmentStateAdapter(fragment)
|
||||
fun updateBackingItems(newItems: Collection<Attachment>) {
|
||||
if (newItems != items) {
|
||||
items = newItems.toList()
|
||||
currentIdSet.clear()
|
||||
items.forEach {
|
||||
currentIdSet.add(stableIdGenerator.getId(it))
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user