Automatically scroll to bottom

This commit is contained in:
Pierre HUBERT 2018-08-16 09:28:17 +02:00
parent a0feee9516
commit e579891f73
3 changed files with 16 additions and 4 deletions

View File

@ -185,8 +185,8 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
if(pos < 2) if(pos < 2)
setUserInfoVisibility(true); setUserInfoVisibility(true);
else else
if(mList.get(pos).getUser_id() == mList.get(pos-1).getUser_id()) setUserInfoVisibility(
setUserInfoVisibility(false); !(mList.get(pos).getUser_id() == mList.get(pos-1).getUser_id()));
} }
} }
} }

View File

@ -112,6 +112,11 @@ public class ConversationFragment extends Fragment
*/ */
private RecyclerView convMessRecyclerView; private RecyclerView convMessRecyclerView;
/**
* Conversation messages layout manager
*/
private LinearLayoutManager mLinearLayoutManager;
/** /**
* Conversation messages helper * Conversation messages helper
*/ */
@ -231,8 +236,11 @@ public class ConversationFragment extends Fragment
messagesList, userID); messagesList, userID);
//Apply adapter //Apply adapter
convMessRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); mLinearLayoutManager = new LinearLayoutManager(getActivity());
convMessRecyclerView.setLayoutManager(mLinearLayoutManager);
convMessRecyclerView.setAdapter(convMessAdapter); convMessRecyclerView.setAdapter(convMessAdapter);
mLinearLayoutManager.setStackFromEnd(true);
//Get new messages input fields //Get new messages input fields
new_message_content = view.findViewById(R.id.fragment_conversation_newmessage_content); new_message_content = view.findViewById(R.id.fragment_conversation_newmessage_content);
@ -283,7 +291,7 @@ public class ConversationFragment extends Fragment
//Set a listener to detect when the user reaches the top of the conversation //Set a listener to detect when the user reaches the top of the conversation
//convMessRecyclerView.setOnScrollChangeDetectListener(this); //TODO : add reach top listener
} }
@Override @Override
@ -357,6 +365,9 @@ public class ConversationFragment extends Fragment
//Make sure we have got information about all the members of the conversation //Make sure we have got information about all the members of the conversation
refreshUserInfo(); refreshUserInfo();
//Scroll to bottom
convMessRecyclerView.scrollToPosition(messagesList.size() - 1);
} }
@Override @Override

View File

@ -35,6 +35,7 @@
android:divider="@null" android:divider="@null"
android:stackFromBottom="true" android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" android:transcriptMode="alwaysScroll"
android:layout_marginBottom="5dp"
/> />
<!-- Send messages form --> <!-- Send messages form -->