use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method sendMediaMessage.
/**
* This method is used to send media messages to other users and group.
*
* @param file is an object of File which is been sent within the message.
* @param filetype is a string which indicate a type of file been sent within the message.
* @see CometChat#sendMediaMessage(MediaMessage, CometChat.CallbackListener)
* @see MediaMessage
*/
private void sendMediaMessage(File file, String filetype) {
MediaMessage mediaMessage;
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_USER);
else
mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_GROUP);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("path", file.getAbsolutePath());
} catch (JSONException e) {
e.printStackTrace();
}
mediaMessage.setMetadata(jsonObject);
mediaMessage.setMuid("" + System.currentTimeMillis());
mediaMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
mediaMessage.setSender(loggedInUser);
if (messageAdapter != null) {
messageAdapter.addMessage(mediaMessage);
scrollToBottom();
}
mediaMessage.setParentMessageId(parentId);
CometChat.sendMediaMessage(mediaMessage, new CometChat.CallbackListener<MediaMessage>() {
@Override
public void onSuccess(MediaMessage mediaMessage) {
noReplyMessages.setVisibility(GONE);
Log.d(TAG, "sendMediaMessage onSuccess: " + mediaMessage.toString());
if (messageAdapter != null) {
setReply();
messageAdapter.updateChangedMessage(mediaMessage);
}
}
@Override
public void onError(CometChatException e) {
if (messageAdapter != null) {
mediaMessage.setSentAt(-1);
messageAdapter.updateChangedMessage(mediaMessage);
}
if (getActivity() != null) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
}
});
}
use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class ThreadAdapter method openMediaViewActivity.
private void openMediaViewActivity(BaseMessage baseMessage) {
Intent intent = new Intent(context, CometChatMediaViewActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
intent.putExtra(UIKitConstants.IntentStrings.INTENT_MEDIA_MESSAGE, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
context.startActivity(intent);
}
use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class ThreadAdapter method setFileData.
/**
* This method is called whenever viewType of item is file. It is used to bind FileMessageViewHolder
* contents with MediaMessage at a given position.
* It shows FileName, FileType, FileSize.
*
* @param viewHolder is a object of FileMessageViewHolder.
* @param i is a position of item in recyclerView.
* @see MediaMessage
* @see BaseMessage
*/
private void setFileData(FileMessageViewHolder viewHolder, int i) {
BaseMessage baseMessage = messageList.get(i);
if (baseMessage != null && baseMessage.getDeletedAt() == 0) {
setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
viewHolder.tvUser.setText(baseMessage.getSender().getName());
Attachment attachement = ((MediaMessage) baseMessage).getAttachment();
if (attachement != null) {
viewHolder.fileName.setText(attachement.getFileName());
viewHolder.fileExt.setText(attachement.getFileExtension());
int fileSize = attachement.getFileSize();
viewHolder.fileSize.setText(Utils.getFileSize(fileSize));
}
showMessageTime(viewHolder, baseMessage);
// if (selectedItemList.contains(baseMessage.getId()))
// viewHolder.txtTime.setVisibility(View.VISIBLE);
// else
// viewHolder.txtTime.setVisibility(View.GONE);
viewHolder.rlMessageBubble.setOnClickListener(view -> {
// if (isLongClickEnabled && !isTextMessageClick) {
// setLongClickSelectedItem(baseMessage);
// }
// else {
setSelectedMessage(baseMessage.getId());
// }
notifyDataSetChanged();
});
viewHolder.fileName.setOnClickListener(view -> MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(), context));
viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!isLongClickEnabled && !isTextMessageClick) {
isImageMessageClick = true;
setLongClickSelectedItem(baseMessage);
messageLongClick.setLongMessageClick(longselectedItemList);
notifyDataSetChanged();
}
return true;
}
});
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 ThreadAdapter method setVideoData.
private void setVideoData(VideoMessageViewHolder viewHolder, int i) {
BaseMessage baseMessage = messageList.get(i);
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);
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);
notifyDataSetChanged();
}
return true;
}
});
viewHolder.playBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(), context);
}
});
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 CometChatMessageList method sendMediaMessage.
/**
* This method is used to send media messages to other users and group.
*
* @param file is an object of File which is been sent within the message.
* @param filetype is a string which indicate a type of file been sent within the message.
* @see CometChat#sendMediaMessage(MediaMessage, CometChat.CallbackListener)
* @see MediaMessage
*/
private void sendMediaMessage(File file, String filetype) {
MediaMessage mediaMessage;
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_USER);
else
mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_GROUP);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("path", file.getAbsolutePath());
} catch (JSONException e) {
e.printStackTrace();
}
mediaMessage.setMetadata(jsonObject);
mediaMessage.setMuid("" + System.currentTimeMillis());
mediaMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
mediaMessage.setSender(loggedInUser);
if (messageAdapter != null) {
messageAdapter.addMessage(mediaMessage);
scrollToBottom();
}
CometChat.sendMediaMessage(mediaMessage, new CometChat.CallbackListener<MediaMessage>() {
@Override
public void onSuccess(MediaMessage mediaMessage) {
Log.d(TAG, "sendMediaMessage onSuccess: " + mediaMessage.toString());
if (messageAdapter != null) {
messageAdapter.updateChangedMessage(mediaMessage);
rvSmartReply.setVisibility(GONE);
}
}
@Override
public void onError(CometChatException e) {
e.printStackTrace();
if (messageAdapter != null) {
mediaMessage.setSentAt(-1);
messageAdapter.updateChangedMessage(mediaMessage);
}
if (getActivity() != null) {
CometChatSnackBar.show(context, rvChatListView, e.getMessage(), CometChatSnackBar.ERROR);
}
}
});
}
Aggregations