aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-29 22:39:55 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-29 22:39:55 +0200
commitf149772daffab5351aec06c5e62ebb9e9d54dc64 (patch)
tree0f30be60e33f5fcbaf6703d66f05956a2cdef869
parent52436756a938327da0dcc0a4d800fb9fd763bac5 (diff)
scroll to bottom even if last visible item is heigher than view
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 823eacf55..cad1beb44 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -426,7 +426,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
@Override
public void onClick(View v) {
stopScrolling();
- setSelection(binding.messagesView.getCount() - 1);
+ setSelection(binding.messagesView.getCount() - 1, true);
}
};
@@ -2218,13 +2218,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final Message first = conversation.getFirstUnreadMessage();
final int bottom = Math.max(0, this.messageList.size() - 1);
final int pos;
+ final boolean jumpToBottom;
if (first == null) {
pos = bottom;
+ jumpToBottom = true;
} else {
int i = getIndexOf(first.getUuid(), this.messageList);
pos = i < 0 ? bottom : i;
+ jumpToBottom = false;
}
- setSelection(pos);
+ setSelection(pos, jumpToBottom);
}
}
@@ -2287,17 +2290,25 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
this.binding.unreadCountCustomView.setVisibility(View.GONE);
}
- private void setSelection(int pos) {
- this.binding.messagesView.setSelection(pos);
- this.binding.messagesView.post(() -> this.binding.messagesView.setSelection(pos));
+ private void setSelection(int pos, boolean jumpToBottom) {
+ setSelection(this.binding.messagesView, pos, jumpToBottom);
+ this.binding.messagesView.post(() -> setSelection(this.binding.messagesView, pos, jumpToBottom));
this.binding.messagesView.post(this::fireReadEvent);
}
- private boolean scrolledToBottom() {
- if (this.binding == null) {
- return false;
+ private static void setSelection(final ListView listView, int pos, boolean jumpToBottom) {
+ if (jumpToBottom) {
+ final View lastChild = listView.getChildAt(listView.getChildCount() - 1);
+ if (lastChild != null) {
+ listView.setSelectionFromTop(pos, -lastChild.getHeight());
+ return;
+ }
}
- return scrolledToBottom(this.binding.messagesView);
+ listView.setSelection(pos);
+ }
+
+ private boolean scrolledToBottom() {
+ return this.binding != null && scrolledToBottom(this.binding.messagesView);
}
private void processExtras(Bundle extras) {