scroll to bottom even if last visible item is heigher than view
This commit is contained in:
parent
2a9413e64d
commit
cfaebbdbd1
|
@ -92,7 +92,6 @@ import eu.siacs.conversations.ui.util.ScrollState;
|
||||||
import eu.siacs.conversations.ui.util.SendButtonAction;
|
import eu.siacs.conversations.ui.util.SendButtonAction;
|
||||||
import eu.siacs.conversations.ui.util.SendButtonTool;
|
import eu.siacs.conversations.ui.util.SendButtonTool;
|
||||||
import eu.siacs.conversations.ui.widget.EditMessage;
|
import eu.siacs.conversations.ui.widget.EditMessage;
|
||||||
import eu.siacs.conversations.utils.ExceptionHelper;
|
|
||||||
import eu.siacs.conversations.utils.MessageUtils;
|
import eu.siacs.conversations.utils.MessageUtils;
|
||||||
import eu.siacs.conversations.utils.NickValidityChecker;
|
import eu.siacs.conversations.utils.NickValidityChecker;
|
||||||
import eu.siacs.conversations.utils.QuickLoader;
|
import eu.siacs.conversations.utils.QuickLoader;
|
||||||
|
@ -374,7 +373,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
stopScrolling();
|
stopScrolling();
|
||||||
setSelection(binding.messagesView.getCount() - 1);
|
setSelection(binding.messagesView.getCount() - 1, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private OnClickListener mSendButtonListener = new OnClickListener() {
|
private OnClickListener mSendButtonListener = new OnClickListener() {
|
||||||
|
@ -1938,13 +1937,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
final Message first = conversation.getFirstUnreadMessage();
|
final Message first = conversation.getFirstUnreadMessage();
|
||||||
final int bottom = Math.max(0, this.messageList.size() - 1);
|
final int bottom = Math.max(0, this.messageList.size() - 1);
|
||||||
final int pos;
|
final int pos;
|
||||||
|
final boolean jumpToBottom;
|
||||||
if (first == null) {
|
if (first == null) {
|
||||||
pos = bottom;
|
pos = bottom;
|
||||||
|
jumpToBottom = true;
|
||||||
} else {
|
} else {
|
||||||
int i = getIndexOf(first.getUuid(), this.messageList);
|
int i = getIndexOf(first.getUuid(), this.messageList);
|
||||||
pos = i < 0 ? bottom : i;
|
pos = i < 0 ? bottom : i;
|
||||||
|
jumpToBottom = false;
|
||||||
}
|
}
|
||||||
setSelection(pos);
|
setSelection(pos, jumpToBottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1969,17 +1971,25 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
this.binding.unreadCountCustomView.setVisibility(View.GONE);
|
this.binding.unreadCountCustomView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSelection(int pos) {
|
private void setSelection(int pos, boolean jumpToBottom) {
|
||||||
this.binding.messagesView.setSelection(pos);
|
setSelection(this.binding.messagesView, pos, jumpToBottom);
|
||||||
this.binding.messagesView.post(() -> this.binding.messagesView.setSelection(pos));
|
this.binding.messagesView.post(() -> setSelection(this.binding.messagesView, pos, jumpToBottom));
|
||||||
this.binding.messagesView.post(this::fireReadEvent);
|
this.binding.messagesView.post(this::fireReadEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean scrolledToBottom() {
|
private static void setSelection(final ListView listView, int pos, boolean jumpToBottom) {
|
||||||
if (this.binding == null) {
|
if (jumpToBottom) {
|
||||||
return false;
|
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) {
|
private void processExtras(Bundle extras) {
|
||||||
|
|
Loading…
Reference in a new issue