mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 08:47:46 +00:00
Fixed some cursor-related bugs in Search.
This commit is contained in:
parent
8fc63c4d78
commit
e189fff856
@ -30,8 +30,6 @@ public class CursorList<T> implements List<T>, Closeable {
|
||||
public CursorList(@NonNull Cursor cursor, @NonNull ModelBuilder<T> modelBuilder) {
|
||||
this.cursor = cursor;
|
||||
this.modelBuilder = modelBuilder;
|
||||
|
||||
this.cursor.moveToFirst();
|
||||
}
|
||||
|
||||
public static <T> CursorList<T> emptyList() {
|
||||
@ -58,6 +56,8 @@ public class CursorList<T> implements List<T>, Closeable {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
int index = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return cursor.getCount() > 0 && !cursor.isLast();
|
||||
@ -65,9 +65,8 @@ public class CursorList<T> implements List<T>, Closeable {
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
T model = modelBuilder.build(cursor);
|
||||
cursor.moveToNext();
|
||||
return model;
|
||||
cursor.moveToPosition(index++);
|
||||
return modelBuilder.build(cursor);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -179,7 +178,7 @@ public class CursorList<T> implements List<T>, Closeable {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (cursor != null) {
|
||||
if (!cursor.isClosed()) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ class SearchViewModel extends ViewModel {
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
debouncer.clear();
|
||||
searchResult.close();
|
||||
}
|
||||
|
||||
|
@ -29,4 +29,8 @@ public class Debouncer {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
handler.postDelayed(runnable, threshold);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user