From 13322a568a08b1620dc00f43344e1d00b2cbd656 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 26 Feb 2018 16:59:51 +0100 Subject: [PATCH] jump to first unread message if was scrolled to bottom earlier --- .../conversations/ui/ConversationFragment.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 81057906c..8680a1a04 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1701,6 +1701,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke return false; } Log.d(Config.LOGTAG,"reInit(hasExtras="+Boolean.toString(hasExtras)+")"); + + if (this.conversation.isRead() && hasExtras) { + Log.d(Config.LOGTAG,"trimming conversation"); + this.conversation.trim(); + } + setupIme(); this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName())); @@ -1712,7 +1718,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke refresh(false); this.conversation.messagesLoaded.set(true); - if (hasExtras) { + final boolean scrolledToBottomAndNoPending = this.scrolledToBottom() && pendingScrollState.peek() == null; + + Log.d(Config.LOGTAG,"scrolledToBottomAndNoPending="+Boolean.toString(scrolledToBottomAndNoPending)); + + if (hasExtras || scrolledToBottomAndNoPending) { synchronized (this.messageList) { Log.d(Config.LOGTAG,"jump to first unread message"); final Message first = conversation.getFirstUnreadMessage(); @@ -1735,6 +1745,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke return true; } + private boolean scrolledToBottom() { + final ListView l = this.binding.messagesView; + return l.getLastVisiblePosition() == l.getAdapter().getCount() -1 && l.getChildAt(l.getChildCount() - 1).getBottom() <= l.getHeight(); + } + private void processExtras(Bundle extras) { final String downloadUuid = extras.getString(ConversationActivity.EXTRA_DOWNLOAD_UUID); final String text = extras.getString(ConversationActivity.EXTRA_TEXT);