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_not_msg_notice(false);
final ArrayList<Integer> 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<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
if(usersToFetch.size() > 0){
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
*
@ -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<Void, Void, ArrayList<ConversationMessage>>(){
@ -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();
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Loading wheel -->
@ -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"/>
<!-- No message notice -->
<TextView
@ -18,53 +19,59 @@
android:layout_height="wrap_content"
android:text="@string/fragment_conversation_no_msg"
android:textAlignment="center"
android:layout_marginTop="10dp"/>
android:layout_marginTop="70dp" />
<!-- Messages -->
<org.communiquons.android.comunic.client.ui.views.ScrollListView
android:id="@+id/fragment_conversation_messageslist"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
/>
<!-- Send messages form -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/conversation_footer_bg">
android:layout_height="match_parent">
<EditText
android:id="@+id/fragment_conversation_newmessage_content"
android:layout_width="0dp"
<!-- Messages -->
<org.communiquons.android.comunic.client.ui.views.ScrollListView
android:id="@+id/fragment_conversation_messageslist"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
/>
<!-- Send messages form -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/fragment_conversation_new_message_placeholder"/>
android:background="@color/conversation_footer_bg">
<ImageButton
android:id="@+id/fragment_conversation_newmessage_pickimage"
android:layout_width="@dimen/fragment_conversation_buttons_width"
android:layout_height="@dimen/fragment_conversation_buttons_height"
android:src="@android:drawable/ic_menu_gallery"
android:scaleType="fitCenter"
android:contentDescription="@string/conversation_message_add_image"/>
<EditText
android:id="@+id/fragment_conversation_newmessage_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/fragment_conversation_new_message_placeholder"/>
<ImageButton
android:id="@+id/fragment_conversation_newmessage_send"
android:layout_width="@dimen/fragment_conversation_buttons_width"
android:layout_height="@dimen/fragment_conversation_buttons_height"
android:src="@android:drawable/ic_menu_send"
android:contentDescription="@string/conversation_message_send"/>
<ImageButton
android:id="@+id/fragment_conversation_newmessage_pickimage"
android:layout_width="@dimen/fragment_conversation_buttons_width"
android:layout_height="@dimen/fragment_conversation_buttons_height"
android:src="@android:drawable/ic_menu_gallery"
android:scaleType="fitCenter"
android:contentDescription="@string/conversation_message_add_image"/>
<ProgressBar
android:id="@+id/fragment_conversation_newmessage_loading"
android:layout_width="@dimen/fragment_conversation_buttons_width"
android:layout_height="@dimen/fragment_conversation_buttons_height" />
<ImageButton
android:id="@+id/fragment_conversation_newmessage_send"
android:layout_width="@dimen/fragment_conversation_buttons_width"
android:layout_height="@dimen/fragment_conversation_buttons_height"
android:src="@android:drawable/ic_menu_send"
android:contentDescription="@string/conversation_message_send"/>
<ProgressBar
android:id="@+id/fragment_conversation_newmessage_loading"
android:layout_width="@dimen/fragment_conversation_buttons_width"
android:layout_height="@dimen/fragment_conversation_buttons_height" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>