I use FirebaseRecycleAdapter to load chat data from Firebase RealtimeDatabase. I want to show the message on two way, so the left image different the right image.
But the image sometimes misplace like the picture.
Here is my code:
mFirebaseAdapter = new FirebaseRecyclerAdapter<Message, MessageViewHolder>(
Message.class,
R.layout.item_message_onetoone,
MessageViewHolder.class,
databaseReference.child(Constant.CHILD_CHATONETOONE).child(myUid).child(clientUid)) {
@Override
protected void populateViewHolder(MessageViewHolder viewHolder, Message message, int position) {
String senderUid= message.getSenderUid();
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(RecyclerView.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
lp.leftMargin= 10;
lp.rightMargin= 10;
viewHolder.messageTextView.setText(message.getMessage());
if (senderUid.equals(myUid)){
lp.gravity= Gravity.RIGHT;
viewHolder.linearLayout.setLayoutParams(lp);
Glide.with(OneToOneConversationActivity.this).load(myPhotoURL).into(viewHolder.messengerImageView);
viewHolder.messengerTextView.setText(myName);
}
else if(senderUid.equals(clientUid)){
lp.gravity= Gravity.LEFT;
viewHolder.linearLayout.setLayoutParams(lp);
viewHolder.messengerTextView.setText(clientName);
}
}
};
MessageViewHolder class:
public static class MessageViewHolder extends RecyclerView.ViewHolder {
public TextView messageTextView;
public TextView messengerTextView;
public CircleImageView messengerImageView;
public LinearLayout linearLayout;
public MessageViewHolder(View v) {
super(v);
messageTextView = (TextView) itemView.findViewById(R.id.messageTextView);
messengerTextView = (TextView) itemView.findViewById(R.id.messengerTextView);
messengerImageView = (CircleImageView) itemView.findViewById(R.id.messengerImageView);
linearLayout= (LinearLayout) itemView.findViewById(R.id.llOneToOneChat);
}
}
The linearlayout and textViews works fine exept CircleImageView. It seems like context: OneToOneChatActivity.this when i use code : Glide.with(....) is wrong, but I cant figure out solution. How can I make it work property?
I found my problem. There is two way to solve the problem
so in this post, in "else" case, you can set a transparent color to imageView to avoid the problem