mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 11:22:21 +00:00
Fix bug related to gallery selection state.
TreeSets are annoying. contains() is calculated with the comparator, which can lead to some weird bugs. Made sure the comparator didn't think two items with the same date were identical. Also fixed stableId generation to avoid any potential weirdness there.
This commit is contained in:
31
src/org/thoughtcrime/securesms/util/StableIdGenerator.java
Normal file
31
src/org/thoughtcrime/securesms/util/StableIdGenerator.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Useful for generate ID's to be used with
|
||||
* {@link android.support.v7.widget.RecyclerView.Adapter#getItemId(int)} when you otherwise don't
|
||||
* have a good way to generate an ID.
|
||||
*/
|
||||
public class StableIdGenerator<E> {
|
||||
|
||||
private final Map<E, Long> keys = new HashMap<>();
|
||||
|
||||
private long index = 1;
|
||||
|
||||
@MainThread
|
||||
public long getId(@NonNull E item) {
|
||||
if (keys.containsKey(item)) {
|
||||
return keys.get(item);
|
||||
}
|
||||
|
||||
long key = index++;
|
||||
keys.put(item, key);
|
||||
|
||||
return key;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user