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 ...@@ -215,10 +215,17 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
}); });
updateChat();
return view; return view;
} }
@Override
public void onResume() {
super.onResume();
listener.registerChat(this);
updateChat();
restoreInputState();
}
@Override @Override
public void onDetach() { public void onDetach() {
...@@ -267,16 +274,6 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -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() { public void restoreInputState() {
skipOnTextChanges = true; skipOnTextChanges = true;
...@@ -361,7 +358,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -361,7 +358,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
public void updateChat() { public void updateChat() {
ContactTitleInflater.updateTitle(contactTitleView, getActivity(), abstractContact); ContactTitleInflater.updateTitle(contactTitleView, getActivity(), abstractContact);
int itemCountBeforeUpdate = recyclerView.getAdapter().getItemCount(); int itemCountBeforeUpdate = chatMessageAdapter.getItemCount();
chatMessageAdapter.onChange(); chatMessageAdapter.onChange();
scrollChat(itemCountBeforeUpdate); scrollChat(itemCountBeforeUpdate);
setUpOptionsMenu(toolbar.getMenu()); setUpOptionsMenu(toolbar.getMenu());
...@@ -369,9 +366,14 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -369,9 +366,14 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
} }
private void scrollChat(int itemCountBeforeUpdate) { private void scrollChat(int itemCountBeforeUpdate) {
if (layoutManager.findLastVisibleItemPosition() == (itemCountBeforeUpdate - 1)) { int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
recyclerView.scrollToPosition(chatMessageAdapter.getItemCount() - 1); if (lastVisibleItemPosition == -1 || lastVisibleItemPosition == (itemCountBeforeUpdate - 1)) {
scrollDown();
}
} }
private void scrollDown() {
recyclerView.scrollToPosition(chatMessageAdapter.getItemCount() - 1);
} }
private void updateSecurityButton() { 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