From d68e780a91633c1336c31da54c45ec8cdd7ee5cf Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 31 Mar 2018 22:52:09 +0200 Subject: jump to first unread message if was scrolled to bottom earlier --- .../de/pixart/messenger/ui/ConversationFragment.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 30058dd1e..4ef1d95da 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1982,6 +1982,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())); @@ -1993,7 +1999,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(); @@ -2022,6 +2032,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); -- cgit v1.2.3