use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatSharedMediaAdapter method setVideoData.
private void setVideoData(VideoViewHolder viewHolder, int i) {
BaseMessage message = messageArrayList.get(i);
Glide.with(context).load(((MediaMessage) message).getAttachment().getFileUrl()).into(viewHolder.imageView);
viewHolder.imageView.setOnClickListener(view -> {
Intent intent = new Intent(context, CometChatMediaViewActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.NAME, message.getSender().getName());
intent.putExtra(UIKitConstants.IntentStrings.UID, message.getSender().getUid());
intent.putExtra(UIKitConstants.IntentStrings.SENTAT, message.getSentAt());
intent.putExtra(UIKitConstants.IntentStrings.INTENT_MEDIA_MESSAGE, ((MediaMessage) message).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, message.getType());
context.startActivity(intent);
});
viewHolder.itemView.setTag(R.string.baseMessage, message);
}
use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class MessageAdapter method setVideoData.
private void setVideoData(VideoMessageViewHolder viewHolder, int i) {
BaseMessage baseMessage = messageList.get(i);
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());
}
}
if (((MediaMessage) baseMessage).getAttachment() != null)
Glide.with(context).load(((MediaMessage) baseMessage).getAttachment().getFileUrl()).into(viewHolder.imageView);
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.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
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);
// if (selectedItemList.contains(baseMessage.getId()))
viewHolder.txtTime.setVisibility(View.VISIBLE);
// else
// viewHolder.txtTime.setVisibility(View.GONE);
//
viewHolder.rlMessageBubble.setOnClickListener(view -> {
setSelectedMessage(baseMessage.getId());
notifyDataSetChanged();
});
viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!isLongClickEnabled && !isTextMessageClick) {
isImageMessageClick = true;
setLongClickSelectedItem(baseMessage);
messageLongClick.setLongMessageClick(longselectedItemList);
notifyItemChanged(i);
}
return true;
}
});
viewHolder.playBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openMediaViewActivity(baseMessage);
}
});
viewHolder.reactionLayout.setVisibility(View.GONE);
setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class MessageAdapter method setLinkData.
private void setLinkData(LinkMessageViewHolder viewHolder, int i) {
BaseMessage baseMessage = messageList.get(i);
String url = null;
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());
}
}
if (baseMessage.getDeletedAt() == 0) {
HashMap<String, JSONObject> extensionList = Extensions.extensionCheck(baseMessage);
if (extensionList != null) {
if (extensionList.containsKey("linkPreview")) {
JSONObject linkPreviewJsonObject = extensionList.get("linkPreview");
try {
String description = linkPreviewJsonObject.getString("description");
String image = linkPreviewJsonObject.getString("image");
String title = linkPreviewJsonObject.getString("title");
url = linkPreviewJsonObject.getString("url");
Log.e("setLinkData: ", baseMessage.toString() + "\n\n" + url + "\n" + description + "\n" + image);
viewHolder.linkTitle.setText(title);
viewHolder.linkSubtitle.setText(description);
Glide.with(context).load(Uri.parse(image)).timeout(1000).into(viewHolder.linkImg);
if (url.contains("youtu.be") || url.contains("youtube")) {
viewHolder.videoLink.setVisibility(View.VISIBLE);
viewHolder.linkVisit.setText(context.getResources().getString(R.string.view_on_youtube));
} else {
viewHolder.videoLink.setVisibility(View.GONE);
viewHolder.linkVisit.setText(context.getResources().getString(R.string.visit));
}
String messageStr = ((TextMessage) baseMessage).getText();
if (((TextMessage) baseMessage).getText().equals(url) || ((TextMessage) baseMessage).getText().equals(url + "/")) {
viewHolder.message.setVisibility(View.GONE);
} else {
viewHolder.message.setVisibility(View.VISIBLE);
}
viewHolder.message.setText(messageStr);
} catch (Exception e) {
Log.e("setLinkData: ", 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.MESSAGE_CATEGORY, baseMessage.getCategory());
intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT))
intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, ((TextMessage) baseMessage).getText());
else {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
}
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);
});
PatternUtils.setHyperLinkSupport(context, viewHolder.message);
showMessageTime(viewHolder, baseMessage);
String finalUrl = url;
viewHolder.linkVisit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (finalUrl != null) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(finalUrl));
context.startActivity(intent);
}
}
});
// if (selectedItemList.contains(baseMessage.getId()))
viewHolder.txtTime.setVisibility(View.VISIBLE);
// else
// viewHolder.txtTime.setVisibility(View.GONE);
// if (i < selectedItems.length && selectedItems[i] == 0) {
// viewHolder.txtTime.setVisibility(View.GONE);
// } else
// viewHolder.txtTime.setVisibility(View.VISIBLE);
setColorFilter(baseMessage, viewHolder.cvMessageView);
viewHolder.rlMessageBubble.setOnClickListener(view -> {
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) {
isLongClickEnabled = true;
isTextMessageClick = true;
setLongClickSelectedItem(baseMessage);
messageLongClick.setLongMessageClick(longselectedItemList);
notifyItemChanged(i);
}
return true;
}
});
viewHolder.reactionLayout.setVisibility(View.GONE);
setReactionSupport(baseMessage, viewHolder.reactionLayout);
viewHolder.itemView.setTag(R.string.message, baseMessage);
}
}
use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method showBottomSheet.
private void showBottomSheet(CometChatMessageActions messageActionFragment) {
messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {
@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.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
startActivity(intent);
if (getActivity() != null)
getActivity().finish();
}
}
@Override
public void onThreadMessageClick() {
}
@Override
public void onEditMessageClick() {
if (isParent)
editParentMessage();
else
editThreadMessage();
}
@Override
public void onReplyMessageClick() {
}
@Override
public void onReplyMessagePrivately() {
}
@Override
public void onForwardMessageClick() {
if (isParent)
startForwardThreadActivity();
else
startForwardMessageActivity();
}
@Override
public void onDeleteMessageClick() {
deleteMessage(baseMessage);
if (messageAdapter != null) {
messageAdapter.clearLongClickSelectedItem();
messageAdapter.notifyDataSetChanged();
}
}
@Override
public void onCopyMessageClick() {
String copyMessage = "";
if (isParent) {
copyMessage = message;
isParent = true;
} else {
for (BaseMessage bMessage : baseMessages) {
if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
copyMessage = copyMessage + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
}
}
isParent = false;
}
Log.e(TAG, "onCopy: " + message);
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("ThreadMessageAdapter", copyMessage);
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);
if (isParent) {
} else {
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 {
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);
if (isParent) {
body.put("msgId", parentId);
body.put("text", textMessage.getText().toString());
} else {
body.put("msgId", baseMessage.getId());
body.put("text", ((TextMessage) baseMessage).getText());
}
body.put("languages", languages);
CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject jsonObject) {
if (isParent) {
if (Extensions.isMessageTranslated(jsonObject, textMessage.getText().toString())) {
String translatedMessage = Extensions.getTextFromTranslatedMessage(jsonObject, textMessage.getText().toString());
textMessage.setText(translatedMessage);
} else {
CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
}
} else {
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, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
}
}
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "message-translation"), CometChatSnackBar.ERROR);
}
});
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onRetryClick() {
}
});
}
use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method shareMessage.
private void shareMessage() {
if (baseMessage != null && baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TITLE, getResources().getString(R.string.app_name));
shareIntent.putExtra(Intent.EXTRA_TEXT, ((TextMessage) baseMessage).getText());
shareIntent.setType("text/plain");
Intent intent = Intent.createChooser(shareIntent, getResources().getString(R.string.share_message));
startActivity(intent);
} else if (baseMessage != null && baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
String mediaName = ((MediaMessage) baseMessage).getAttachment().getFileName();
Glide.with(context).asBitmap().load(((MediaMessage) baseMessage).getAttachment().getFileUrl()).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), resource, mediaName, null);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
shareIntent.setType(((MediaMessage) baseMessage).getAttachment().getFileMimeType());
Intent intent = Intent.createChooser(shareIntent, getResources().getString(R.string.share_message));
startActivity(intent);
}
});
}
}
Aggregations