From 89fd46a69515d639d7b75cdfc804250a5f85b602 Mon Sep 17 00:00:00 2001 From: Adam Johns Date: Mon, 28 Nov 2016 08:35:34 -0600 Subject: [PATCH] Custom click listener --- .../slyce/messaging/message/MediaMessage.java | 3 ++ .../master/media/MessageMediaItem.java | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/slyce-messaging/src/main/java/it/slyce/messaging/message/MediaMessage.java b/slyce-messaging/src/main/java/it/slyce/messaging/message/MediaMessage.java index 8f33996..503f74b 100644 --- a/slyce-messaging/src/main/java/it/slyce/messaging/message/MediaMessage.java +++ b/slyce-messaging/src/main/java/it/slyce/messaging/message/MediaMessage.java @@ -1,6 +1,7 @@ package it.slyce.messaging.message; import android.content.Context; +import android.view.View; import it.slyce.messaging.message.messageItem.MessageItem; import it.slyce.messaging.message.messageItem.externalUser.media.MessageExternalUserMediaItem; @@ -12,6 +13,8 @@ public class MediaMessage extends Message { private String url; + public View.OnClickListener onClickListener; + public String getUrl() { return url; } diff --git a/slyce-messaging/src/main/java/it/slyce/messaging/message/messageItem/master/media/MessageMediaItem.java b/slyce-messaging/src/main/java/it/slyce/messaging/message/messageItem/master/media/MessageMediaItem.java index c21c554..661fcac 100644 --- a/slyce-messaging/src/main/java/it/slyce/messaging/message/messageItem/master/media/MessageMediaItem.java +++ b/slyce-messaging/src/main/java/it/slyce/messaging/message/messageItem/master/media/MessageMediaItem.java @@ -7,14 +7,14 @@ import com.bumptech.glide.Glide; +import it.slyce.messaging.ViewImageActivity; import it.slyce.messaging.message.MediaMessage; import it.slyce.messaging.message.MessageSource; -import it.slyce.messaging.utils.MediaUtils; -import it.slyce.messaging.utils.DateUtils; -import it.slyce.messaging.ViewImageActivity; import it.slyce.messaging.message.messageItem.MessageItem; import it.slyce.messaging.message.messageItem.MessageItemType; import it.slyce.messaging.message.messageItem.MessageViewHolder; +import it.slyce.messaging.utils.DateUtils; +import it.slyce.messaging.utils.MediaUtils; /** * Created by matthewpage on 6/27/16. @@ -60,15 +60,19 @@ public void onClick(View view) { } }); - messageMediaViewHolder.media.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context, ViewImageActivity.class); - intent.putExtra("URL", mediaUrl); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } - }); + if (getMediaMessage().onClickListener != null) { + messageMediaViewHolder.media.setOnClickListener(getMediaMessage().onClickListener); + } else { + messageMediaViewHolder.media.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context, ViewImageActivity.class); + intent.putExtra("URL", mediaUrl); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + }); + } messageMediaViewHolder.avatar.setVisibility(isFirstConsecutiveMessageFromSource && !TextUtils.isEmpty(avatarUrl) ? View.VISIBLE : View.INVISIBLE); messageMediaViewHolder.avatarContainer.setVisibility(isFirstConsecutiveMessageFromSource ? View.VISIBLE : View.INVISIBLE);