use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class ThreadAdapter method setDeleteData.
private void setDeleteData(DeleteMessageViewHolder viewHolder, int i) {
BaseMessage baseMessage = messageList.get(i);
setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
viewHolder.tvUser.setText(baseMessage.getSender().getName());
if (baseMessage.getDeletedAt() != 0) {
viewHolder.txtMessage.setText(R.string.this_message_deleted);
viewHolder.txtMessage.setTextColor(context.getResources().getColor(R.color.secondaryTextColor));
viewHolder.txtMessage.setTypeface(null, Typeface.ITALIC);
}
showMessageTime(viewHolder, baseMessage);
// if (selectedItemList.contains(baseMessage.getId()))
// viewHolder.txtTime.setVisibility(View.VISIBLE);
// else
// viewHolder.txtTime.setVisibility(View.GONE);
//
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageList 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 MessageAdapter(getActivity(), messageList, CometChatMessageList.class.getName());
rvChatListView.setAdapter(messageAdapter);
stickyHeaderDecoration = new StickyHeaderDecoration(messageAdapter);
rvChatListView.addItemDecoration(stickyHeaderDecoration, 0);
scrollToBottom();
messageAdapter.notifyDataSetChanged();
} else {
messageAdapter.updateList(messageList);
}
if (!isBlockedByMe && rvSmartReply.getAdapter().getItemCount() == 0) {
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 CometChatMessageList 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;
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) {
Log.d(TAG, "onError: " + e.getMessage());
}
});
}
use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatConversationsAdapter method setReadReceipts.
public void setReadReceipts(MessageReceipt readReceipts) {
for (int i = 0; i < filterConversationList.size() - 1; i++) {
Conversation conversation = filterConversationList.get(i);
if (conversation.getConversationType().equals(CometChatConstants.RECEIVER_TYPE_USER) && readReceipts.getSender().getUid().equals(((User) conversation.getConversationWith()).getUid())) {
BaseMessage baseMessage = filterConversationList.get(i).getLastMessage();
if (baseMessage != null && baseMessage.getReadAt() == 0) {
baseMessage.setReadAt(readReceipts.getReadAt());
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 CometChatConversationsAdapter 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 conversationViewHolder is a object of ConversationViewHolder.
* @param position is a position of item in recyclerView.
*
* @see Conversation
*/
@Override
public void onBindViewHolder(@NonNull ConversationViewHolder conversationViewHolder, int position) {
Conversation conversation = filterConversationList.get(position);
String avatar;
String name;
String status;
String lastMessageText = null;
BaseMessage baseMessage = conversation.getLastMessage();
conversationViewHolder.conversationListRowBinding.setConversation(conversation);
conversationViewHolder.conversationListRowBinding.executePendingBindings();
String type = null;
String category = null;
if (baseMessage != null) {
type = baseMessage.getType();
category = baseMessage.getCategory();
setStatusIcon(conversationViewHolder.conversationListRowBinding.messageTime, baseMessage);
conversationViewHolder.conversationListRowBinding.messageTime.setVisibility(View.VISIBLE);
conversationViewHolder.conversationListRowBinding.messageTime.setText(Utils.getLastMessageDate(context, baseMessage.getSentAt()));
lastMessageText = Utils.getLastMessage(context, baseMessage);
if (conversation.getLastMessage().getParentMessageId() != 0) {
conversationViewHolder.conversationListRowBinding.txtInThread.setVisibility(View.VISIBLE);
} else {
conversationViewHolder.conversationListRowBinding.txtInThread.setVisibility(View.GONE);
}
if (UIKitSettings.isHideDeleteMessage() && baseMessage.getDeletedAt() > 0) {
conversationViewHolder.conversationListRowBinding.txtInThread.setVisibility(View.GONE);
conversationViewHolder.conversationListRowBinding.txtUserMessage.setVisibility(View.GONE);
lastMessageText = "";
} else {
conversationViewHolder.conversationListRowBinding.txtUserMessage.setVisibility(View.VISIBLE);
}
} else {
lastMessageText = context.getResources().getString(R.string.tap_to_start_conversation);
conversationViewHolder.conversationListRowBinding.txtUserMessage.setMarqueeRepeatLimit(100);
conversationViewHolder.conversationListRowBinding.txtUserMessage.setHorizontallyScrolling(true);
conversationViewHolder.conversationListRowBinding.txtUserMessage.setSingleLine(true);
conversationViewHolder.conversationListRowBinding.messageTime.setVisibility(View.GONE);
}
if (lastMessageText.trim().isEmpty())
conversationViewHolder.conversationListRowBinding.txtInThread.setVisibility(View.GONE);
conversationViewHolder.conversationListRowBinding.txtUserMessage.setText(lastMessageText);
if (baseMessage != null) {
boolean isSentimentNegative = Extensions.checkSentiment(baseMessage);
if (isSentimentNegative && !baseMessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
conversationViewHolder.conversationListRowBinding.txtUserMessage.setText(context.getResources().getString(R.string.sentiment_content));
}
}
conversationViewHolder.conversationListRowBinding.txtUserMessage.setTypeface(fontUtils.getTypeFace(FontUtils.robotoRegular));
conversationViewHolder.conversationListRowBinding.txtUserName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
conversationViewHolder.conversationListRowBinding.messageTime.setTypeface(fontUtils.getTypeFace(FontUtils.robotoRegular));
if (conversation.getConversationType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
User conversationUser = ((User) conversation.getConversationWith());
name = conversationUser.getName();
avatar = conversationUser.getAvatar();
status = conversationUser.getStatus();
if (status.equals(CometChatConstants.USER_STATUS_ONLINE)) {
conversationViewHolder.conversationListRowBinding.userStatus.setVisibility(View.VISIBLE);
conversationViewHolder.conversationListRowBinding.userStatus.setUserStatus(status);
} else
conversationViewHolder.conversationListRowBinding.userStatus.setVisibility(View.GONE);
} else {
name = ((Group) conversation.getConversationWith()).getName();
avatar = ((Group) conversation.getConversationWith()).getIcon();
conversationViewHolder.conversationListRowBinding.userStatus.setVisibility(View.GONE);
}
conversationViewHolder.conversationListRowBinding.messageCount.setCount(conversation.getUnreadMessageCount());
conversationViewHolder.conversationListRowBinding.txtUserName.setText(name);
conversationViewHolder.conversationListRowBinding.messageCount.setCountBackground(Color.parseColor(UIKitSettings.getColor()));
if (typingIndicator != null) {
if (typingIndicator.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER)) {
conversationViewHolder.conversationListRowBinding.typingIndicator.setText(context.getString(R.string.is_typing));
} else {
conversationViewHolder.conversationListRowBinding.typingIndicator.setText(typingIndicator.getSender().getName() + " " + context.getString(R.string.is_typing));
}
if (isTypingVisible) {
conversationViewHolder.conversationListRowBinding.txtUserMessage.setVisibility(View.VISIBLE);
conversationViewHolder.conversationListRowBinding.typingIndicator.setVisibility(View.GONE);
} else {
conversationViewHolder.conversationListRowBinding.txtUserMessage.setVisibility(View.GONE);
conversationViewHolder.conversationListRowBinding.typingIndicator.setVisibility(View.VISIBLE);
}
}
if (avatar != null && !avatar.isEmpty()) {
conversationViewHolder.conversationListRowBinding.avUser.setAvatar(avatar);
} else {
conversationViewHolder.conversationListRowBinding.avUser.setInitials(name);
}
if (Utils.isDarkMode(context)) {
conversationViewHolder.conversationListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.textColorWhite));
conversationViewHolder.conversationListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.grey));
} else {
conversationViewHolder.conversationListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
conversationViewHolder.conversationListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.light_grey));
}
conversationViewHolder.conversationListRowBinding.getRoot().setTag(R.string.conversation, conversation);
}
Aggregations