Search in sources :

Example 6 with User

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

the class CometChatUsersAdapter method getHeaderId.

@Override
public long getHeaderId(int var1) {
    User user = this.userArrayList.get(var1);
    char name = user.getName() != null && !user.getName().isEmpty() ? user.getName().substring(0, 1).toUpperCase().toCharArray()[0] : '#';
    return (int) name;
}
Also used : User(com.cometchat.pro.models.User)

Example 7 with User

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

the class CallBroadcast method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String ourCode = "*007#";
    String dialNumber = intent.getData().toString();
    if (dialNumber.contains(ourCode)) {
        setResultData(null);
        String phoneNumber = dialNumber.replace(ourCode, "");
        UsersRequest usersRequest = new UsersRequest.UsersRequestBuilder().setTags(Arrays.asList(phoneNumber)).setLimit(10).build();
        usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {

            @Override
            public void onSuccess(List<User> users) {
                if (!users.isEmpty()) {
                    User user = users.get(0);
                    Intent userDetail = new Intent(context, CometChatUserDetailScreenActivity.class);
                    userDetail.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
                    userDetail.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
                    userDetail.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                    context.startActivity(userDetail);
                }
            }

            @Override
            public void onError(CometChatException e) {
                Toast.makeText(context, "Unable to find user", Toast.LENGTH_LONG).show();
                context.startActivity(new Intent(context, CometChatUI.class));
            }
        });
    }
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) List(java.util.List) Intent(android.content.Intent) UsersRequest(com.cometchat.pro.core.UsersRequest) CometChatUserDetailScreenActivity(com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity)

Example 8 with User

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

the class CometChatThreadMessageList method showBottomSheet.

private void showBottomSheet(CometChatMessageActions messageActionFragment) {
    messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
    messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {

        @Override
        public void onPrivateReplyToUser() {
            if (baseMessage != null) {
                User user = baseMessage.getSender();
                Intent intent = new Intent(context, CometChatMessageListActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
                intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
                intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
                startActivity(intent);
                if (getActivity() != null)
                    getActivity().finish();
            }
        }

        @Override
        public void onThreadMessageClick() {
        }

        @Override
        public void onEditMessageClick() {
            if (isParent)
                editParentMessage();
            else
                editThreadMessage();
        }

        @Override
        public void onReplyMessageClick() {
        }

        @Override
        public void onReplyMessagePrivately() {
        }

        @Override
        public void onForwardMessageClick() {
            if (isParent)
                startForwardThreadActivity();
            else
                startForwardMessageActivity();
        }

        @Override
        public void onDeleteMessageClick() {
            deleteMessage(baseMessage);
            if (messageAdapter != null) {
                messageAdapter.clearLongClickSelectedItem();
                messageAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onCopyMessageClick() {
            String copyMessage = "";
            if (isParent) {
                copyMessage = message;
                isParent = true;
            } else {
                for (BaseMessage bMessage : baseMessages) {
                    if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
                        copyMessage = copyMessage + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
                    }
                }
                isParent = false;
            }
            Log.e(TAG, "onCopy: " + message);
            ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("ThreadMessageAdapter", copyMessage);
            clipboardManager.setPrimaryClip(clipData);
            Toast.makeText(context, getResources().getString(R.string.text_copied), Toast.LENGTH_LONG).show();
            if (messageAdapter != null) {
                messageAdapter.clearLongClickSelectedItem();
                messageAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onShareMessageClick() {
            shareMessage();
        }

        @Override
        public void onMessageInfoClick() {
            Intent intent = new Intent(context, CometChatMessageInfoScreenActivity.class);
            if (isParent) {
            } else {
                intent.putExtra(UIKitConstants.IntentStrings.ID, baseMessage.getId());
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
                intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
                if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                    intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.checkProfanityMessage(context, baseMessage));
                } else if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_CUSTOM)) {
                    if (((CustomMessage) baseMessage).getCustomData() != null)
                        intent.putExtra(UIKitConstants.IntentStrings.CUSTOM_MESSAGE, ((CustomMessage) baseMessage).getCustomData().toString());
                    if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
                        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION);
                    }
                } else {
                    boolean isImageNotSafe = Extensions.getImageModeration(context, baseMessage);
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
                    intent.putExtra(UIKitConstants.IntentStrings.IMAGE_MODERATION, isImageNotSafe);
                }
            }
            context.startActivity(intent);
        }

        @Override
        public void onReactionClick(Reaction reaction) {
            if (reaction.getName().equals("add_emoji")) {
                CometChatReactionDialog reactionDialog = new CometChatReactionDialog();
                reactionDialog.setOnEmojiClick(new OnReactionClickListener() {

                    @Override
                    public void onEmojiClicked(Reaction emojicon) {
                        sendReaction(emojicon);
                        reactionDialog.dismiss();
                    }
                });
                reactionDialog.show(getFragmentManager(), "ReactionDialog");
            } else {
                sendReaction(reaction);
            }
        }

        @Override
        public void onTranslateMessageClick() {
            try {
                String localeLanguage = Locale.getDefault().getLanguage();
                JSONObject body = new JSONObject();
                JSONArray languages = new JSONArray();
                languages.put(localeLanguage);
                if (isParent) {
                    body.put("msgId", parentId);
                    body.put("text", textMessage.getText().toString());
                } else {
                    body.put("msgId", baseMessage.getId());
                    body.put("text", ((TextMessage) baseMessage).getText());
                }
                body.put("languages", languages);
                CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {

                    @Override
                    public void onSuccess(JSONObject jsonObject) {
                        if (isParent) {
                            if (Extensions.isMessageTranslated(jsonObject, textMessage.getText().toString())) {
                                String translatedMessage = Extensions.getTextFromTranslatedMessage(jsonObject, textMessage.getText().toString());
                                textMessage.setText(translatedMessage);
                            } else {
                                CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
                            }
                        } else {
                            if (Extensions.isMessageTranslated(jsonObject, ((TextMessage) baseMessage).getText())) {
                                if (baseMessage.getMetadata() != null) {
                                    JSONObject meta = baseMessage.getMetadata();
                                    try {
                                        meta.accumulate("values", jsonObject);
                                        baseMessage.setMetadata(meta);
                                        updateMessage(baseMessage);
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    baseMessage.setMetadata(jsonObject);
                                    updateMessage(baseMessage);
                                }
                            } else {
                                CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
                            }
                        }
                    }

                    @Override
                    public void onError(CometChatException e) {
                        CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "message-translation"), CometChatSnackBar.ERROR);
                    }
                });
            } catch (Exception e) {
                Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onRetryClick() {
        }
    });
}
Also used : ClipboardManager(android.content.ClipboardManager) OnReactionClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener) CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) MediaMessage(com.cometchat.pro.models.MediaMessage) CometChatMessageListActivity(com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Intent(android.content.Intent) Reaction(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) CometChatReactionDialog(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog) BaseMessage(com.cometchat.pro.models.BaseMessage) JSONObject(org.json.JSONObject) CometChatMessageInfoScreenActivity(com.cometchat.pro.uikit.ui_components.messages.message_information.CometChatMessageInfoScreenActivity) CometChatMessageActions(com.cometchat.pro.uikit.ui_components.messages.message_actions.CometChatMessageActions) ClipData(android.content.ClipData) TextMessage(com.cometchat.pro.models.TextMessage)

Example 9 with User

use of com.cometchat.pro.models.User 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();
}
Also used : User(com.cometchat.pro.models.User) BaseMessage(com.cometchat.pro.models.BaseMessage) Conversation(com.cometchat.pro.models.Conversation)

Example 10 with User

use of com.cometchat.pro.models.User 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);
}
Also used : User(com.cometchat.pro.models.User) BaseMessage(com.cometchat.pro.models.BaseMessage) Conversation(com.cometchat.pro.models.Conversation)

Aggregations

User (com.cometchat.pro.models.User)28 CometChatException (com.cometchat.pro.exceptions.CometChatException)12 View (android.view.View)10 Intent (android.content.Intent)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 CometChat (com.cometchat.pro.core.CometChat)8 BaseMessage (com.cometchat.pro.models.BaseMessage)7 TextView (android.widget.TextView)6 Call (com.cometchat.pro.core.Call)6 Group (com.cometchat.pro.models.Group)6 Editable (android.text.Editable)5 TextWatcher (android.text.TextWatcher)5 ImageView (android.widget.ImageView)5 Conversation (com.cometchat.pro.models.Conversation)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ViewGroup (android.view.ViewGroup)4 InputMethodManager (android.view.inputmethod.InputMethodManager)4 UsersRequest (com.cometchat.pro.core.UsersRequest)4 KeyEvent (android.view.KeyEvent)3