Search in sources :

Example 1 with CometChatReactionDialog

use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog 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 2 with CometChatReactionDialog

use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatThreadMessageList method initViewComponent.

/**
 * This is a main method which is used to initialize the view for this fragment.
 *
 * @param view
 */
private void initViewComponent(View view) {
    setHasOptionsMenu(true);
    CometChatError.init(getContext());
    nestedScrollView = view.findViewById(R.id.nested_scrollview);
    noReplyMessages = view.findViewById(R.id.no_reply_layout);
    ivMoreOption = view.findViewById(R.id.ic_more_option);
    ivMoreOption.setOnClickListener(this);
    ivForwardMessage = view.findViewById(R.id.ic_forward_option);
    ivForwardMessage.setOnClickListener(this);
    textMessage = view.findViewById(R.id.tv_textMessage);
    imageMessage = view.findViewById(R.id.iv_imageMessage);
    videoMessage = view.findViewById(R.id.vv_videoMessage);
    fileMessage = view.findViewById(R.id.rl_fileMessage);
    locationMessage = view.findViewById(R.id.rl_locationMessage);
    mapView = view.findViewById(R.id.iv_mapView);
    addressView = view.findViewById(R.id.tv_address);
    fileName = view.findViewById(R.id.tvFileName);
    fileSize = view.findViewById(R.id.tvFileSize);
    fileExtension = view.findViewById(R.id.tvFileExtension);
    stickerMessage = view.findViewById(R.id.iv_stickerMessage);
    whiteboardMessage = view.findViewById(R.id.whiteboard_vw);
    whiteBoardTxt = view.findViewById(R.id.whiteboard_message);
    joinWhiteBoard = view.findViewById(R.id.join_whiteboard);
    writeboardMessage = view.findViewById(R.id.writeboard_vw);
    writeBoardTxt = view.findViewById(R.id.writeboard_message);
    joinWriteBoard = view.findViewById(R.id.join_whiteboard);
    pollMessage = view.findViewById(R.id.poll_message);
    pollQuestionTv = view.findViewById(R.id.tv_question);
    pollOptionsLL = view.findViewById(R.id.options_group);
    totalCount = view.findViewById(R.id.total_votes);
    if (messageType.equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
        imageMessage.setVisibility(View.VISIBLE);
        Glide.with(context).load(message).into(imageMessage);
    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_VIDEO)) {
        videoMessage.setVisibility(VISIBLE);
        MediaController mediacontroller = new MediaController(getContext());
        mediacontroller.setAnchorView(videoMessage);
        videoMessage.setMediaController(mediacontroller);
        videoMessage.setVideoURI(Uri.parse(message));
    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_FILE) || messageType.equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
        fileMessage.setVisibility(VISIBLE);
        if (messageFileName != null)
            fileName.setText(messageFileName);
        if (messageExtension != null)
            fileExtension.setText(messageExtension);
        fileSize.setText(Utils.getFileSize(messageSize));
    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
        textMessage.setVisibility(View.VISIBLE);
        textMessage.setText(message);
    } else if (messageType.equals(UIKitConstants.IntentStrings.STICKERS)) {
        ivForwardMessage.setVisibility(GONE);
        stickerMessage.setVisibility(View.VISIBLE);
        Glide.with(context).load(message).into(stickerMessage);
    } else if (messageType.equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
        ivForwardMessage.setVisibility(GONE);
        whiteboardMessage.setVisibility(View.VISIBLE);
        if (name.equals(loggedInUser.getName()))
            whiteBoardTxt.setText(getString(R.string.you_created_whiteboard));
        else
            whiteBoardTxt.setText(name + " " + getString(R.string.has_shared_whiteboard));
        joinWhiteBoard.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                String boardUrl = message;
                Intent intent = new Intent(context, CometChatWebViewActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.URL, boardUrl);
                startActivity(intent);
            }
        });
    } else if (messageType.equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
        ivForwardMessage.setVisibility(GONE);
        writeboardMessage.setVisibility(View.VISIBLE);
        if (name.equals(loggedInUser.getName()))
            writeBoardTxt.setText(getString(R.string.you_created_document));
        else
            writeBoardTxt.setText(name + " " + getString(R.string.has_shared_document));
        joinWriteBoard.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                String boardUrl = message;
                Intent intent = new Intent(context, CometChatWebViewActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.URL, boardUrl);
                startActivity(intent);
            }
        });
    } else if (messageType.equals(UIKitConstants.IntentStrings.LOCATION)) {
        initLocation();
        locationMessage.setVisibility(VISIBLE);
        addressView.setText(Utils.getAddress(context, parentMessageLatitude, parentMessageLongitude));
        String mapUrl = UIKitConstants.MapUrl.MAPS_URL + parentMessageLatitude + "," + parentMessageLongitude + "&key=" + UIKitConstants.MapUrl.MAP_ACCESS_KEY;
        Glide.with(context).load(mapUrl).diskCacheStrategy(DiskCacheStrategy.ALL).into(mapView);
    } else if (messageType.equals(UIKitConstants.IntentStrings.POLLS)) {
        ivForwardMessage.setVisibility(GONE);
        pollMessage.setVisibility(VISIBLE);
        totalCount.setText(voteCount + " Votes");
        pollQuestionTv.setText(pollQuestion);
        try {
            JSONObject options = new JSONObject(pollOptions);
            ArrayList<String> voterInfo = pollResult;
            for (int k = 0; k < options.length(); k++) {
                LinearLayout linearLayout = new LinearLayout(context);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                linearLayout.setPadding(8, 8, 8, 8);
                linearLayout.setBackground(context.getResources().getDrawable(R.drawable.cc_message_bubble_right));
                linearLayout.setBackgroundTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.textColorWhite)));
                layoutParams.bottomMargin = (int) Utils.dpToPx(context, 8);
                linearLayout.setLayoutParams(layoutParams);
                TextView textViewPercentage = new TextView(context);
                TextView textViewOption = new TextView(context);
                textViewPercentage.setPadding(16, 4, 0, 4);
                textViewOption.setPadding(16, 4, 0, 4);
                textViewOption.setTextAppearance(context, R.style.TextAppearance_AppCompat_Medium);
                textViewPercentage.setTextAppearance(context, R.style.TextAppearance_AppCompat_Medium);
                textViewPercentage.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
                textViewOption.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
                String optionStr = options.getString(String.valueOf(k + 1));
                if (voteCount > 0) {
                    int percentage = Math.round((Integer.parseInt(voterInfo.get(k)) * 100) / voteCount);
                    if (percentage > 0)
                        textViewPercentage.setText(percentage + "% ");
                }
                textViewOption.setText(optionStr);
                int finalK = k;
                if (pollOptionsLL.getChildCount() != options.length()) {
                    linearLayout.addView(textViewPercentage);
                    linearLayout.addView(textViewOption);
                    pollOptionsLL.addView(linearLayout);
                }
                textViewOption.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        try {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("vote", finalK + 1);
                            jsonObject.put("id", baseMessage.getId());
                            CometChat.callExtension("polls", "POST", "/v1/vote", jsonObject, new CometChat.CallbackListener<JSONObject>() {

                                @Override
                                public void onSuccess(JSONObject jsonObject) {
                                    // Voted successfully
                                    Log.e(TAG, "onSuccess: " + jsonObject.toString());
                                    CometChatSnackBar.show(context, rvChatListView, context.getString(R.string.voted_success), CometChatSnackBar.SUCCESS);
                                }

                                @Override
                                public void onError(CometChatException e) {
                                    // Some error occured
                                    CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "polls"), CometChatSnackBar.ERROR);
                                }
                            });
                        } catch (Exception e) {
                            Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
                            Log.e(TAG, "onError: " + e.getMessage());
                        }
                    }
                });
            }
        } catch (Exception e) {
            Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
            Log.e(TAG, "setPollsData: " + e.getMessage());
        }
    }
    addReaction = view.findViewById(R.id.add_reaction);
    reactionLayout = view.findViewById(R.id.reactions_layout);
    if (reactionInfo.size() > 0)
        reactionLayout.setVisibility(VISIBLE);
    setReactionForParentMessage();
    addReaction.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            CometChatReactionDialog reactionDialog = new CometChatReactionDialog();
            reactionDialog.setOnEmojiClick(new OnReactionClickListener() {

                @Override
                public void onEmojiClicked(Reaction emojicon) {
                    JSONObject body = new JSONObject();
                    try {
                        body.put("msgId", parentId);
                        body.put("emoji", emojicon.getName());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    CometChat.callExtension("reactions", "POST", "/v1/react", body, new CometChat.CallbackListener<JSONObject>() {

                        @Override
                        public void onSuccess(JSONObject responseObject) {
                            reactionLayout.setVisibility(VISIBLE);
                            reactionDialog.dismiss();
                            Log.e(TAG, "onSuccess: " + responseObject);
                        // ReactionModel added successfully.
                        }

                        @Override
                        public void onError(CometChatException e) {
                            CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "reactions"), CometChatSnackBar.ERROR);
                        // Some error occured.
                        }
                    });
                }
            });
            reactionDialog.show(getFragmentManager(), "ReactionThreadDialog");
        }
    });
    bottomLayout = view.findViewById(R.id.bottom_layout);
    composeBox = view.findViewById(R.id.message_box);
    messageShimmer = view.findViewById(R.id.shimmer_layout);
    composeBox = view.findViewById(R.id.message_box);
    composeBox.usedIn(CometChatThreadMessageListActivity.class.getName());
    composeBox.hidePollOption(true);
    composeBox.hideStickerOption(true);
    composeBox.hideWriteBoardOption(true);
    composeBox.hideWhiteBoardOption(true);
    composeBox.hideGroupCallOption(true);
    composeBox.hideRecordOption(true);
    composeBox.hideSendButton(false);
    container = view.findViewById(R.id.reactions_container);
    composeBox.liveReactionBtn.setOnTouchListener(new LiveReactionListener(700, 1000, new ReactionClickListener() {

        @Override
        public void onClick(View var1) {
            container.setAlpha(1.0f);
            sendLiveReaction();
        }

        @Override
        public void onCancel(View var1) {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (imageView != null && animation != null && animation.isRunning()) {
                        ObjectAnimator animator = ObjectAnimator.ofFloat(container, "alpha", 0.2f);
                        animator.setDuration(700);
                        animator.start();
                        animator.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationEnd(Animator animation) {
                                super.onAnimationEnd(animation);
                                if (imageView != null)
                                    imageView.clearAnimation();
                                container.removeAllViews();
                                if (typingTimer != null)
                                    typingTimer.schedule(new TimerTask() {

                                        @Override
                                        public void run() {
                                            JSONObject metaData = new JSONObject();
                                            try {
                                                metaData.put("reaction", "heart");
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                            TypingIndicator typingIndicator = new TypingIndicator(Id, type, metaData);
                                            CometChat.endTyping(typingIndicator);
                                        }
                                    }, 2000);
                            }
                        });
                    }
                }
            }, 1400);
        }
    }));
    setComposeBoxListener();
    rvSmartReply = view.findViewById(R.id.rv_smartReply);
    editMessageLayout = view.findViewById(R.id.editMessageLayout);
    tvMessageTitle = view.findViewById(R.id.tv_message_layout_title);
    tvMessageSubTitle = view.findViewById(R.id.tv_message_layout_subtitle);
    ImageView ivMessageClose = view.findViewById(R.id.iv_message_close);
    ivMessageClose.setOnClickListener(this);
    replyMessageLayout = view.findViewById(R.id.replyMessageLayout);
    replyTitle = view.findViewById(R.id.tv_reply_layout_title);
    replyMessage = view.findViewById(R.id.tv_reply_layout_subtitle);
    replyMedia = view.findViewById(R.id.iv_reply_media);
    replyClose = view.findViewById(R.id.iv_reply_close);
    replyClose.setOnClickListener(this);
    senderAvatar = view.findViewById(R.id.av_sender);
    setAvatar();
    senderName = view.findViewById(R.id.tv_sender_name);
    senderName.setText(name);
    sentAt = view.findViewById(R.id.tv_message_time);
    sentAt.setText(String.format(getString(R.string.sentattxt), Utils.getLastMessageDate(context, messageSentAt)));
    tvReplyCount = view.findViewById(R.id.thread_reply_count);
    rvChatListView = view.findViewById(R.id.rv_message_list);
    if (parentMessageCategory.equals(CometChatConstants.CATEGORY_CUSTOM)) {
        ivMoreOption.setVisibility(GONE);
    }
    if (replyCount > 0) {
        tvReplyCount.setText(replyCount + " " + getString(R.string.replies));
        noReplyMessages.setVisibility(GONE);
    } else {
        noReplyMessages.setVisibility(VISIBLE);
    }
    MaterialButton unblockUserBtn = view.findViewById(R.id.btn_unblock_user);
    unblockUserBtn.setOnClickListener(this);
    blockedUserName = view.findViewById(R.id.tv_blocked_user_name);
    blockUserLayout = view.findViewById(R.id.blocked_user_layout);
    tvName = view.findViewById(R.id.tv_name);
    tvTypingIndicator = view.findViewById(R.id.tv_typing);
    toolbar = view.findViewById(R.id.chatList_toolbar);
    toolbar.setOnClickListener(this);
    linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    tvName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
    tvName.setText(String.format(getString(R.string.thread_in_name), conversationName));
    setAvatar();
    rvChatListView.setLayoutManager(linearLayoutManager);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Utils.isDarkMode(context)) {
        ivMoreOption.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.textColorWhite)));
        ivForwardMessage.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.textColorWhite)));
        bottomLayout.setBackgroundColor(getResources().getColor(R.color.darkModeBackground));
        toolbar.setBackgroundColor(getResources().getColor(R.color.grey));
        editMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border_dark));
        replyMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border_dark));
        composeBox.setBackgroundColor(getResources().getColor(R.color.darkModeBackground));
        rvChatListView.setBackgroundColor(getResources().getColor(R.color.darkModeBackground));
        tvName.setTextColor(getResources().getColor(R.color.textColorWhite));
    } else {
        ivMoreOption.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.primaryTextColor)));
        ivForwardMessage.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.primaryTextColor)));
        bottomLayout.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.textColorWhite)));
        toolbar.setBackgroundColor(getResources().getColor(R.color.textColorWhite));
        editMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border));
        replyMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border));
        composeBox.setBackgroundColor(getResources().getColor(R.color.textColorWhite));
        rvChatListView.setBackgroundColor(getResources().getColor(R.color.textColorWhite));
        tvName.setTextColor(getResources().getColor(R.color.primaryTextColor));
    }
    KeyBoardUtils.setKeyboardVisibilityListener(getActivity(), (View) rvChatListView.getParent(), keyboardVisible -> {
        if (keyboardVisible) {
            scrollToBottom();
        }
    });
    // Uses to fetch next list of messages if rvChatListView (RecyclerView) is scrolled in downward direction.
    rvChatListView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            // for toolbar elevation animation i.e stateListAnimator
            toolbar.setSelected(rvChatListView.canScrollVertically(-1));
        }

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            if (!isNoMoreMessages && !isInProgress) {
                if (linearLayoutManager.findFirstVisibleItemPosition() == 10 || !rvChatListView.canScrollVertically(-1)) {
                    isInProgress = true;
                    fetchMessage();
                }
            }
        }
    });
    rvSmartReply.setItemClickListener(new OnItemClickListener<String>() {

        @Override
        public void OnItemClick(String var, int position) {
            if (!isSmartReplyClicked) {
                isSmartReplyClicked = true;
                rvSmartReply.setVisibility(GONE);
                sendMessage(var);
            }
        }
    });
    // Check Ongoing Call
    onGoingCallView = view.findViewById(R.id.ongoing_call_view);
    onGoingCallClose = view.findViewById(R.id.close_ongoing_view);
    onGoingCallTxt = view.findViewById(R.id.ongoing_call);
    checkOnGoingCall();
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) OnReactionClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener) MediaController(android.widget.MediaController) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialButton(com.google.android.material.button.MaterialButton) CometChatReactionDialog(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog) TimerTask(java.util.TimerTask) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CometChatWebViewActivity(com.cometchat.pro.uikit.ui_components.messages.extensions.Collaborative.CometChatWebViewActivity) ReactionClickListener(com.cometchat.pro.uikit.ui_components.messages.live_reaction.ReactionClickListener) OnReactionClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener) CometChat(com.cometchat.pro.core.CometChat) ObjectAnimator(android.animation.ObjectAnimator) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Handler(android.os.Handler) JSONException(org.json.JSONException) Intent(android.content.Intent) Reaction(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction) ImageView(android.widget.ImageView) NestedScrollView(androidx.core.widget.NestedScrollView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) VideoView(android.widget.VideoView) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) TypingIndicator(com.cometchat.pro.models.TypingIndicator) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) JSONObject(org.json.JSONObject) RecyclerView(androidx.recyclerview.widget.RecyclerView) LiveReactionListener(com.cometchat.pro.uikit.ui_components.messages.live_reaction.LiveReactionListener) LinearLayout(android.widget.LinearLayout)

Example 3 with CometChatReactionDialog

use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatMessageList method setLongMessageClick.

@Override
public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
    Log.e(TAG, "setLongMessageClick: " + baseMessagesList);
    isReply = false;
    isEdit = false;
    messageActionFragment = new CometChatMessageActions();
    replyMessageLayout.setVisibility(GONE);
    editMessageLayout.setVisibility(GONE);
    fetchSettings();
    List<BaseMessage> textMessageList = new ArrayList<>();
    List<BaseMessage> mediaMessageList = new ArrayList<>();
    List<BaseMessage> locationMessageList = new ArrayList<>();
    List<BaseMessage> pollsMessageList = new ArrayList<>();
    List<BaseMessage> stickerMessageList = new ArrayList<>();
    List<BaseMessage> whiteBoardMessageList = new ArrayList<>();
    List<BaseMessage> writeBoardMessageList = new ArrayList<>();
    List<BaseMessage> meetingMessageList = new ArrayList<>();
    for (BaseMessage baseMessage : baseMessagesList) {
        if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
            textMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_VIDEO) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_FILE) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
            mediaMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
            locationMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.STICKERS)) {
            stickerMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.POLLS)) {
            pollsMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
            whiteBoardMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
            writeBoardMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
            meetingMessageList.add(baseMessage);
        }
    }
    if (textMessageList.size() == 1) {
        BaseMessage basemessage = textMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    editVisible = false;
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
                if (basemessage.getSentAt() == -1) {
                    translateVisible = false;
                    threadVisible = false;
                    deleteVisible = false;
                    editVisible = false;
                    copyVisible = false;
                    forwardVisible = false;
                    reactionVisible = false;
                    replyVisible = false;
                    shareVisible = false;
                    retryVisible = true;
                }
            }
        }
    }
    if (mediaMessageList.size() == 1) {
        translateVisible = false;
        BaseMessage basemessage = mediaMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                copyVisible = false;
                // }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                    editVisible = false;
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                    editVisible = false;
                }
            }
            if (basemessage.getSentAt() == -1) {
                translateVisible = false;
                threadVisible = false;
                deleteVisible = false;
                editVisible = false;
                copyVisible = false;
                forwardVisible = false;
                reactionVisible = false;
                replyVisible = false;
                shareVisible = false;
                retryVisible = true;
            }
        }
    }
    if (locationMessageList.size() == 1) {
        translateVisible = false;
        BaseMessage basemessage = locationMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                copyVisible = false;
                FeatureRestriction.isMessageRepliesEnabled(new FeatureRestriction.OnSuccessListener() {

                    @Override
                    public void onSuccess(Boolean booleanVal) {
                        replyVisible = booleanVal;
                    }
                });
                shareVisible = false;
                FeatureRestriction.isShareCopyForwardMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                    @Override
                    public void onSuccess(Boolean booleanVal) {
                        forwardVisible = booleanVal;
                    }
                });
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                    editVisible = false;
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                    editVisible = false;
                }
            }
            if (basemessage.getSentAt() == -1) {
                translateVisible = false;
                threadVisible = false;
                deleteVisible = false;
                editVisible = false;
                copyVisible = false;
                forwardVisible = false;
                reactionVisible = false;
                replyVisible = false;
                shareVisible = false;
                retryVisible = true;
            }
        }
    }
    if (pollsMessageList.size() == 1) {
        forwardVisible = false;
        translateVisible = false;
        copyVisible = false;
        editVisible = false;
        shareVisible = false;
        BaseMessage basemessage = pollsMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (stickerMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        editVisible = false;
        translateVisible = false;
        shareVisible = false;
        BaseMessage basemessage = stickerMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (whiteBoardMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        translateVisible = false;
        editVisible = false;
        shareVisible = false;
        BaseMessage basemessage = whiteBoardMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (writeBoardMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        editVisible = false;
        translateVisible = false;
        shareVisible = false;
        BaseMessage basemessage = writeBoardMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (meetingMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        editVisible = false;
        shareVisible = false;
        replyVisible = true;
        translateVisible = false;
        threadVisible = false;
        BaseMessage basemessage = meetingMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    baseMessages = baseMessagesList;
    Bundle bundle = new Bundle();
    bundle.putBoolean("copyVisible", copyVisible);
    bundle.putBoolean("threadVisible", threadVisible);
    bundle.putBoolean("shareVisible", shareVisible);
    bundle.putBoolean("editVisible", editVisible);
    bundle.putBoolean("deleteVisible", deleteVisible);
    bundle.putBoolean("replyVisible", replyVisible);
    bundle.putBoolean("forwardVisible", forwardVisible);
    bundle.putBoolean("translateVisible", translateVisible);
    bundle.putBoolean("retryVisible", retryVisible);
    bundle.putBoolean("isReactionVisible", reactionVisible);
    if (baseMessage.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP) && !baseMessage.getSender().getUid().equalsIgnoreCase(loggedInUser.getUid())) {
        bundle.putBoolean("privateReplyVisible", replyPrivately);
        bundle.putBoolean("replyPrivatelyVisible", replyVisible);
    }
    if (CometChat.isExtensionEnabled("reactions")) {
        bundle.putBoolean("isReactionVisible", true);
    } else {
        bundle.putBoolean("isReactionVisible", false);
    }
    if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP) && baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
        FeatureRestriction.isDeliveryReceiptsEnabled(new FeatureRestriction.OnSuccessListener() {

            @Override
            public void onSuccess(Boolean booleanVal) {
                if (booleanVal)
                    bundle.putBoolean("messageInfoVisible", true);
            }
        });
    }
    bundle.putString("type", CometChatMessageListActivity.class.getName());
    messageActionFragment.setArguments(bundle);
    if (baseMessage.getSentAt() != 0) {
        if (retryVisible || editVisible || copyVisible || threadVisible || shareVisible || deleteVisible || replyVisible || forwardVisible || reactionVisible) {
            messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
        }
    }
    messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {

        @Override
        public void onReplyMessagePrivately() {
            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.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE, baseMessage.getRawMessage().toString());
                startActivity(intent);
                if (getActivity() != null)
                    getActivity().finish();
            }
        }

        @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.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
                startActivity(intent);
                if (getActivity() != null)
                    getActivity().finish();
            }
        }

        @Override
        public void onThreadMessageClick() {
            startThreadActivity();
        }

        @Override
        public void onEditMessageClick() {
            if (baseMessage != null && baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                isEdit = true;
                isReply = false;
                tvMessageTitle.setText(getResources().getString(R.string.edit_message));
                tvMessageSubTitle.setText(((TextMessage) baseMessage).getText());
                composeBox.ivMic.setVisibility(GONE);
                composeBox.ivSend.setVisibility(View.VISIBLE);
                editMessageLayout.setVisibility(View.VISIBLE);
                composeBox.etComposeBox.setText(((TextMessage) baseMessage).getText());
                if (messageAdapter != null) {
                    messageAdapter.setSelectedMessage(baseMessage.getId());
                    messageAdapter.notifyDataSetChanged();
                }
            }
        }

        @Override
        public void onReplyMessageClick() {
            replyMessage();
        }

        @Override
        public void onForwardMessageClick() {
            startForwardMessageActivity();
        }

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

        @Override
        public void onCopyMessageClick() {
            String message = "";
            for (BaseMessage bMessage : baseMessages) {
                if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
                    message = message + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
                }
            }
            Log.e(TAG, "onCopy: " + message);
            ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("MessageAdapter", message);
            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);
            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 if (baseMessage.getType().equals(UIKitConstants.IntentStrings.STICKERS)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS);
                } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WHITEBOARD);
                    intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage));
                } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WRITEBOARD);
                    intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage));
                } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.GROUP_CALL);
                } else {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS);
                }
            } 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);
                body.put("msgId", baseMessage.getId());
                body.put("languages", languages);
                body.put("text", ((TextMessage) baseMessage).getText());
                CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {

                    @Override
                    public void onSuccess(JSONObject jsonObject) {
                        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, context.getString(R.string.no_translation_available), CometChatSnackBar.WARNING);
                        }
                    }

                    @Override
                    public void onError(CometChatException e) {
                        Toast.makeText(context, e.getCode(), Toast.LENGTH_LONG).show();
                    }
                });
            } catch (Exception e) {
                Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onRetryClick() {
            if (baseMessage != null) {
                messageAdapter.remove(baseMessage);
                if (baseMessage.getType().equalsIgnoreCase(CometChatConstants.MESSAGE_TYPE_TEXT))
                    sendMessage(((TextMessage) baseMessage).getText());
            }
        }
    });
}
Also used : OnReactionClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener) CometChatException(com.cometchat.pro.exceptions.CometChatException) Action(com.cometchat.pro.models.Action) User(com.cometchat.pro.models.User) MediaMessage(com.cometchat.pro.models.MediaMessage) ArrayList(java.util.ArrayList) CometChatReactionDialog(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog) BaseMessage(com.cometchat.pro.models.BaseMessage) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) ClipboardManager(android.content.ClipboardManager) Bundle(android.os.Bundle) 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) 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)

Aggregations

Intent (android.content.Intent)3 CometChatException (com.cometchat.pro.exceptions.CometChatException)3 CometChatReactionDialog (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog)3 OnReactionClickListener (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener)3 Reaction (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2 BaseMessage (com.cometchat.pro.models.BaseMessage)2 MediaMessage (com.cometchat.pro.models.MediaMessage)2 TextMessage (com.cometchat.pro.models.TextMessage)2 User (com.cometchat.pro.models.User)2 CometChatMessageActions (com.cometchat.pro.uikit.ui_components.messages.message_actions.CometChatMessageActions)2 CometChatMessageInfoScreenActivity (com.cometchat.pro.uikit.ui_components.messages.message_information.CometChatMessageInfoScreenActivity)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Bundle (android.os.Bundle)1