1

I want display image file after sent. But result is empty message and is displayed on the left side of screen(received side). This happens with any url set.

image example

My item_list.xml:

<com.stfalcon.chatkit.messages.MessagesList
        android:id="@+id/chat.room.messagesList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/chat.room.input" />

My adapter:

adapter = new MessagesListAdapter<ChatMessage>(getMyChatUser().getId(), null);
        messagesList.setAdapter(adapter);

or

adapter = new MessagesListAdapter<ChatMessage>(getMyChatUser().getId(), imageLoader);
        messagesList.setAdapter(adapter);

with ImageLoader

imageLoader = new ImageLoader() {
            @Override
            public void loadImage(ImageView imageView, @Nullable String url, @Nullable Object payload) {
                Picasso.with(getActivity()).load(url).into(imageView);
            }
        };

My attachments:

messageInput.setAttachmentsListener(new MessageInput.AttachmentsListener() {
   @Override
   public void onAddAttachments() {
      ChatMessage chatMessage = new ChatMessage(String.valueOf(new Random().nextInt()), null, getMyChatUser());
      chatMessage.setImage(urlImage);
      adapter.addToStart(chatMessage, true);
   }
});

ChatMessage implements MessageContentType.Image as the official guide says.

Solution Implementation is right. I passed the wrong URL format

1 Answers1

1

Few notes

This is the constructor when you want your adapter to contain image/s.

MessagesListAdapter<Message> adapter = new MessagesListAdapter<T>(senderId, imageLoader);
messagesList.setAdapter(adapter);

More on MessageListAdapter.java:

/**
 * For default list item layout and view holder.
 *
 * @param senderId    identifier of sender.
 * @param imageLoader image loading method.
 */
public MessagesListAdapter(String senderId, ImageLoader imageLoader) {
   this(senderId, new MessageHolders(), imageLoader);
}

What went wrong

You are passing null on the constructor

adapter = new MessagesListAdapter<ChatMessage>(getMyChatUser().getId(), null);
        messagesList.setAdapter(adapter);

If the method returns null, the adapter recognizes the message as a text message and displays it in the appropriate form. If the url of the image is present, an image will be displayed using ImageLoader, which we passed to the adapter.

What you can do

Create something like this[1] and pass it to the MessageListAdapter

ImageLoader imageLoader = new ImageLoader() {
   @Override
   public void loadImage(ImageView imageView, String url) {
       Picasso.with(MessagesListActivity.this).load(url).into(imageView);
   }
};

Read more on

Joshua de Guzman
  • 2,063
  • 9
  • 24