use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class ThreadAdapter 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())) {
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();
}
});
} else {
viewHolder.txtMessage.setVisibility(View.VISIBLE);
viewHolder.sentimentVw.setVisibility(View.GONE);
}
setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
viewHolder.tvUser.setText(baseMessage.getSender().getName());
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) {
if (count == 1) {
viewHolder.txtMessage.setTextSize((int) Utils.dpToPx(context, 32));
} else if (count == 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));
viewHolder.txtMessage.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
PatternUtils.setHyperLinkSupport(context, viewHolder.txtMessage);
showMessageTime(viewHolder, baseMessage);
if (messageList.get(messageList.size() - 1).equals(baseMessage)) {
selectedItemList.add(baseMessage.getId());
}
setColorFilter(baseMessage, viewHolder.cardView);
viewHolder.rlMessageBubble.setOnClickListener(view -> {
if (isLongClickEnabled && !isImageMessageClick) {
setLongClickSelectedItem(baseMessage);
messageLongClick.setLongMessageClick(longselectedItemList);
} else {
setSelectedMessage(baseMessage.getId());
}
notifyDataSetChanged();
});
viewHolder.txtMessage.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);
}
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageList method setLongMessageClick.
@Override
public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
Log.e(TAG, "setLongMessageClick: " + baseMessagesList);
isReply = false;
isEdit = false;
messageActionFragment = new CometChatMessageActions();
replyMessageLayout.setVisibility(GONE);
editMessageLayout.setVisibility(GONE);
fetchSettings();
List<BaseMessage> textMessageList = new ArrayList<>();
List<BaseMessage> mediaMessageList = new ArrayList<>();
List<BaseMessage> locationMessageList = new ArrayList<>();
List<BaseMessage> pollsMessageList = new ArrayList<>();
List<BaseMessage> stickerMessageList = new ArrayList<>();
List<BaseMessage> whiteBoardMessageList = new ArrayList<>();
List<BaseMessage> writeBoardMessageList = new ArrayList<>();
List<BaseMessage> meetingMessageList = new ArrayList<>();
for (BaseMessage baseMessage : baseMessagesList) {
if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
textMessageList.add(baseMessage);
} else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_VIDEO) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_FILE) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
mediaMessageList.add(baseMessage);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
locationMessageList.add(baseMessage);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.STICKERS)) {
stickerMessageList.add(baseMessage);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.POLLS)) {
pollsMessageList.add(baseMessage);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
whiteBoardMessageList.add(baseMessage);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
writeBoardMessageList.add(baseMessage);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
meetingMessageList.add(baseMessage);
}
}
if (textMessageList.size() == 1) {
BaseMessage basemessage = textMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getReplyCount() > 0)
threadVisible = false;
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
editVisible = false;
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
}
if (basemessage.getSentAt() == -1) {
translateVisible = false;
threadVisible = false;
deleteVisible = false;
editVisible = false;
copyVisible = false;
forwardVisible = false;
reactionVisible = false;
replyVisible = false;
shareVisible = false;
retryVisible = true;
}
}
}
}
if (mediaMessageList.size() == 1) {
translateVisible = false;
BaseMessage basemessage = mediaMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getReplyCount() > 0)
threadVisible = false;
copyVisible = false;
// }
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
editVisible = false;
} else {
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
editVisible = false;
}
}
if (basemessage.getSentAt() == -1) {
translateVisible = false;
threadVisible = false;
deleteVisible = false;
editVisible = false;
copyVisible = false;
forwardVisible = false;
reactionVisible = false;
replyVisible = false;
shareVisible = false;
retryVisible = true;
}
}
}
if (locationMessageList.size() == 1) {
translateVisible = false;
BaseMessage basemessage = locationMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getReplyCount() > 0)
threadVisible = false;
else {
FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
threadVisible = booleanVal;
}
});
}
copyVisible = false;
FeatureRestriction.isMessageRepliesEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
replyVisible = booleanVal;
}
});
shareVisible = false;
FeatureRestriction.isShareCopyForwardMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
forwardVisible = booleanVal;
}
});
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
editVisible = false;
} else {
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
editVisible = false;
}
}
if (basemessage.getSentAt() == -1) {
translateVisible = false;
threadVisible = false;
deleteVisible = false;
editVisible = false;
copyVisible = false;
forwardVisible = false;
reactionVisible = false;
replyVisible = false;
shareVisible = false;
retryVisible = true;
}
}
}
if (pollsMessageList.size() == 1) {
forwardVisible = false;
translateVisible = false;
copyVisible = false;
editVisible = false;
shareVisible = false;
BaseMessage basemessage = pollsMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getReplyCount() > 0)
threadVisible = false;
else {
FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
threadVisible = booleanVal;
}
});
}
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
}
}
}
}
if (stickerMessageList.size() == 1) {
forwardVisible = false;
copyVisible = false;
editVisible = false;
translateVisible = false;
shareVisible = false;
BaseMessage basemessage = stickerMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getReplyCount() > 0)
threadVisible = false;
else {
FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
threadVisible = booleanVal;
}
});
}
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
}
}
}
}
if (whiteBoardMessageList.size() == 1) {
forwardVisible = false;
copyVisible = false;
translateVisible = false;
editVisible = false;
shareVisible = false;
BaseMessage basemessage = whiteBoardMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getReplyCount() > 0)
threadVisible = false;
else {
FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
threadVisible = booleanVal;
}
});
}
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
}
}
}
}
if (writeBoardMessageList.size() == 1) {
forwardVisible = false;
copyVisible = false;
editVisible = false;
translateVisible = false;
shareVisible = false;
BaseMessage basemessage = writeBoardMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getReplyCount() > 0)
threadVisible = false;
else {
FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
threadVisible = booleanVal;
}
});
}
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
}
}
}
}
if (meetingMessageList.size() == 1) {
forwardVisible = false;
copyVisible = false;
editVisible = false;
shareVisible = false;
replyVisible = true;
translateVisible = false;
threadVisible = false;
BaseMessage basemessage = meetingMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (basemessage.getDeletedAt() == 0) {
baseMessage = basemessage;
if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
deleteVisible = booleanVal;
}
});
} else {
deleteVisible = false;
}
}
}
}
}
baseMessages = baseMessagesList;
Bundle bundle = new Bundle();
bundle.putBoolean("copyVisible", copyVisible);
bundle.putBoolean("threadVisible", threadVisible);
bundle.putBoolean("shareVisible", shareVisible);
bundle.putBoolean("editVisible", editVisible);
bundle.putBoolean("deleteVisible", deleteVisible);
bundle.putBoolean("replyVisible", replyVisible);
bundle.putBoolean("forwardVisible", forwardVisible);
bundle.putBoolean("translateVisible", translateVisible);
bundle.putBoolean("retryVisible", retryVisible);
bundle.putBoolean("isReactionVisible", reactionVisible);
if (baseMessage.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP) && !baseMessage.getSender().getUid().equalsIgnoreCase(loggedInUser.getUid())) {
bundle.putBoolean("privateReplyVisible", replyPrivately);
bundle.putBoolean("replyPrivatelyVisible", replyVisible);
}
if (CometChat.isExtensionEnabled("reactions")) {
bundle.putBoolean("isReactionVisible", true);
} else {
bundle.putBoolean("isReactionVisible", false);
}
if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP) && baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
FeatureRestriction.isDeliveryReceiptsEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal)
bundle.putBoolean("messageInfoVisible", true);
}
});
}
bundle.putString("type", CometChatMessageListActivity.class.getName());
messageActionFragment.setArguments(bundle);
if (baseMessage.getSentAt() != 0) {
if (retryVisible || editVisible || copyVisible || threadVisible || shareVisible || deleteVisible || replyVisible || forwardVisible || reactionVisible) {
messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
}
}
messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {
@Override
public void onReplyMessagePrivately() {
if (baseMessage != null) {
User user = baseMessage.getSender();
Intent intent = new Intent(context, CometChatMessageListActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE, baseMessage.getRawMessage().toString());
startActivity(intent);
if (getActivity() != null)
getActivity().finish();
}
}
@Override
public void onPrivateReplyToUser() {
if (baseMessage != null) {
User user = baseMessage.getSender();
Intent intent = new Intent(context, CometChatMessageListActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
startActivity(intent);
if (getActivity() != null)
getActivity().finish();
}
}
@Override
public void onThreadMessageClick() {
startThreadActivity();
}
@Override
public void onEditMessageClick() {
if (baseMessage != null && baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
isEdit = true;
isReply = false;
tvMessageTitle.setText(getResources().getString(R.string.edit_message));
tvMessageSubTitle.setText(((TextMessage) baseMessage).getText());
composeBox.ivMic.setVisibility(GONE);
composeBox.ivSend.setVisibility(View.VISIBLE);
editMessageLayout.setVisibility(View.VISIBLE);
composeBox.etComposeBox.setText(((TextMessage) baseMessage).getText());
if (messageAdapter != null) {
messageAdapter.setSelectedMessage(baseMessage.getId());
messageAdapter.notifyDataSetChanged();
}
}
}
@Override
public void onReplyMessageClick() {
replyMessage();
}
@Override
public void onForwardMessageClick() {
startForwardMessageActivity();
}
@Override
public void onDeleteMessageClick() {
deleteMessage(baseMessage);
if (messageAdapter != null) {
messageAdapter.clearLongClickSelectedItem();
messageAdapter.notifyDataSetChanged();
}
}
@Override
public void onCopyMessageClick() {
String message = "";
for (BaseMessage bMessage : baseMessages) {
if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
message = message + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
}
}
Log.e(TAG, "onCopy: " + message);
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("MessageAdapter", message);
clipboardManager.setPrimaryClip(clipData);
Toast.makeText(context, getResources().getString(R.string.text_copied), Toast.LENGTH_LONG).show();
if (messageAdapter != null) {
messageAdapter.clearLongClickSelectedItem();
messageAdapter.notifyDataSetChanged();
}
}
@Override
public void onShareMessageClick() {
shareMessage();
}
@Override
public void onMessageInfoClick() {
Intent intent = new Intent(context, CometChatMessageInfoScreenActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.ID, baseMessage.getId());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.checkProfanityMessage(context, baseMessage));
} else if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_CUSTOM)) {
if (((CustomMessage) baseMessage).getCustomData() != null)
intent.putExtra(UIKitConstants.IntentStrings.CUSTOM_MESSAGE, ((CustomMessage) baseMessage).getCustomData().toString());
if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.STICKERS)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS);
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WHITEBOARD);
intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage));
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WRITEBOARD);
intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage));
} else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.GROUP_CALL);
} else {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS);
}
} else {
boolean isImageNotSafe = Extensions.getImageModeration(context, baseMessage);
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
intent.putExtra(UIKitConstants.IntentStrings.IMAGE_MODERATION, isImageNotSafe);
}
context.startActivity(intent);
}
@Override
public void onReactionClick(Reaction reaction) {
if (reaction.getName().equals("add_emoji")) {
CometChatReactionDialog reactionDialog = new CometChatReactionDialog();
reactionDialog.setOnEmojiClick(new OnReactionClickListener() {
@Override
public void onEmojiClicked(Reaction emojicon) {
sendReaction(emojicon);
reactionDialog.dismiss();
}
});
reactionDialog.show(getFragmentManager(), "ReactionDialog");
} else {
sendReaction(reaction);
}
}
@Override
public void onTranslateMessageClick() {
try {
String localeLanguage = Locale.getDefault().getLanguage();
JSONObject body = new JSONObject();
JSONArray languages = new JSONArray();
languages.put(localeLanguage);
body.put("msgId", baseMessage.getId());
body.put("languages", languages);
body.put("text", ((TextMessage) baseMessage).getText());
CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject jsonObject) {
if (Extensions.isMessageTranslated(jsonObject, ((TextMessage) baseMessage).getText())) {
if (baseMessage.getMetadata() != null) {
JSONObject meta = baseMessage.getMetadata();
try {
meta.accumulate("values", jsonObject);
baseMessage.setMetadata(meta);
updateMessage(baseMessage);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
baseMessage.setMetadata(jsonObject);
updateMessage(baseMessage);
}
} else {
CometChatSnackBar.show(context, rvChatListView, context.getString(R.string.no_translation_available), CometChatSnackBar.WARNING);
}
}
@Override
public void onError(CometChatException e) {
Toast.makeText(context, e.getCode(), Toast.LENGTH_LONG).show();
}
});
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onRetryClick() {
if (baseMessage != null) {
messageAdapter.remove(baseMessage);
if (baseMessage.getType().equalsIgnoreCase(CometChatConstants.MESSAGE_TYPE_TEXT))
sendMessage(((TextMessage) baseMessage).getText());
}
}
});
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatCallsAdapter method onBindViewHolder.
/**
* This method is used to bind the ConversationViewHolder contents with conversation at given
* position. It set avatar, name, lastMessage, unreadMessageCount and messageTime of conversation
* in a respective ConversationViewHolder content. It checks whether conversation type is user
* or group and set name and avatar as accordingly. It also checks whether last message is text, media
* or file and modify txtUserMessage view accordingly.
*
* @param callViewHolder is a object of ConversationViewHolder.
* @param position is a position of item in recyclerView.
*
* @see Conversation
*/
@Override
public void onBindViewHolder(@NonNull CallViewHolder callViewHolder, int position) {
BaseMessage baseMessage = callList.get(position);
Call call = (Call) baseMessage;
String avatar;
String uid;
String type;
boolean isIncoming, isVideo, isMissed = false;
String name;
String callMessageText;
String callType;
String callCategory;
if (call.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
String callName = ((User) call.getCallReceiver()).getName();
callViewHolder.callListRowBinding.callSenderName.setText(callName);
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar(((User) call.getCallReceiver()).getAvatar());
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
callMessageText = context.getResources().getString(R.string.outgoing);
uid = ((User) call.getCallReceiver()).getUid();
isIncoming = false;
} else {
String callName = ((User) call.getCallInitiator()).getName();
callViewHolder.callListRowBinding.callSenderName.setText(callName);
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar((User) call.getCallInitiator());
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
callMessageText = context.getResources().getString(R.string.incoming);
uid = call.getSender().getUid();
isIncoming = true;
}
type = CometChatConstants.RECEIVER_TYPE_USER;
} else {
callViewHolder.callListRowBinding.callSenderName.setText(((Group) call.getCallReceiver()).getName());
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar(((Group) call.getCallReceiver()));
if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
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
callMessageText = context.getResources().getString(R.string.incoming);
isIncoming = false;
} else {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
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
callMessageText = context.getResources().getString(R.string.incoming);
isIncoming = true;
}
uid = ((Group) call.getCallReceiver()).getGuid();
type = CometChatConstants.RECEIVER_TYPE_GROUP;
}
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;
}
if (isVideo) {
if (isIncoming) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_video_call, 0, 0, 0);
} else {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_video_call, 0, 0, 0);
}
} else {
if (isIncoming && isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_incoming_24dp, 0, 0, 0);
} else if (isIncoming && !isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_call, 0, 0, 0);
} else if (!isIncoming && isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_outgoing_24dp, 0, 0, 0);
} else {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_call, 0, 0, 0);
}
}
callViewHolder.callListRowBinding.calltimeTv.setText(Utils.getLastMessageDate(context, call.getInitiatedAt()));
callViewHolder.callListRowBinding.callMessage.setText(callMessageText);
callViewHolder.callListRowBinding.getRoot().setTag(R.string.call, call);
if (call.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER)) {
// if(FeatureRestriction.isOneOnOneAudioCallEnabled() ||
// FeatureRestriction.isOneOnOneVideoCallEnabled())
callViewHolder.callListRowBinding.callIv.setVisibility(View.VISIBLE);
// else
// callViewHolder.callListRowBinding.callIv.setVisibility(View.GONE);
}
callViewHolder.callListRowBinding.callIv.setImageTintList(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatConversationsAdapter method setDeliveredReceipts.
public void setDeliveredReceipts(MessageReceipt deliveryReceipts) {
for (int i = 0; i < filterConversationList.size() - 1; i++) {
Conversation conversation = filterConversationList.get(i);
if (conversation.getConversationType().equals(CometChatConstants.RECEIVER_TYPE_USER) && deliveryReceipts.getSender().getUid().equals(((User) conversation.getConversationWith()).getUid())) {
BaseMessage baseMessage = filterConversationList.get(i).getLastMessage();
if (baseMessage != null && baseMessage.getDeliveredAt() == 0) {
baseMessage.setReadAt(deliveryReceipts.getDeliveredAt());
int index = filterConversationList.indexOf(filterConversationList.get(i));
filterConversationList.remove(index);
conversation.setLastMessage(baseMessage);
filterConversationList.add(index, conversation);
}
}
}
notifyDataSetChanged();
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatSharedMediaAdapter method setFileData.
private void setFileData(FileViewHolder viewHolder, int i) {
BaseMessage message = messageArrayList.get(i);
viewHolder.fileName.setText(((MediaMessage) message).getAttachment().getFileName());
viewHolder.fileExtension.setText(((MediaMessage) message).getAttachment().getFileExtension());
viewHolder.itemView.setOnClickListener(view -> {
MediaUtils.openFile(((MediaMessage) message).getAttachment().getFileUrl(), context);
});
viewHolder.itemView.setTag(R.string.baseMessage, message);
}
Aggregations