From 9d8ce9e82715f3de656daf93b8818eb71e3b018e Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 18 Oct 2018 10:22:03 +0000 Subject: [PATCH] Added source file --- .../eu/faircode/email/ViewModelMessages.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/src/main/java/eu/faircode/email/ViewModelMessages.java diff --git a/app/src/main/java/eu/faircode/email/ViewModelMessages.java b/app/src/main/java/eu/faircode/email/ViewModelMessages.java new file mode 100644 index 00000000..8308d0c2 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/ViewModelMessages.java @@ -0,0 +1,34 @@ +package eu.faircode.email; + +import androidx.lifecycle.ViewModel; +import androidx.paging.PagedList; + +class ViewModelMessages extends ViewModel { + private PagedList messages = null; + + void setMessages(PagedList messages) { + this.messages = messages; + } + + String[] getPrevNext(String thread) { + boolean found = false; + TupleMessageEx prev = null; + TupleMessageEx next = null; + + for (int i = 0; i < messages.size(); i++) { + TupleMessageEx item = messages.get(i); + if (item == null) + continue; + if (found) { + next = item; + messages.loadAround(i); + break; + } + if (thread.equals(item.thread)) + found = true; + else + prev = item; + } + return new String[]{prev == null ? null : prev.thread, next == null ? null : next.thread}; + } +}