Skip to content

Commit

Permalink
ability to pass custom data in ImageLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
bevzaanton committed Oct 1, 2018
1 parent ca51b2f commit 3561042
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,14 @@ MessageHolders registerContentType(
/**
* Registers custom content type (e.g. multimedia, events etc.)
*
* @param type unique id for content type
* @param incomingHolder holder class for incoming message
* @param outcomingHolder holder class for outcoming message
* @param incomingPayload payload for incoming message
* @param type unique id for content type
* @param incomingHolder holder class for incoming message
* @param outcomingHolder holder class for outcoming message
* @param incomingPayload payload for incoming message
* @param outcomingPayload payload for outcoming message
* @param incomingLayout layout resource for incoming message
* @param outcomingLayout layout resource for outcoming message
* @param contentChecker {@link MessageHolders.ContentChecker} for registered type
* @param incomingLayout layout resource for incoming message
* @param outcomingLayout layout resource for outcoming message
* @param contentChecker {@link MessageHolders.ContentChecker} for registered type
* @return {@link MessageHolders} for subsequent configuration.
*/
public <TYPE extends MessageContentType>
Expand Down Expand Up @@ -881,7 +881,7 @@ public IncomingImageMessageViewHolder(View itemView, Object payload) {
public void onBind(MESSAGE message) {
super.onBind(message);
if (image != null && imageLoader != null) {
loadImage(message);
imageLoader.loadImage(image, message.getImageUrl(), getPayloadForImageLoader(message));
}

if (imageOverlay != null) {
Expand All @@ -903,8 +903,13 @@ public final void applyStyle(MessagesListStyle style) {
}
}

protected void loadImage(MESSAGE message) {
imageLoader.loadImage(image, message.getImageUrl(), null);
/**
* Override this method to have ability to pass custom data in ImageLoader for loading image(not avatar).
*
* @param message Message with image
*/
protected Object getPayloadForImageLoader(MESSAGE message) {
return null;
}

private void init(View itemView) {
Expand Down Expand Up @@ -946,7 +951,7 @@ public OutcomingImageMessageViewHolder(View itemView, Object payload) {
public void onBind(MESSAGE message) {
super.onBind(message);
if (image != null && imageLoader != null) {
loadImage(message);
imageLoader.loadImage(image, message.getImageUrl(), getPayloadForImageLoader(message));
}

if (imageOverlay != null) {
Expand All @@ -969,12 +974,12 @@ public final void applyStyle(MessagesListStyle style) {
}

/**
* Calls Imageloader for loading image.
* Override this method to have ability to pass custom data in ImageLoader.
* Override this method to have ability to pass custom data in ImageLoader for loading image(not avatar).
*
* @param message Message with image
*/
protected void loadImage(MESSAGE message) {
imageLoader.loadImage(image, message.getImageUrl(), null);
protected Object getPayloadForImageLoader(MESSAGE message) {
return null;
}

private void init(View itemView) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stfalcon.chatkit.sample.features.demo.custom.holder.holders.messages;

import android.util.Pair;
import android.view.View;

import com.stfalcon.chatkit.messages.MessageHolders;
Expand All @@ -22,9 +23,10 @@ public void onBind(Message message) {
time.setText(message.getStatus() + " " + time.getText());
}

//Override this method to pass custom data in ImageLoader.
//Override this method to have ability to pass custom data in ImageLoader for loading image(not avatar).
@Override
protected void loadImage(Message message) {
imageLoader.loadImage(image, message.getImageUrl(), null);
protected Object getPayloadForImageLoader(Message message) {
//For example you can pass size of placeholder before loading
return new Pair<>(100, 100);
}
}

0 comments on commit 3561042

Please sign in to comment.