Search in sources :

Example 6 with TextMessage

use of com.cometchat.pro.models.TextMessage 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 7 with TextMessage

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

the class Extensions method getTranslatedMessage.

public static String getTranslatedMessage(BaseMessage baseMessage) {
    String translatedMessage = ((TextMessage) baseMessage).getText();
    try {
        if (baseMessage.getMetadata() != null) {
            JSONObject metadataObject = baseMessage.getMetadata();
            if (metadataObject.has("values")) {
                JSONObject valueObject = metadataObject.getJSONObject("values");
                if (valueObject.has("data")) {
                    JSONObject dataObject = valueObject.getJSONObject("data");
                    if (dataObject.has("translations")) {
                        JSONArray translations = dataObject.getJSONArray("translations");
                        if (translations.length() > 0) {
                            JSONObject jsonObject = translations.getJSONObject(0);
                            translatedMessage = jsonObject.getString("message_translated");
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "getTranslatedMessageError: " + e.getMessage());
    }
    return translatedMessage;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TextMessage(com.cometchat.pro.models.TextMessage) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException)

Example 8 with TextMessage

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

the class Extensions method checkDataMasking.

public static String checkDataMasking(Context context, BaseMessage baseMessage) {
    String result = ((TextMessage) baseMessage).getText();
    String sensitiveData;
    String messageMasked;
    HashMap<String, JSONObject> extensionList = Extensions.extensionCheck(baseMessage);
    if (extensionList != null) {
        try {
            if (extensionList.containsKey("dataMasking")) {
                JSONObject dataMasking = extensionList.get("dataMasking");
                JSONObject dataObject = dataMasking.getJSONObject("data");
                if (dataObject.has("sensitive_data") && dataObject.has("message_masked")) {
                    sensitiveData = dataObject.getString("sensitive_data");
                    messageMasked = dataObject.getString("message_masked");
                    if (sensitiveData.equals("no"))
                        result = ((TextMessage) baseMessage).getText();
                    else
                        result = messageMasked;
                } else if (dataObject.has("action") && dataObject.has("message")) {
                    result = dataObject.getString("message");
                }
            } else {
                result = ((TextMessage) baseMessage).getText();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return result;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) TextMessage(com.cometchat.pro.models.TextMessage)

Example 9 with TextMessage

use of com.cometchat.pro.models.TextMessage 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());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) BaseMessage(com.cometchat.pro.models.BaseMessage) CometChat(com.cometchat.pro.core.CometChat) TextMessage(com.cometchat.pro.models.TextMessage)

Example 10 with TextMessage

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

the class CometChatConversationsAdapter method getFilter.

/**
 * It is used to perform search operation in filterConversationList. It will check
 * whether searchKeyword is similar to username or group name and modify filterConversationList
 * accordingly. In case if searchKeyword is empty it will set filterConversationList = conversationList
 *
 * @return
 */
@Override
public Filter getFilter() {
    return new Filter() {

        @Override
        protected FilterResults performFiltering(CharSequence charSequence) {
            String searchKeyword = charSequence.toString();
            if (searchKeyword.isEmpty()) {
                filterConversationList = conversationList;
            } else {
                List<Conversation> tempFilter = new ArrayList<>();
                for (Conversation conversation : filterConversationList) {
                    if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_USER) && ((User) conversation.getConversationWith()).getName().toLowerCase().contains(searchKeyword)) {
                        tempFilter.add(conversation);
                    } else if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_GROUP) && ((Group) conversation.getConversationWith()).getName().toLowerCase().contains(searchKeyword)) {
                        tempFilter.add(conversation);
                    } else if (conversation.getLastMessage() != null && conversation.getLastMessage().getCategory().equals(CometChatConstants.CATEGORY_MESSAGE) && conversation.getLastMessage().getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT) && ((TextMessage) conversation.getLastMessage()).getText() != null && ((TextMessage) conversation.getLastMessage()).getText().contains(searchKeyword)) {
                        tempFilter.add(conversation);
                    }
                }
                filterConversationList = tempFilter;
            }
            FilterResults filterResults = new FilterResults();
            filterResults.values = filterConversationList;
            return filterResults;
        }

        @Override
        protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
            filterConversationList = (List<Conversation>) filterResults.values;
            notifyDataSetChanged();
        }
    };
}
Also used : Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup) Filter(android.widget.Filter) ArrayList(java.util.ArrayList) Conversation(com.cometchat.pro.models.Conversation) TextMessage(com.cometchat.pro.models.TextMessage)

Aggregations

TextMessage (com.cometchat.pro.models.TextMessage)19 CometChatException (com.cometchat.pro.exceptions.CometChatException)17 JSONObject (org.json.JSONObject)13 JSONException (org.json.JSONException)12 BaseMessage (com.cometchat.pro.models.BaseMessage)8 Intent (android.content.Intent)7 CometChat (com.cometchat.pro.core.CometChat)7 View (android.view.View)5 ImageView (android.widget.ImageView)5 MediaMessage (com.cometchat.pro.models.MediaMessage)5 TextView (android.widget.TextView)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 CardView (androidx.cardview.widget.CardView)3 CustomMessage (com.cometchat.pro.models.CustomMessage)3 User (com.cometchat.pro.models.User)3 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)3 ArrayList (java.util.ArrayList)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2 Conversation (com.cometchat.pro.models.Conversation)2