Search in sources :

Example 16 with BaseMessage

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

the class ThreadAdapter method setLocationData.

private void setLocationData(ThreadAdapter.LocationMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    viewHolder.tvUser.setVisibility(View.VISIBLE);
    viewHolder.ivUser.setVisibility(View.VISIBLE);
    setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
    viewHolder.tvUser.setText(baseMessage.getSender().getName());
    setLocationData(baseMessage, viewHolder.tvAddress, viewHolder.ivMap);
    viewHolder.senderTxt.setText(String.format(context.getString(R.string.shared_location), baseMessage.getSender().getName()));
    viewHolder.navigateBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                double latitude = ((CustomMessage) baseMessage).getCustomData().getDouble("latitude");
                double longitude = ((CustomMessage) baseMessage).getCustomData().getDouble("longitude");
                ;
                String label = Utils.getAddress(context, latitude, longitude);
                String uriBegin = "geo:" + latitude + "," + longitude;
                String query = label;
                String encodedQuery = Uri.encode(query);
                String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
                Uri uri = Uri.parse(uriString);
                Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
                // mapIntent.setPackage("com.google.android.apps.maps");
                context.startActivity(mapIntent);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    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);
    viewHolder.rlMessageBubble.setOnClickListener(view -> {
        if (isLongClickEnabled && !isImageMessageClick) {
            setLongClickSelectedItem(baseMessage);
            messageLongClick.setLongMessageClick(longselectedItemList);
        } else {
            setSelectedMessage(baseMessage.getId());
        }
        notifyDataSetChanged();
    });
    viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            if (!isImageMessageClick && !isTextMessageClick) {
                isLongClickEnabled = true;
                isLocationMessageClick = true;
                setLongClickSelectedItem(baseMessage);
                messageLongClick.setLongMessageClick(longselectedItemList);
                notifyDataSetChanged();
            }
            return true;
        }
    });
    viewHolder.reactionLayout.setVisibility(View.GONE);
    setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) CustomMessage(com.cometchat.pro.models.CustomMessage) JSONException(org.json.JSONException) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView) Uri(android.net.Uri)

Example 17 with BaseMessage

use of com.cometchat.pro.models.BaseMessage 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);
    }
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) Attachment(com.cometchat.pro.models.Attachment) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView)

Example 18 with BaseMessage

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

the class ThreadAdapter method setReadReceipts.

/**
 * This method is used to set real time read receipt of particular message in messageList
 * of adapter by updating message.
 *
 * @param messageReceipt is a object of MessageReceipt.
 * @see MessageReceipt
 */
public void setReadReceipts(MessageReceipt messageReceipt) {
    for (int i = messageList.size() - 1; i >= 0; i--) {
        BaseMessage baseMessage = messageList.get(i);
        if (baseMessage.getReadAt() == 0) {
            int index = messageList.indexOf(baseMessage);
            messageList.get(index).setReadAt(messageReceipt.getReadAt());
        }
    }
    notifyDataSetChanged();
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 19 with BaseMessage

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

the class ThreadAdapter method setLinkData.

private void setLinkData(LinkMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    String url = null;
    if (baseMessage != null) {
        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());
                    }
                }
            }
        }
        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);
        viewHolder.rlMessageBubble.setOnClickListener(view -> {
            if (isLongClickEnabled && !isImageMessageClick) {
                setLongClickSelectedItem(baseMessage);
                messageLongClick.setLongMessageClick(longselectedItemList);
            } else {
                setSelectedMessage(baseMessage.getId());
            }
            notifyDataSetChanged();
        });
        viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                if (!isImageMessageClick) {
                    isLongClickEnabled = true;
                    isTextMessageClick = true;
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                    notifyDataSetChanged();
                }
                return true;
            }
        });
        viewHolder.itemView.setTag(R.string.message, baseMessage);
    }
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) JSONObject(org.json.JSONObject) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView) TextMessage(com.cometchat.pro.models.TextMessage) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException)

Example 20 with BaseMessage

use of com.cometchat.pro.models.BaseMessage 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);
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView)

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