use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class MessageAdapter method setCustomData.
private void setCustomData(CustomMessageViewHolder 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.txtMessage.setText(context.getResources().getString(R.string.custom_message));
viewHolder.txtMessage.setTypeface(fontUtils.getTypeFace(FontUtils.robotoLight));
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.cardView);
viewHolder.rlMessageBubble.setOnClickListener(view -> {
setSelectedMessage(baseMessage.getId());
notifyDataSetChanged();
});
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 MessageAdapter method setDeliveryReceipts.
/**
* This method is used to set real time delivery receipt of particular message in messageList
* of adapter by updating message.
*
* @param messageReceipt is a object of MessageReceipt.
* @see MessageReceipt
*/
public void setDeliveryReceipts(MessageReceipt messageReceipt) {
for (int i = messageList.size() - 1; i >= 0; i--) {
BaseMessage baseMessage = messageList.get(i);
if (baseMessage.getDeliveredAt() == 0) {
int index = messageList.indexOf(baseMessage);
messageList.get(index).setDeliveredAt(messageReceipt.getDeliveredAt());
}
}
notifyDataSetChanged();
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class MessageAdapter method setAudioData.
/**
* This method is called whenever viewType of item is file. It is used to bind AudioMessageViewHolder
* contents with MediaMessage at a given position.
*
* @param viewHolder is a object of AudioMessageViewHolder.
* @param i is a position of item in recyclerView.
* @see MediaMessage
* @see BaseMessage
*/
private void setAudioData(AudioMessageViewHolder viewHolder, int i) {
BaseMessage baseMessage = messageList.get(i);
if (baseMessage != null && baseMessage.getDeletedAt() == 0) {
if (!baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
viewHolder.playBtn.setImageTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.textColorWhite)));
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());
}
} else {
viewHolder.playBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
}
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);
setColorFilter(baseMessage, viewHolder.rlMessageBubble);
// if (selectedItemList.contains(baseMessage.getId()))
viewHolder.txtTime.setVisibility(View.VISIBLE);
// viewHolder.txtTime.setVisibility(View.GONE);
if (((MediaMessage) baseMessage).getAttachment() != null) {
viewHolder.length.setText(Utils.getFileSize(((MediaMessage) baseMessage).getAttachment().getFileSize()));
viewHolder.playBtn.setVisibility(View.VISIBLE);
} else {
viewHolder.length.setText("-");
viewHolder.playBtn.setVisibility(View.GONE);
}
viewHolder.playBtn.setImageResource(R.drawable.ic_play_arrow_black_24dp);
viewHolder.playBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, CometChatMediaViewActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.MEDIA_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, CometChatConstants.MESSAGE_TYPE_AUDIO);
intent.putExtra(UIKitConstants.IntentStrings.INTENT_MEDIA_MESSAGE, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
context.startActivity(intent);
}
});
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.reactionLayout.setVisibility(View.GONE);
setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method initMessageAdapter.
/**
* This method is used to initialize the message adapter if it is empty else it helps
* to update the messagelist in adapter.
*
* @param messageList is a list of messages which will be added.
*/
private void initMessageAdapter(List<BaseMessage> messageList) {
if (messageAdapter == null) {
messageAdapter = new ThreadAdapter(getActivity(), messageList, type);
rvChatListView.setAdapter(messageAdapter);
messageAdapter.notifyDataSetChanged();
} else {
messageAdapter.updateList(messageList);
}
if (!isBlockedByMe && rvSmartReply.getAdapter().getItemCount() == 0 && rvSmartReply.getVisibility() == GONE) {
BaseMessage lastMessage = messageAdapter.getLastMessage();
checkSmartReply(lastMessage);
}
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method editMessage.
/**
* This method is used to edit the message. This methods takes old message and change text of old
* message with new message i.e String and update it.
*
* @param baseMessage is an object of BaseMessage, It is a old message which is going to be edited.
* @param message is String, It is a new message which will be replaced with text of old message.
* @see TextMessage
* @see BaseMessage
* @see CometChat#editMessage(BaseMessage, CometChat.CallbackListener)
*/
private void editMessage(BaseMessage baseMessage, String message) {
isEdit = false;
isParent = true;
TextMessage textMessage;
if (baseMessage.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_USER);
else
textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_GROUP);
sendTypingIndicator(true);
textMessage.setId(baseMessage.getId());
CometChat.editMessage(textMessage, new CometChat.CallbackListener<BaseMessage>() {
@Override
public void onSuccess(BaseMessage message) {
if (messageAdapter != null) {
Log.e(TAG, "onSuccess: " + message.toString());
messageAdapter.setUpdatedMessage(message);
}
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
Log.d(TAG, "onError: " + e.getMessage());
}
});
}
Aggregations