mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-30 09:16:36 +00:00
Improved views layout
This commit is contained in:
parent
0f2f28ec36
commit
e04ec17272
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -75,6 +76,12 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
|
||||
ConversationMessage message = getItem(position);
|
||||
assert message != null;
|
||||
|
||||
//Get the previous message
|
||||
ConversationMessage previousMessage = null;
|
||||
if(position > 0){
|
||||
previousMessage = getItem(position-1);
|
||||
}
|
||||
|
||||
/*
|
||||
Get the view of the messages
|
||||
|
||||
@ -82,29 +89,38 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
|
||||
*/
|
||||
TextView contentView;
|
||||
ImageView accountImage;
|
||||
TextView userName;
|
||||
if(message.getUser_id() == userID){
|
||||
|
||||
//Message appears on the right
|
||||
convertView.findViewById(R.id.fragment_conversation_message_left).
|
||||
setVisibility(View.GONE);
|
||||
convertView.findViewById(R.id.fragment_conversation_message_right).
|
||||
setVisibility(View.VISIBLE);
|
||||
|
||||
contentView = convertView.
|
||||
findViewById(R.id.fragment_conversation_message_item_content_right);
|
||||
|
||||
accountImage = convertView.
|
||||
findViewById(R.id.fragment_conversation_message_item_accountimage_right);
|
||||
|
||||
userName = null;
|
||||
}
|
||||
else {
|
||||
|
||||
//Message appears on the left
|
||||
convertView.findViewById(R.id.fragment_conversation_message_right).
|
||||
setVisibility(View.GONE);
|
||||
convertView.findViewById(R.id.fragment_conversation_message_left).
|
||||
setVisibility(View.VISIBLE);
|
||||
|
||||
contentView = convertView.
|
||||
findViewById(R.id.fragment_conversation_message_item_content);
|
||||
|
||||
accountImage = convertView.
|
||||
findViewById(R.id.fragment_conversation_message_item_accountimage);
|
||||
|
||||
userName = convertView.findViewById(R.id.fragment_conversation_message_item_username);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -123,6 +139,27 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
|
||||
contentView.setText(message.getContent());
|
||||
|
||||
|
||||
/*
|
||||
Update user name
|
||||
*/
|
||||
if(userName != null){
|
||||
|
||||
if(user != null){
|
||||
//Set the name of the user
|
||||
userName.setText(user.getFullName());
|
||||
userName.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else
|
||||
userName.setVisibility(View.GONE);
|
||||
|
||||
if(previousMessage != null){
|
||||
if (message.getUser_id() == previousMessage.getUser_id()){
|
||||
userName.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Update account image
|
||||
*/
|
||||
@ -131,6 +168,7 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
|
||||
|
||||
//Set the default image
|
||||
accountImage.setImageResource(R.drawable.default_account_image);
|
||||
accountImage.setVisibility(View.VISIBLE);
|
||||
|
||||
//Check if we can load a specific image
|
||||
if(user != null) {
|
||||
@ -138,6 +176,13 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
|
||||
ImageLoadManager.load(getContext(), imageURL, accountImage);
|
||||
}
|
||||
|
||||
//Hide user image if not required
|
||||
if(previousMessage != null){
|
||||
if (message.getUser_id() == previousMessage.getUser_id()){
|
||||
accountImage.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
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"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
@ -10,34 +10,48 @@
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<!-- Messages on the left -->
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:id="@+id/fragment_conversation_message_left"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fragment_conversation_message_item_accountimage"
|
||||
android:layout_width="26dp"
|
||||
android:layout_height="26dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:src="@drawable/default_account_image" />
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_conversation_message_item_content"
|
||||
android:id="@+id/fragment_conversation_message_item_username"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_toEndOf="@id/fragment_conversation_message_item_accountimage"
|
||||
android:background="@color/conversation_otheruser_messages_background"
|
||||
android:padding="5dp"
|
||||
android:paddingEnd="15dp"
|
||||
android:paddingStart="15dp"
|
||||
android:textColor="@color/conversation_otheruser_messages_textColor"
|
||||
tools:text="A message"/>
|
||||
tools:text="User name" />
|
||||
|
||||
</RelativeLayout>
|
||||
<RelativeLayout
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fragment_conversation_message_item_accountimage"
|
||||
android:layout_width="26dp"
|
||||
android:layout_height="26dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:src="@drawable/default_account_image" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_conversation_message_item_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_toEndOf="@id/fragment_conversation_message_item_accountimage"
|
||||
android:background="@color/conversation_otheruser_messages_background"
|
||||
android:padding="5dp"
|
||||
android:paddingEnd="15dp"
|
||||
android:paddingStart="15dp"
|
||||
android:textColor="@color/conversation_otheruser_messages_textColor"
|
||||
tools:text="A message" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Messages on the right -->
|
||||
<RelativeLayout
|
||||
@ -66,8 +80,7 @@
|
||||
android:paddingEnd="15dp"
|
||||
android:paddingStart="15dp"
|
||||
android:textColor="@color/conversation_user_messages_textColor"
|
||||
tools:text="A message"/>
|
||||
|
||||
tools:text="A message" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user