Only consider the latest item for preloading.

This commit is contained in:
akwizgran
2018-11-14 15:13:25 +00:00
parent 78a8ae6b8e
commit 4db075d643

View File

@@ -336,17 +336,19 @@ public class ConversationActivity extends BriarActivity
new ArrayList<>(headers); new ArrayList<>(headers);
sort(sorted, (a, b) -> sort(sorted, (a, b) ->
Long.compare(b.getTimestamp(), a.getTimestamp())); Long.compare(b.getTimestamp(), a.getTimestamp()));
// Eagerly load the text of the latest message to avoid jumping if (!sorted.isEmpty()) {
for (ConversationMessageHeader h : sorted) { // If the latest header is a private message, eagerly load
if (h instanceof PrivateMessageHeader) { // its text so we can set the scroll position correctly
MessageId id = h.getId(); ConversationMessageHeader latest = sorted.get(0);
if (latest instanceof PrivateMessageHeader &&
((PrivateMessageHeader) latest).hasText()) {
MessageId id = latest.getId();
String text = textCache.get(id); String text = textCache.get(id);
if (text == null) { if (text == null) {
LOG.info("Eagerly loading text of latest message"); LOG.info("Eagerly loading text of latest message");
text = messagingManager.getMessageText(id); text = messagingManager.getMessageText(id);
textCache.put(id, text); textCache.put(id, text);
} }
break;
} }
} }
displayMessages(revision, sorted); displayMessages(revision, sorted);