Stop scanning for prev/next on destroy

pull/194/merge
M66B 3 years ago
parent a6837729f4
commit 0b6fe99183

@ -21,4 +21,11 @@ package eu.faircode.email;
public class ObjectHolder<T> {
public T value;
public ObjectHolder() {
}
public ObjectHolder(T init) {
this.value = init;
}
}

@ -272,6 +272,14 @@ public class ViewModelMessages extends ViewModel {
return;
}
ObjectHolder<Boolean> alive = new ObjectHolder<>(true);
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
public void onAny() {
alive.value = owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED);
}
});
Log.i("Observe previous/next id=" + id);
//model.list.getValue().loadAround(lpos);
model.list.observe(owner, new Observer<PagedList<TupleMessageEx>>() {
@ -363,7 +371,7 @@ public class ViewModelMessages extends ViewModel {
return getPair(plist, ds, count, from + j);
}
for (int i = 0; i < count; i += CHUNK_SIZE) {
for (int i = 0; i < count && alive.value; i += CHUNK_SIZE) {
Log.i("Observe previous/next load" +
" range=" + i + "/#" + count);
List<TupleMessageEx> messages = ds.loadRange(i, Math.min(CHUNK_SIZE, count - i));

Loading…
Cancel
Save