Does not scroll to bottom of current conversation if no new SMS are received in this conversation

This commit is contained in:
Stéphane BAUSSERON
2016-08-10 17:53:56 +02:00
committed by Stéphane BAUSSERON
parent e134516b3c
commit 00430de112
@@ -208,6 +208,7 @@ public class MessageListFragment extends QKFragment implements ActivityLauncher,
mAdapter.setItemClickListener(this);
mAdapter.setMultiSelectListener(this);
mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
private long mLastMessageId = -1;
@Override
public void onChanged() {
LinearLayoutManager manager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
@@ -225,8 +226,15 @@ public class MessageListFragment extends QKFragment implements ActivityLauncher,
position = mAdapter.getItemCount() - 1;
}
if (position != -1) {
manager.smoothScrollToPosition(mRecyclerView, null, position);
if(mAdapter.getCount() > 0) {
MessageItem lastMessage = mAdapter.getItem(mAdapter.getCount() - 1);
if (mLastMessageId >= 0 && mLastMessageId != lastMessage.getMessageId()) {
// Scroll to bottom only if a new message was inserted in this conversation
if (position != -1) {
manager.smoothScrollToPosition(mRecyclerView, null, position);
}
}
mLastMessageId = lastMessage.getMessageId();
}
}
});