Search in sources :

Example 31 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MessageAdapter method setWriteBoardData.

private void setWriteBoardData(WriteBoardViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (baseMessage != null) {
        if (!baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
            if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
                viewHolder.tvUser.setVisibility(View.GONE);
                viewHolder.ivUser.setVisibility(View.GONE);
            } else if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
                if (isUserDetailVisible) {
                    viewHolder.tvUser.setVisibility(View.VISIBLE);
                    viewHolder.ivUser.setVisibility(View.VISIBLE);
                } else {
                    viewHolder.tvUser.setVisibility(View.GONE);
                    viewHolder.ivUser.setVisibility(View.INVISIBLE);
                }
                setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
                viewHolder.tvUser.setText(baseMessage.getSender().getName());
            }
            viewHolder.whiteBoardMessage.setText(baseMessage.getSender().getName() + " " + context.getString(R.string.has_shared_document));
        } else {
            viewHolder.whiteBoardMessage.setText(context.getString(R.string.you_created_document));
        }
        viewHolder.joinBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Extensions.openWriteBoard(baseMessage, context);
            }
        });
        if (baseMessage.getReplyCount() != 0) {
            viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE);
            viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount() + " " + context.getResources().getString(R.string.replies));
        } else {
            viewHolder.tvThreadReplyCount.setVisibility(View.GONE);
        }
        viewHolder.tvThreadReplyCount.setOnClickListener(view -> {
            Intent intent = new Intent(context, CometChatThreadMessageListActivity.class);
            intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
            intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount());
            intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
            intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
            intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
            intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
            if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
                intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid());
            } else {
                if (baseMessage.getReceiverUid().equals(loggedInUser.getUid()))
                    intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
                else
                    intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid());
            }
            context.startActivity(intent);
        });
        showMessageTime(viewHolder, baseMessage);
        viewHolder.txtTime.setVisibility(View.VISIBLE);
        setColorFilter(baseMessage, viewHolder.messageContainer);
        viewHolder.rlMessageBubble.setOnClickListener(view -> {
            if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                if (isLongClickEnabled && !isImageMessageClick) {
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                } else {
                    setSelectedMessage(baseMessage.getId());
                }
                notifyItemChanged(i);
            }
        });
        viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                if (!isImageMessageClick && !isTextMessageClick) {
                    isLongClickEnabled = true;
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                    notifyItemChanged(i);
                }
                return true;
            }
        });
        setReactionSupport(baseMessage, viewHolder.reactionLayout);
    }
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView)

Example 32 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MessageAdapter method setActionData.

/**
 * This method is called whenever viewType of item is Action. It is used to bind
 * ActionMessageViewHolder contents with Action at a given position. It shows action message
 * or call status based on message category
 *
 * @param viewHolder is a object of ActionMessageViewHolder.
 * @param i is a position of item in recyclerView.
 * @see Action
 * @see Call
 * @see BaseMessage
 */
private void setActionData(ActionMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (Utils.isDarkMode(context))
        viewHolder.textView.setTextColor(context.getResources().getColor(R.color.textColorWhite));
    else
        viewHolder.textView.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
    viewHolder.textView.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
    if (baseMessage instanceof Action) {
        String actionMessage = "";
        if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_JOINED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.joined);
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_MEMBER_ADDED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.added) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_KICKED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.kicked_by) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_BANNED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.ban) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_UNBANNED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.unban) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_LEFT))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.left);
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_SCOPE_CHANGED))
            if (((Action) baseMessage).getNewScope().equals(CometChatConstants.SCOPE_MODERATOR)) {
                actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.made) + " " + ((User) ((Action) baseMessage).getActionOn()).getName() + " " + context.getString(R.string.moderator);
            } else if (((Action) baseMessage).getNewScope().equals(CometChatConstants.SCOPE_ADMIN)) {
                actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.made) + " " + ((User) ((Action) baseMessage).getActionOn()).getName() + " " + context.getString(R.string.admin);
            } else if (((Action) baseMessage).getNewScope().equals(CometChatConstants.SCOPE_PARTICIPANT)) {
                actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.made) + " " + ((User) ((Action) baseMessage).getActionOn()).getName() + " " + context.getString(R.string.participant);
            } else
                actionMessage = ((Action) baseMessage).getMessage();
        viewHolder.textView.setText(actionMessage);
    } else if (baseMessage instanceof Call) {
        Call call = ((Call) baseMessage);
        String callMessageText = "";
        boolean isMissed = false, isIncoming = false, isVideo = false;
        if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_INITIATED)) {
            callMessageText = call.getSender().getName() + " " + context.getString(R.string.initiated);
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED) || call.getCallStatus().equals(CometChatConstants.CALL_STATUS_CANCELLED)) {
            callMessageText = context.getResources().getString(R.string.missed_call);
            isMissed = true;
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
            callMessageText = context.getResources().getString(R.string.rejected_call);
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_ONGOING)) {
            callMessageText = context.getString(R.string.ongoing);
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_ENDED)) {
            callMessageText = context.getString(R.string.ended);
        } else {
            callMessageText = call.getCallStatus();
        }
        if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
            isIncoming = false;
        } else {
            isIncoming = true;
        }
        if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
            callMessageText = callMessageText + " " + context.getResources().getString(R.string.video_call);
            isVideo = true;
        } else {
            callMessageText = callMessageText + " " + context.getResources().getString(R.string.audio_call);
            isVideo = false;
        }
        viewHolder.textView.setText(callMessageText);
    }
}
Also used : Call(com.cometchat.pro.core.Call) Action(com.cometchat.pro.models.Action) User(com.cometchat.pro.models.User) BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 33 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MessageAdapter method getItemViewTypes.

/**
 * This method is used to maintain different viewType based on message category and type and
 * returns the different view types to adapter based on it.
 *
 * Ex :- For message with category <b>CometChatConstants.CATEGORY_MESSAGE</b> and type
 * <b>CometChatConstants.MESSAGE_TYPE_TEXT</b> and message is sent by a <b>Logged-in user</b>,
 * It will return <b>RIGHT_TEXT_MESSAGE</b>
 *
 * @param position is a position of item in recyclerView.
 * @return It returns int which is value of view type of item.
 *
 * @see MessageAdapter#onCreateViewHolder(ViewGroup, int)
 * @see BaseMessage
 */
private int getItemViewTypes(int position) {
    BaseMessage baseMessage = messageList.get(position);
    HashMap<String, JSONObject> extensionList = Extensions.extensionCheck(baseMessage);
    if (baseMessage.getDeletedAt() == 0) {
        if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_MESSAGE)) {
            switch(baseMessage.getType()) {
                case CometChatConstants.MESSAGE_TYPE_TEXT:
                    if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                        if (extensionList != null && extensionList.containsKey("linkPreview") && extensionList.get("linkPreview") != null)
                            return RIGHT_LINK_MESSAGE;
                        else if (baseMessage.getMetadata() != null && baseMessage.getMetadata().has("reply"))
                            return RIGHT_REPLY_TEXT_MESSAGE;
                        else
                            return RIGHT_TEXT_MESSAGE;
                    } else {
                        if (extensionList != null && extensionList.containsKey("linkPreview") && extensionList.get("linkPreview") != null)
                            return LEFT_LINK_MESSAGE;
                        else if (baseMessage.getMetadata() != null && baseMessage.getMetadata().has("reply"))
                            return LEFT_REPLY_TEXT_MESSAGE;
                        else
                            return LEFT_TEXT_MESSAGE;
                    }
                case CometChatConstants.MESSAGE_TYPE_AUDIO:
                    if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                        return RIGHT_AUDIO_MESSAGE;
                    } else {
                        return LEFT_AUDIO_MESSAGE;
                    }
                case CometChatConstants.MESSAGE_TYPE_IMAGE:
                    if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                        return RIGHT_IMAGE_MESSAGE;
                    } else {
                        return LEFT_IMAGE_MESSAGE;
                    }
                case CometChatConstants.MESSAGE_TYPE_VIDEO:
                    if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                        return RIGHT_VIDEO_MESSAGE;
                    } else {
                        return LEFT_VIDEO_MESSAGE;
                    }
                case CometChatConstants.MESSAGE_TYPE_FILE:
                    if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                        return RIGHT_FILE_MESSAGE;
                    } else {
                        return LEFT_FILE_MESSAGE;
                    }
                default:
                    return -1;
            }
        } else {
            if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION)) {
                return ACTION_MESSAGE;
            } else if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_CALL)) {
                return CALL_MESSAGE;
            } else if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_CUSTOM)) {
                if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                    if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.LOCATION))
                        return RIGHT_LOCATION_CUSTOM_MESSAGE;
                    else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.POLLS))
                        return RIGHT_POLLS_CUSTOM_MESSAGE;
                    else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.STICKERS))
                        return RIGHT_STICKER_MESSAGE;
                    else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.WHITEBOARD))
                        return RIGHT_WHITEBOARD_MESSAGE;
                    else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.WRITEBOARD))
                        return RIGHT_WRITEBOARD_MESSAGE;
                    else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.GROUP_CALL))
                        return RIGHT_GROUP_CALL_MESSAGE;
                    else
                        return RIGHT_CUSTOM_MESSAGE;
                } else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.LOCATION))
                    return LEFT_LOCATION_CUSTOM_MESSAGE;
                else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.POLLS))
                    return LEFT_POLLS_CUSTOM_MESSAGE;
                else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.STICKERS))
                    return LEFT_STICKER_MESSAGE;
                else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.WHITEBOARD))
                    return LEFT_WHITEBOARD_MESSAGE;
                else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.WRITEBOARD))
                    return LEFT_WRITEBOARD_MESSAGE;
                else if (baseMessage.getType().equalsIgnoreCase(UIKitConstants.IntentStrings.GROUP_CALL))
                    return LEFT_GROUP_CALL_MESSAGE;
                else
                    return LEFT_CUSTOM_MESSAGE;
            }
        }
    } else {
        if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
            return RIGHT_DELETE_MESSAGE;
        } else {
            return LEFT_DELETE_MESSAGE;
        }
    }
    return -1;
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) JSONObject(org.json.JSONObject)

Example 34 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MessageAdapter method updateReplyCount.

public void updateReplyCount(int parentMessageId) {
    for (BaseMessage baseMessage : messageList) {
        if (baseMessage.getId() == parentMessageId) {
            int replyCount = baseMessage.getReplyCount();
            baseMessage.setReplyCount(++replyCount);
            notifyItemChanged(messageList.indexOf(baseMessage));
        }
    }
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 35 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MessageAdapter method setTextData.

/**
 * This method is called whenever viewType of item is TextMessage. It is used to bind
 * TextMessageViewHolder content with TextMessage at given position.
 * It shows text of a message if deletedAt = 0 else it shows "message deleted"
 *
 * @param viewHolder is a object of TextMessageViewHolder.
 * @param i is postion of item in recyclerView.
 * @see TextMessage
 * @see BaseMessage
 */
private void setTextData(TextMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (baseMessage != null) {
        if (!baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
            if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
                viewHolder.tvUser.setVisibility(View.GONE);
                viewHolder.ivUser.setVisibility(View.GONE);
            } else if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
                if (isUserDetailVisible) {
                    viewHolder.tvUser.setVisibility(View.VISIBLE);
                    viewHolder.ivUser.setVisibility(View.VISIBLE);
                } else {
                    viewHolder.tvUser.setVisibility(View.GONE);
                    viewHolder.ivUser.setVisibility(View.INVISIBLE);
                }
                setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
                viewHolder.tvUser.setText(baseMessage.getSender().getName());
            }
            boolean isSentimentNegative = Extensions.checkSentiment(baseMessage);
            if (isSentimentNegative) {
                viewHolder.txtMessage.setVisibility(View.GONE);
                viewHolder.sentimentVw.setVisibility(View.VISIBLE);
            } else {
                viewHolder.txtMessage.setVisibility(View.VISIBLE);
                viewHolder.sentimentVw.setVisibility(View.GONE);
            }
            viewHolder.viewSentimentMessage.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    AlertDialog.Builder sentimentAlert = new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.sentiment_alert)).setMessage(context.getResources().getString(R.string.sentiment_alert_message)).setPositiveButton(context.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            viewHolder.txtMessage.setVisibility(View.VISIBLE);
                            viewHolder.sentimentVw.setVisibility(View.GONE);
                        }
                    }).setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
                    sentimentAlert.create().show();
                }
            });
        }
        if (baseMessage.getMetadata() != null) {
            try {
                JSONObject metaData = baseMessage.getMetadata();
                if (metaData.has("reply-message")) {
                    JSONObject replyMessageJSON = metaData.getJSONObject("reply-message");
                    BaseMessage replyMessage = CometChatHelper.processMessage(replyMessageJSON);
                    String messageType = replyMessage.getType();
                    viewHolder.replyLayout.setVisibility(View.VISIBLE);
                    viewHolder.replyUser.setVisibility(View.VISIBLE);
                    if (replyMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER))
                        viewHolder.replyUser.setText(replyMessage.getSender().getName());
                    else
                        viewHolder.replyUser.setText(replyMessage.getSender().getName() + " ~ " + ((Group) replyMessage.getReceiver()).getName());
                    if (messageType.equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                        String message = ((TextMessage) replyMessage).getText();
                        if (CometChat.isExtensionEnabled("profanity-filter")) {
                            message = Extensions.checkProfanityMessage(context, replyMessage);
                        }
                        if (CometChat.isExtensionEnabled("data-masking")) {
                            message = Extensions.checkDataMasking(context, replyMessage);
                        }
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(message);
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_image));
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_audio));
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_VIDEO)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_video));
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_FILE)) {
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_file));
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                    } else if (messageType.equals(UIKitConstants.IntentStrings.LOCATION)) {
                        viewHolder.replyMessage.setText(R.string.custom_message_location);
                        viewHolder.replyMessageImage.setImageResource(R.drawable.default_map);
                    } else if (messageType.equals(UIKitConstants.IntentStrings.POLLS)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_poll));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.STICKERS)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(String.format(context.getString(R.string.custom_message_sticker)));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_whiteboard));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_document));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_meeting));
                    }
                    viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

                        @Override
                        public boolean onLongClick(View view) {
                            if (!isImageMessageClick) {
                                isLongClickEnabled = true;
                                isTextMessageClick = true;
                                setLongClickSelectedItem(baseMessage);
                                messageLongClick.setLongMessageClick(longselectedItemList);
                                notifyItemChanged(i);
                            }
                            return true;
                        }
                    });
                } else {
                    viewHolder.replyLayout.setVisibility(View.GONE);
                }
            } catch (Exception e) {
                Log.e(TAG, "setTextData: " + e.getMessage());
            }
        }
        FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

            @Override
            public void onSuccess(Boolean booleanVal) {
                if (baseMessage.getReplyCount() != 0 && booleanVal) {
                    viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE);
                    viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount() + " " + context.getResources().getString(R.string.replies));
                } else {
                    viewHolder.tvThreadReplyCount.setVisibility(View.GONE);
                }
            }
        });
        viewHolder.tvThreadReplyCount.setOnClickListener(view -> {
            Intent intent = new Intent(context, CometChatThreadMessageListActivity.class);
            // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString());
            intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
            intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount());
            intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
            intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
            intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, ((TextMessage) baseMessage).getText());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
            intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
            if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
                intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid());
            } else {
                if (baseMessage.getReceiverUid().equals(loggedInUser.getUid()))
                    intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
                else
                    intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid());
            }
            context.startActivity(intent);
        });
        String txtMessage = ((TextMessage) baseMessage).getText().trim();
        viewHolder.txtMessage.setTextSize(16f);
        int count = 0;
        CharSequence processed = EmojiCompat.get().process(txtMessage, 0, txtMessage.length() - 1, Integer.MAX_VALUE, EmojiCompat.REPLACE_STRATEGY_ALL);
        if (processed instanceof Spannable) {
            Spannable spannable = (Spannable) processed;
            count = spannable.getSpans(0, spannable.length() - 1, EmojiSpan.class).length;
            if (PatternUtils.removeEmojiAndSymbol(txtMessage).trim().length() == 0) {
                int tempcount = count;
                FeatureRestriction.isLargeSizeEmojisEnabled(new FeatureRestriction.OnSuccessListener() {

                    @Override
                    public void onSuccess(Boolean booleanVal) {
                        if (booleanVal) {
                            if (tempcount == 1) {
                                viewHolder.txtMessage.setTextSize((int) Utils.dpToPx(context, 32));
                            } else if (tempcount == 2) {
                                viewHolder.txtMessage.setTextSize((int) Utils.dpToPx(context, 24));
                            }
                        }
                    }
                });
            }
        }
        String message = txtMessage;
        if (CometChat.isExtensionEnabled("profanity-filter")) {
            message = Extensions.checkProfanityMessage(context, baseMessage);
        }
        if (CometChat.isExtensionEnabled("data-masking")) {
            message = Extensions.checkDataMasking(context, baseMessage);
        }
        if (baseMessage.getMetadata() != null && baseMessage.getMetadata().has("values")) {
            try {
                if (Extensions.isMessageTranslated(baseMessage.getMetadata().getJSONObject("values"), ((TextMessage) baseMessage).getText())) {
                    String translatedMessage = Extensions.getTranslatedMessage(baseMessage);
                    message = message + "\n(" + translatedMessage + ")";
                }
            } catch (JSONException e) {
                Toast.makeText(context, context.getString(R.string.no_translation_available), Toast.LENGTH_SHORT).show();
            }
        }
        viewHolder.txtMessage.setText(message);
        viewHolder.txtMessage.setTypeface(fontUtils.getTypeFace(FontUtils.robotoRegular));
        PatternUtils.setHyperLinkSupport(context, viewHolder.txtMessage);
        viewHolder.txtMessage.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                if (!isImageMessageClick) {
                    isLongClickEnabled = true;
                    isTextMessageClick = true;
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                    notifyItemChanged(i);
                }
                return true;
            }
        });
        if (baseMessage.getSender().getUid().equals(loggedInUser.getUid()))
            viewHolder.txtMessage.setTextColor(context.getResources().getColor(R.color.textColorWhite));
        else
            viewHolder.txtMessage.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
        showMessageTime(viewHolder, baseMessage);
        // if (messageList.get(messageList.size()-1).equals(baseMessage))
        // {
        // selectedItemList.add(baseMessage.getId());
        // }
        // if (selectedItemList.contains(baseMessage.getId()))
        viewHolder.txtTime.setVisibility(View.VISIBLE);
        // else
        // viewHolder.txtTime.setVisibility(View.GONE);
        setColorFilter(baseMessage, viewHolder.cvMessageView);
        // viewHolder.rlMessageBubble.setOnClickListener(view -> {
        // if (isLongClickEnabled && !isImageMessageClick) {
        // setLongClickSelectedItem(baseMessage);
        // messageLongClick.setLongMessageClick(longselectedItemList);
        // }
        // else {
        // setSelectedMessage(baseMessage.getId());
        // }
        // notifyDataSetChanged();
        // 
        // });
        // viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {
        // @Override
        // public boolean onLongClick(View view) {
        // if (!isImageMessageClick) {
        // isLongClickEnabled = true;
        // isTextMessageClick = true;
        // setLongClickSelectedItem(baseMessage);
        // messageLongClick.setLongMessageClick(longselectedItemList);
        // notifyDataSetChanged();
        // }
        // return true;
        // }
        // });
        viewHolder.reactionLayout.setVisibility(View.GONE);
        setReactionSupport(baseMessage, viewHolder.reactionLayout);
        viewHolder.itemView.setTag(R.string.message, baseMessage);
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) JSONException(org.json.JSONException) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) BaseMessage(com.cometchat.pro.models.BaseMessage) JSONObject(org.json.JSONObject) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) TextMessage(com.cometchat.pro.models.TextMessage) Spannable(android.text.Spannable)

Aggregations

BaseMessage (com.cometchat.pro.models.BaseMessage)53 View (android.view.View)19 ImageView (android.widget.ImageView)19 TextView (android.widget.TextView)19 CardView (androidx.cardview.widget.CardView)19 RecyclerView (androidx.recyclerview.widget.RecyclerView)19 MaterialCardView (com.google.android.material.card.MaterialCardView)19 Intent (android.content.Intent)18 MediaMessage (com.cometchat.pro.models.MediaMessage)14 JSONException (org.json.JSONException)14 CometChatException (com.cometchat.pro.exceptions.CometChatException)11 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)11 JSONObject (org.json.JSONObject)10 TextMessage (com.cometchat.pro.models.TextMessage)8 User (com.cometchat.pro.models.User)7 AlertDialog (android.app.AlertDialog)6 DialogInterface (android.content.DialogInterface)6 CustomMessage (com.cometchat.pro.models.CustomMessage)5 Call (com.cometchat.pro.core.Call)4 Attachment (com.cometchat.pro.models.Attachment)4