From 6a3de2621d535faef6ded75985970d755d5878ea Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 2 Aug 2021 07:03:54 +0200 Subject: [PATCH] Fixed prev/next fallback --- .../eu/faircode/email/ViewModelMessages.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ViewModelMessages.java b/app/src/main/java/eu/faircode/email/ViewModelMessages.java index 68e0c2ff0c..913f07595e 100644 --- a/app/src/main/java/eu/faircode/email/ViewModelMessages.java +++ b/app/src/main/java/eu/faircode/email/ViewModelMessages.java @@ -301,14 +301,20 @@ public class ViewModelMessages extends ViewModel { return; } + Log.i("Observe previous/next" + + " prev=" + (curState[0] == null ? null : curState[0].first + "/" + curState[0].second) + + " base=" + (curState[1] == null ? null : curState[1].first + "/" + curState[1].second) + + " next=" + (curState[2] == null ? null : curState[2].first + "/" + curState[2].second)); + lastState[0] = curState[0]; lastState[1] = curState[1]; lastState[2] = curState[2]; - if (curState[1] != null) + if (curState[1] != null) { intf.onFound(curState[1].second, messages.size()); - intf.onPrevious(curState[0] != null, curState[0] == null ? null : curState[0].first); - intf.onNext(curState[2] != null, curState[2] == null ? null : curState[2].first); + intf.onPrevious(curState[0] != null, curState[0] == null ? null : curState[0].first); + intf.onNext(curState[2] != null, curState[2] == null ? null : curState[2].first); + } if (curState[1] != null && (curState[0] == null || curState[0].first != null) && @@ -355,6 +361,23 @@ public class ViewModelMessages extends ViewModel { return null; } + @Override + protected void onExecuted(Bundle args, Pair data) { + if (data == null) { + Log.i("Observe previous/next fallback=none"); + return; // keep current + } + + intf.onPrevious(data.first != null, data.first); + intf.onNext(data.second != null, data.second); + intf.onFound(-1, messages.size()); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + // No nothing + } + private Pair getPair( PagedList plist, LimitOffsetDataSource ds, @@ -379,18 +402,6 @@ public class ViewModelMessages extends ViewModel { Log.i("Observe previous/next fallback=" + result); return result; } - - @Override - protected void onExecuted(Bundle args, Pair data) { - intf.onPrevious(data != null && data.first != null, data == null ? null : data.first); - intf.onNext(data != null && data.second != null, data == null ? null : data.second); - intf.onFound(-1, messages.size()); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - // No nothing - } }.execute(context, owner, args, "model:fallback"); } });