mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	Conversation messages images are displayed
This commit is contained in:
		@@ -100,6 +100,15 @@ public class ConversationMessage {
 | 
			
		||||
        return image_path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check whether the message has an associated image or not
 | 
			
		||||
     *
 | 
			
		||||
     * @return TRUE if the message has an associated image / FALSE else
 | 
			
		||||
     */
 | 
			
		||||
    public boolean hasImage(){
 | 
			
		||||
        return image_path != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the path of the image associated with the content
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -88,8 +88,9 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
 | 
			
		||||
            Update the general layout of the message
 | 
			
		||||
         */
 | 
			
		||||
        TextView contentView;
 | 
			
		||||
        ImageView accountImage;
 | 
			
		||||
        TextView userName;
 | 
			
		||||
        ImageView messageImageView;
 | 
			
		||||
        ImageView accountImageView;
 | 
			
		||||
        TextView userNameView;
 | 
			
		||||
        if(message.getUser_id() == userID){
 | 
			
		||||
 | 
			
		||||
            //Message appears on the right
 | 
			
		||||
@@ -101,10 +102,14 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
 | 
			
		||||
            contentView = convertView.
 | 
			
		||||
                    findViewById(R.id.fragment_conversation_message_item_content_right);
 | 
			
		||||
 | 
			
		||||
            accountImage = convertView.
 | 
			
		||||
            messageImageView = convertView.
 | 
			
		||||
                    findViewById(R.id.fragment_conversation_message_item_messageimage_right);
 | 
			
		||||
 | 
			
		||||
            accountImageView = convertView.
 | 
			
		||||
                    findViewById(R.id.fragment_conversation_message_item_accountimage_right);
 | 
			
		||||
 | 
			
		||||
            userName = null;
 | 
			
		||||
 | 
			
		||||
            userNameView = null;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
 | 
			
		||||
@@ -117,10 +122,13 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
 | 
			
		||||
            contentView = convertView.
 | 
			
		||||
                    findViewById(R.id.fragment_conversation_message_item_content);
 | 
			
		||||
 | 
			
		||||
            accountImage = convertView.
 | 
			
		||||
            messageImageView = convertView.
 | 
			
		||||
                    findViewById(R.id.fragment_conversation_message_item_messageimage);
 | 
			
		||||
 | 
			
		||||
            accountImageView = convertView.
 | 
			
		||||
                    findViewById(R.id.fragment_conversation_message_item_accountimage);
 | 
			
		||||
 | 
			
		||||
            userName = convertView.findViewById(R.id.fragment_conversation_message_item_username);
 | 
			
		||||
            userNameView = convertView.findViewById(R.id.fragment_conversation_message_item_username);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
@@ -139,22 +147,37 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
 | 
			
		||||
        contentView.setText(message.getContent());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
            Update message image
 | 
			
		||||
         */
 | 
			
		||||
        if(message.hasImage()){
 | 
			
		||||
            //Load the image
 | 
			
		||||
            ImageLoadManager.remove(messageImageView);
 | 
			
		||||
            ImageLoadManager.load(getContext(), message.getImage_path(), messageImageView);
 | 
			
		||||
 | 
			
		||||
            //Make the image visible
 | 
			
		||||
            messageImageView.setVisibility(View.VISIBLE);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            messageImageView.setVisibility(View.GONE);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
            Update user name
 | 
			
		||||
         */
 | 
			
		||||
        if(userName != null){
 | 
			
		||||
        if(userNameView != null){
 | 
			
		||||
 | 
			
		||||
            if(user != null){
 | 
			
		||||
                //Set the name of the user
 | 
			
		||||
                userName.setText(user.getFullName());
 | 
			
		||||
                userName.setVisibility(View.VISIBLE);
 | 
			
		||||
                userNameView.setText(user.getFullName());
 | 
			
		||||
                userNameView.setVisibility(View.VISIBLE);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
                userName.setVisibility(View.GONE);
 | 
			
		||||
                userNameView.setVisibility(View.GONE);
 | 
			
		||||
 | 
			
		||||
            if(previousMessage != null){
 | 
			
		||||
                if (message.getUser_id() == previousMessage.getUser_id()){
 | 
			
		||||
                    userName.setVisibility(View.GONE);
 | 
			
		||||
                    userNameView.setVisibility(View.GONE);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -164,22 +187,22 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
 | 
			
		||||
            Update account image
 | 
			
		||||
         */
 | 
			
		||||
        //Cancel any load pending operation
 | 
			
		||||
        ImageLoadManager.remove(accountImage);
 | 
			
		||||
        ImageLoadManager.remove(accountImageView);
 | 
			
		||||
 | 
			
		||||
        //Set the default image
 | 
			
		||||
        accountImage.setImageResource(R.drawable.default_account_image);
 | 
			
		||||
        accountImage.setVisibility(View.VISIBLE);
 | 
			
		||||
        accountImageView.setImageResource(R.drawable.default_account_image);
 | 
			
		||||
        accountImageView.setVisibility(View.VISIBLE);
 | 
			
		||||
 | 
			
		||||
        //Check if we can load a specific image
 | 
			
		||||
        if(user != null) {
 | 
			
		||||
            String imageURL = user.getAcountImageURL();
 | 
			
		||||
            ImageLoadManager.load(getContext(), imageURL, accountImage);
 | 
			
		||||
            ImageLoadManager.load(getContext(), imageURL, accountImageView);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Hide user image if not required
 | 
			
		||||
        if(previousMessage != null){
 | 
			
		||||
            if (message.getUser_id() == previousMessage.getUser_id()){
 | 
			
		||||
                accountImage.setVisibility(View.INVISIBLE);
 | 
			
		||||
                accountImageView.setVisibility(View.INVISIBLE);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,6 @@
 | 
			
		||||
            tools:text="User name" />
 | 
			
		||||
 | 
			
		||||
        <RelativeLayout
 | 
			
		||||
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:padding="1dp">
 | 
			
		||||
@@ -34,21 +33,40 @@
 | 
			
		||||
                android:layout_height="26dp"
 | 
			
		||||
                android:layout_gravity="center"
 | 
			
		||||
                android:layout_marginEnd="5dp"
 | 
			
		||||
                android:src="@drawable/default_account_image"
 | 
			
		||||
                android:contentDescription="@string/user_image_description"/>
 | 
			
		||||
                android:contentDescription="@string/user_image_description"
 | 
			
		||||
                android:src="@drawable/default_account_image"/>
 | 
			
		||||
 | 
			
		||||
            <TextView
 | 
			
		||||
                android:id="@+id/fragment_conversation_message_item_content"
 | 
			
		||||
            <LinearLayout
 | 
			
		||||
                android:layout_width="wrap_content"
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:layout_gravity="center"
 | 
			
		||||
                android:layout_toEndOf="@id/fragment_conversation_message_item_accountimage"
 | 
			
		||||
                android:padding="5dp"
 | 
			
		||||
                android:paddingEnd="15dp"
 | 
			
		||||
                android:paddingStart="15dp"
 | 
			
		||||
                android:textColor="@color/conversation_otheruser_messages_textColor"
 | 
			
		||||
                android:background="@drawable/fragment_conversation_message_otheruser_bg"
 | 
			
		||||
                tools:text="A message" />
 | 
			
		||||
                android:orientation="vertical"
 | 
			
		||||
                android:paddingBottom="5dp"
 | 
			
		||||
                android:paddingEnd="15dp"
 | 
			
		||||
                android:paddingStart="15dp">
 | 
			
		||||
 | 
			
		||||
                <TextView
 | 
			
		||||
                    android:id="@+id/fragment_conversation_message_item_content"
 | 
			
		||||
                    android:layout_width="wrap_content"
 | 
			
		||||
                    android:layout_height="wrap_content"
 | 
			
		||||
                    android:layout_gravity="center"
 | 
			
		||||
                    android:padding="5dp"
 | 
			
		||||
                    android:textColor="@color/conversation_otheruser_messages_textColor"
 | 
			
		||||
                    tools:text="A message" />
 | 
			
		||||
 | 
			
		||||
                <ImageView
 | 
			
		||||
                    android:id="@+id/fragment_conversation_message_item_messageimage"
 | 
			
		||||
                    android:layout_width="wrap_content"
 | 
			
		||||
                    android:layout_height="wrap_content"
 | 
			
		||||
                    android:layout_gravity="center"
 | 
			
		||||
                    android:contentDescription="@string/fragment_conversation_message_image"
 | 
			
		||||
                    tools:background="@android:color/black"
 | 
			
		||||
                    tools:layout_height="40dp"
 | 
			
		||||
                    tools:layout_width="40dp"/>
 | 
			
		||||
            </LinearLayout>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        </RelativeLayout>
 | 
			
		||||
 | 
			
		||||
@@ -71,18 +89,38 @@
 | 
			
		||||
            android:contentDescription="@string/user_image_description"
 | 
			
		||||
            android:src="@drawable/default_account_image" />
 | 
			
		||||
 | 
			
		||||
        <TextView
 | 
			
		||||
            android:id="@+id/fragment_conversation_message_item_content_right"
 | 
			
		||||
        <LinearLayout
 | 
			
		||||
            android:layout_width="wrap_content"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:layout_gravity="center"
 | 
			
		||||
            android:layout_toStartOf="@id/fragment_conversation_message_item_accountimage_right"
 | 
			
		||||
            android:background="@drawable/fragment_conversation_message_currentuser_bg"
 | 
			
		||||
            android:padding="5dp"
 | 
			
		||||
            android:orientation="vertical"
 | 
			
		||||
            android:paddingBottom="5dp"
 | 
			
		||||
            android:paddingEnd="15dp"
 | 
			
		||||
            android:paddingStart="15dp"
 | 
			
		||||
            android:textColor="@color/conversation_user_messages_textColor"
 | 
			
		||||
            tools:text="A message" />
 | 
			
		||||
            android:paddingStart="15dp">
 | 
			
		||||
 | 
			
		||||
            <TextView
 | 
			
		||||
                android:id="@+id/fragment_conversation_message_item_content_right"
 | 
			
		||||
                android:layout_width="wrap_content"
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:layout_gravity="center"
 | 
			
		||||
                android:padding="5dp"
 | 
			
		||||
                android:textColor="@color/conversation_user_messages_textColor"
 | 
			
		||||
                tools:text="A message" />
 | 
			
		||||
 | 
			
		||||
            <ImageView
 | 
			
		||||
                android:id="@+id/fragment_conversation_message_item_messageimage_right"
 | 
			
		||||
                android:layout_width="wrap_content"
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:layout_gravity="center"
 | 
			
		||||
                android:contentDescription="@string/fragment_conversation_message_image"
 | 
			
		||||
                tools:background="@android:color/black"
 | 
			
		||||
                tools:layout_height="40dp"
 | 
			
		||||
                tools:layout_width="40dp"/>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        </LinearLayout>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    </RelativeLayout>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -52,4 +52,5 @@
 | 
			
		||||
    <string name="date_hours">date_hours</string>
 | 
			
		||||
    <string name="err_get_user_info">Couldn\'t get user information !</string>
 | 
			
		||||
    <string name="fragment_conversation_err_load_message">Could not load messages!</string>
 | 
			
		||||
    <string name="fragment_conversation_message_image">Conversation message image</string>
 | 
			
		||||
</resources>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user