Commit ec6fd8d3 authored by Grigory Fedorov's avatar Grigory Fedorov

Chat scroll to bottom disabled if it was scrolled up manually.

parent b9f4d741
...@@ -77,6 +77,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -77,6 +77,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
private RecyclerView recyclerView; private RecyclerView recyclerView;
private View contactTitleView; private View contactTitleView;
private AbstractContact abstractContact; private AbstractContact abstractContact;
private LinearLayoutManager layoutManager;
public static ChatViewerFragment newInstance(String account, String user) { public static ChatViewerFragment newInstance(String account, String user) {
ChatViewerFragment fragment = new ChatViewerFragment(); ChatViewerFragment fragment = new ChatViewerFragment();
...@@ -157,7 +158,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -157,7 +158,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
recyclerView = (RecyclerView) view.findViewById(R.id.chat_messages_recycler_view); recyclerView = (RecyclerView) view.findViewById(R.id.chat_messages_recycler_view);
recyclerView.setAdapter(chatMessageAdapter); recyclerView.setAdapter(chatMessageAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setStackFromEnd(true); layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
...@@ -408,12 +409,19 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -408,12 +409,19 @@ 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();
chatMessageAdapter.onChange(); chatMessageAdapter.onChange();
recyclerView.scrollToPosition(chatMessageAdapter.getItemCount() - 1); scrollChat(itemCountBeforeUpdate);
setUpOptionsMenu(toolbar.getMenu()); setUpOptionsMenu(toolbar.getMenu());
updateSecurityButton(); updateSecurityButton();
} }
private void scrollChat(int itemCountBeforeUpdate) {
if (layoutManager.findLastVisibleItemPosition() == (itemCountBeforeUpdate - 1)) {
recyclerView.scrollToPosition(chatMessageAdapter.getItemCount() - 1);
}
}
private void updateSecurityButton() { private void updateSecurityButton() {
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user); SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
securityButton.setImageLevel(securityLevel.getImageLevel()); securityButton.setImageLevel(securityLevel.getImageLevel());
......
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