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) {
|
public CursorList(@NonNull Cursor cursor, @NonNull ModelBuilder<T> modelBuilder) {
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
this.modelBuilder = modelBuilder;
|
this.modelBuilder = modelBuilder;
|
||||||
|
|
||||||
this.cursor.moveToFirst();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> CursorList<T> emptyList() {
|
public static <T> CursorList<T> emptyList() {
|
||||||
@ -58,6 +56,8 @@ public class CursorList<T> implements List<T>, Closeable {
|
|||||||
@Override
|
@Override
|
||||||
public Iterator<T> iterator() {
|
public Iterator<T> iterator() {
|
||||||
return new Iterator<T>() {
|
return new Iterator<T>() {
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return cursor.getCount() > 0 && !cursor.isLast();
|
return cursor.getCount() > 0 && !cursor.isLast();
|
||||||
@ -65,9 +65,8 @@ public class CursorList<T> implements List<T>, Closeable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T next() {
|
public T next() {
|
||||||
T model = modelBuilder.build(cursor);
|
cursor.moveToPosition(index++);
|
||||||
cursor.moveToNext();
|
return modelBuilder.build(cursor);
|
||||||
return model;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -179,7 +178,7 @@ public class CursorList<T> implements List<T>, Closeable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (cursor != null) {
|
if (!cursor.isClosed()) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ class SearchViewModel extends ViewModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCleared() {
|
protected void onCleared() {
|
||||||
|
debouncer.clear();
|
||||||
searchResult.close();
|
searchResult.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,4 +29,8 @@ public class Debouncer {
|
|||||||
handler.removeCallbacksAndMessages(null);
|
handler.removeCallbacksAndMessages(null);
|
||||||
handler.postDelayed(runnable, threshold);
|
handler.postDelayed(runnable, threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
handler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user