Commit 5b19c90a authored by Grigory Fedorov's avatar Grigory Fedorov

Chat messages scroll corrected: chat was not scrolled down for new messages in some situations.

parent 9937f1ba
......@@ -215,10 +215,17 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
});
updateChat();
return view;
}
@Override
public void onResume() {
super.onResume();
listener.registerChat(this);
updateChat();
restoreInputState();
}
@Override
public void onDetach() {
......@@ -267,16 +274,6 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
}
}
@Override
public void onResume() {
super.onResume();
listener.registerChat(this);
updateChat();
restoreInputState();
}
public void restoreInputState() {
skipOnTextChanges = true;
......@@ -361,7 +358,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
public void updateChat() {
ContactTitleInflater.updateTitle(contactTitleView, getActivity(), abstractContact);
int itemCountBeforeUpdate = recyclerView.getAdapter().getItemCount();
int itemCountBeforeUpdate = chatMessageAdapter.getItemCount();
chatMessageAdapter.onChange();
scrollChat(itemCountBeforeUpdate);
setUpOptionsMenu(toolbar.getMenu());
......@@ -369,9 +366,14 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
}
private void scrollChat(int itemCountBeforeUpdate) {
if (layoutManager.findLastVisibleItemPosition() == (itemCountBeforeUpdate - 1)) {
recyclerView.scrollToPosition(chatMessageAdapter.getItemCount() - 1);
int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
if (lastVisibleItemPosition == -1 || lastVisibleItemPosition == (itemCountBeforeUpdate - 1)) {
scrollDown();
}
}
private void scrollDown() {
recyclerView.scrollToPosition(chatMessageAdapter.getItemCount() - 1);
}
private void updateSecurityButton() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment