From 82493db25bbc1a364681808198b4fb50c16441e3 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 28 Apr 2018 14:30:37 +0200 Subject: [PATCH] Fix issue on user information load. --- .../ui/fragments/ConversationFragment.java | 57 +++++++++--- .../main/res/layout/fragment_conversation.xml | 91 ++++++++++--------- 2 files changed, 93 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java index 6a060c4..9c34287 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java @@ -356,19 +356,46 @@ public class ConversationFragment extends Fragment display_main_progress_bar(false); display_not_msg_notice(false); - final ArrayList usersToFetch = new ArrayList<>(); - //Add the messages to the the main list of messages for(ConversationMessage message : newMessages){ messagesList.add(message); - - if(!users.containsKey(message.getUser_id())) - usersToFetch.add(message.getUser_id()); } convMessAdapter.notifyDataSetChanged(); last_message_id = lastID; + //Make sure we have got information about all the members of the conversation + refreshUserInfo(); + } + + @Override + public void onLoadError() { + //Display a toast + Toast.makeText(getActivity(), R.string.fragment_conversation_err_load_message, + Toast.LENGTH_SHORT).show(); + } + + /** + * Make sure we have got the information about all the users of the conversation + */ + private void refreshUserInfo(){ + + if(messagesList == null) + return; + + final ArrayList usersToFetch = new ArrayList<>(); + + //Process the list of messages + for(ConversationMessage message : messagesList){ + + if(!users.containsKey(message.getUser_id())){ + if(!usersToFetch.contains(message.getUser_id())) + usersToFetch.add(message.getUser_id()); + } + + } + + //Fetch user information if required if(usersToFetch.size() > 0){ new AsyncTask>(){ @@ -386,13 +413,6 @@ public class ConversationFragment extends Fragment } } - @Override - public void onLoadError() { - //Display a toast - Toast.makeText(getActivity(), R.string.fragment_conversation_err_load_message, - Toast.LENGTH_SHORT).show(); - } - /** * This method is called when we get informations about users * @@ -634,6 +654,9 @@ public class ConversationFragment extends Fragment if(mGetOlderMessagesTask != null) return; + //Display progress bar + display_main_progress_bar(true); + //Create and execute the task mGetOlderMessagesTask = new AsyncTask>(){ @@ -664,17 +687,25 @@ public class ConversationFragment extends Fragment //Remove link over task mGetOlderMessagesTask = null; + //Remove progress bar + display_main_progress_bar(false); + //Check if the list is null (in case of error) - if(list == null) + if(list == null) { return; + } if(list.size() == 0) return; + Log.v(TAG, "List size: " + list.size()); //Add the messages to the list messagesList.addAll(0, list); //Notify adapter convMessAdapter.notifyDataSetChanged(); + + //Refresh user information if required + refreshUserInfo(); } } diff --git a/app/src/main/res/layout/fragment_conversation.xml b/app/src/main/res/layout/fragment_conversation.xml index 1dc0435..1b19a43 100644 --- a/app/src/main/res/layout/fragment_conversation.xml +++ b/app/src/main/res/layout/fragment_conversation.xml @@ -1,6 +1,6 @@ - @@ -9,7 +9,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginTop="10dp"/> + android:layout_marginTop="10dp" + android:layout_centerHorizontal="true"/> + android:layout_marginTop="70dp" /> - - - - + android:layout_height="match_parent"> - + + + + + android:background="@color/conversation_footer_bg"> - + - + - + + + + + - - \ No newline at end of file + \ No newline at end of file