Search in sources :

Example 1 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CallHistoryAdapter 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;
    boolean isIncoming = false, isVideo = false, isMissed = false;
    String callMessageText = "";
    if (call.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
        if (call.getSender().getUid().equals(loggedInUser)) {
            if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.missed_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.missed_voice_call);
                    isVideo = false;
                }
                isMissed = true;
            } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.rejected_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.rejected_voice_call);
                    isVideo = false;
                }
            } else {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.outgoing_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.outgoing_voice_call);
                    isVideo = false;
                }
            }
            isIncoming = false;
        } else {
            if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.missed_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.missed_voice_call);
                    isVideo = false;
                }
                isMissed = true;
            } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.rejected_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.rejected_voice_call);
                    isVideo = false;
                }
            } else {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.incoming_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.incoming_audio_call);
                    isVideo = false;
                }
            }
            isIncoming = true;
        }
    }
    // }
    if (isVideo) {
        if (isIncoming) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_video_call, 0, 0, 0);
        } else {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_video_call, 0, 0, 0);
        }
    } else {
        if (isIncoming && isMissed) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_incoming_24dp, 0, 0, 0);
        } else if (isIncoming && !isMissed) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_call, 0, 0, 0);
        } else if (!isIncoming && isMissed) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_outgoing_24dp, 0, 0, 0);
        } else {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_call, 0, 0, 0);
        }
    }
    callViewHolder.callHistoryRowBinding.callTimeTv.setText(Utils.getHeaderDate(call.getInitiatedAt() * 1000));
    callViewHolder.callHistoryRowBinding.callInfoTv.setText(callMessageText);
    callViewHolder.callHistoryRowBinding.callDateTv.setText(Utils.getCallDate(call.getSentAt() * 1000));
    callViewHolder.callHistoryRowBinding.getRoot().setTag(R.string.call, call);
}
Also used : Call(com.cometchat.pro.core.Call) BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 2 with BaseMessage

use of com.cometchat.pro.models.BaseMessage 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);
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) Intent(android.content.Intent)

Example 3 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatSharedFiles method setAdapter.

/**
 * This method is used to setAdapter for File messages.
 * @param baseMessageList is object of List<BaseMessage> which contains list of messages.
 * @see CometChatSharedMediaAdapter
 */
private void setAdapter(List<BaseMessage> baseMessageList) {
    List<BaseMessage> filteredList = removeDeletedMessage(baseMessageList);
    messageList.addAll(filteredList);
    if (adapter == null) {
        adapter = new CometChatSharedMediaAdapter(getContext(), filteredList);
        rvFiles.setAdapter(adapter);
    } else
        adapter.updateMessageList(filteredList);
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) CometChatSharedMediaAdapter(com.cometchat.pro.uikit.ui_components.shared.cometchatSharedMedia.adapter.CometChatSharedMediaAdapter)

Example 4 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatSharedVideos method setAdapter.

/**
 * This method is used to setAdapter for Video messages.
 * @param baseMessageList is object of List<BaseMessage> which contains list of messages.
 * @see CometChatSharedMediaAdapter
 */
private void setAdapter(List<BaseMessage> baseMessageList) {
    List<BaseMessage> filteredList = removeDeletedMessage(baseMessageList);
    messageList.addAll(filteredList);
    if (adapter == null) {
        adapter = new CometChatSharedMediaAdapter(getContext(), filteredList);
        rvFiles.setAdapter(adapter);
    } else
        adapter.updateMessageList(filteredList);
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) CometChatSharedMediaAdapter(com.cometchat.pro.uikit.ui_components.shared.cometchatSharedMedia.adapter.CometChatSharedMediaAdapter)

Example 5 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MessageAdapter method setDeleteData.

private void setDeleteData(DeleteMessageViewHolder 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 (baseMessage.getDeletedAt() != 0) {
        viewHolder.tvThreadReplyCount.setVisibility(View.GONE);
        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);
    setColorFilter(baseMessage, viewHolder.cardView);
    // if (selectedItemList.contains(baseMessage.getId()))
    viewHolder.txtTime.setVisibility(View.VISIBLE);
// else
// viewHolder.txtTime.setVisibility(View.GONE);
// 
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage)

Aggregations

BaseMessage (com.cometchat.pro.models.BaseMessage)53 View (android.view.View)19 ImageView (android.widget.ImageView)19 TextView (android.widget.TextView)19 CardView (androidx.cardview.widget.CardView)19 RecyclerView (androidx.recyclerview.widget.RecyclerView)19 MaterialCardView (com.google.android.material.card.MaterialCardView)19 Intent (android.content.Intent)18 MediaMessage (com.cometchat.pro.models.MediaMessage)14 JSONException (org.json.JSONException)14 CometChatException (com.cometchat.pro.exceptions.CometChatException)11 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)11 JSONObject (org.json.JSONObject)10 TextMessage (com.cometchat.pro.models.TextMessage)8 User (com.cometchat.pro.models.User)7 AlertDialog (android.app.AlertDialog)6 DialogInterface (android.content.DialogInterface)6 CustomMessage (com.cometchat.pro.models.CustomMessage)5 Call (com.cometchat.pro.core.Call)4 Attachment (com.cometchat.pro.models.Attachment)4