Fix issue on user information load.

This commit is contained in:
Pierre 2018-04-28 14:30:37 +02:00
parent c672891e3e
commit 82493db25b
2 changed files with 93 additions and 55 deletions

View File

@ -356,19 +356,46 @@ public class ConversationFragment extends Fragment
display_main_progress_bar(false); display_main_progress_bar(false);
display_not_msg_notice(false); display_not_msg_notice(false);
final ArrayList<Integer> usersToFetch = new ArrayList<>();
//Add the messages to the the main list of messages //Add the messages to the the main list of messages
for(ConversationMessage message : newMessages){ for(ConversationMessage message : newMessages){
messagesList.add(message); messagesList.add(message);
if(!users.containsKey(message.getUser_id()))
usersToFetch.add(message.getUser_id());
} }
convMessAdapter.notifyDataSetChanged(); convMessAdapter.notifyDataSetChanged();
last_message_id = lastID; 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<Integer> 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 //Fetch user information if required
if(usersToFetch.size() > 0){ if(usersToFetch.size() > 0){
new AsyncTask<Void, Void, ArrayMap<Integer, UserInfo>>(){ new AsyncTask<Void, Void, ArrayMap<Integer, UserInfo>>(){
@ -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 * This method is called when we get informations about users
* *
@ -634,6 +654,9 @@ public class ConversationFragment extends Fragment
if(mGetOlderMessagesTask != null) if(mGetOlderMessagesTask != null)
return; return;
//Display progress bar
display_main_progress_bar(true);
//Create and execute the task //Create and execute the task
mGetOlderMessagesTask = new AsyncTask<Void, Void, ArrayList<ConversationMessage>>(){ mGetOlderMessagesTask = new AsyncTask<Void, Void, ArrayList<ConversationMessage>>(){
@ -664,17 +687,25 @@ public class ConversationFragment extends Fragment
//Remove link over task //Remove link over task
mGetOlderMessagesTask = null; mGetOlderMessagesTask = null;
//Remove progress bar
display_main_progress_bar(false);
//Check if the list is null (in case of error) //Check if the list is null (in case of error)
if(list == null) if(list == null) {
return; return;
}
if(list.size() == 0) if(list.size() == 0)
return; return;
Log.v(TAG, "List size: " + list.size());
//Add the messages to the list //Add the messages to the list
messagesList.addAll(0, list); messagesList.addAll(0, list);
//Notify adapter //Notify adapter
convMessAdapter.notifyDataSetChanged(); convMessAdapter.notifyDataSetChanged();
//Refresh user information if required
refreshUserInfo();
} }
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<!-- Loading wheel --> <!-- Loading wheel -->
@ -9,7 +9,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginTop="10dp"/> android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
<!-- No message notice --> <!-- No message notice -->
<TextView <TextView
@ -18,7 +19,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/fragment_conversation_no_msg" android:text="@string/fragment_conversation_no_msg"
android:textAlignment="center" android:textAlignment="center"
android:layout_marginTop="10dp"/> android:layout_marginTop="70dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Messages --> <!-- Messages -->
<org.communiquons.android.comunic.client.ui.views.ScrollListView <org.communiquons.android.comunic.client.ui.views.ScrollListView
@ -68,3 +74,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</RelativeLayout>