mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Fix issue on user information load.
This commit is contained in:
parent
c672891e3e
commit
82493db25b
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,53 +19,59 @@
|
|||||||
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" />
|
||||||
|
|
||||||
<!-- 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
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent">
|
||||||
android:background="@color/conversation_footer_bg">
|
|
||||||
|
|
||||||
<EditText
|
<!-- Messages -->
|
||||||
android:id="@+id/fragment_conversation_newmessage_content"
|
<org.communiquons.android.comunic.client.ui.views.ScrollListView
|
||||||
android:layout_width="0dp"
|
android:id="@+id/fragment_conversation_messageslist"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
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:layout_height="wrap_content"
|
||||||
android:inputType="text"
|
android:background="@color/conversation_footer_bg">
|
||||||
android:hint="@string/fragment_conversation_new_message_placeholder"/>
|
|
||||||
|
|
||||||
<ImageButton
|
<EditText
|
||||||
android:id="@+id/fragment_conversation_newmessage_pickimage"
|
android:id="@+id/fragment_conversation_newmessage_content"
|
||||||
android:layout_width="@dimen/fragment_conversation_buttons_width"
|
android:layout_width="0dp"
|
||||||
android:layout_height="@dimen/fragment_conversation_buttons_height"
|
android:layout_weight="1"
|
||||||
android:src="@android:drawable/ic_menu_gallery"
|
android:layout_height="wrap_content"
|
||||||
android:scaleType="fitCenter"
|
android:inputType="text"
|
||||||
android:contentDescription="@string/conversation_message_add_image"/>
|
android:hint="@string/fragment_conversation_new_message_placeholder"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/fragment_conversation_newmessage_send"
|
android:id="@+id/fragment_conversation_newmessage_pickimage"
|
||||||
android:layout_width="@dimen/fragment_conversation_buttons_width"
|
android:layout_width="@dimen/fragment_conversation_buttons_width"
|
||||||
android:layout_height="@dimen/fragment_conversation_buttons_height"
|
android:layout_height="@dimen/fragment_conversation_buttons_height"
|
||||||
android:src="@android:drawable/ic_menu_send"
|
android:src="@android:drawable/ic_menu_gallery"
|
||||||
android:contentDescription="@string/conversation_message_send"/>
|
android:scaleType="fitCenter"
|
||||||
|
android:contentDescription="@string/conversation_message_add_image"/>
|
||||||
|
|
||||||
<ProgressBar
|
<ImageButton
|
||||||
android:id="@+id/fragment_conversation_newmessage_loading"
|
android:id="@+id/fragment_conversation_newmessage_send"
|
||||||
android:layout_width="@dimen/fragment_conversation_buttons_width"
|
android:layout_width="@dimen/fragment_conversation_buttons_width"
|
||||||
android:layout_height="@dimen/fragment_conversation_buttons_height" />
|
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>
|
||||||
</LinearLayout>
|
|
Loading…
Reference in New Issue
Block a user