Search in sources :

Example 21 with CometChatException

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

the class CometChatMessageList method editMessage.

/**
 * This method is used to edit the message. This methods takes old message and change text of old
 * message with new message i.e String and update it.
 *
 * @param baseMessage is an object of BaseMessage, It is a old message which is going to be edited.
 * @param message     is String, It is a new message which will be replaced with text of old message.
 * @see TextMessage
 * @see BaseMessage
 * @see CometChat#editMessage(BaseMessage, CometChat.CallbackListener)
 */
private void editMessage(BaseMessage baseMessage, String message) {
    isEdit = false;
    TextMessage textMessage;
    if (baseMessage.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_USER);
    else
        textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_GROUP);
    sendTypingIndicator(true);
    textMessage.setId(baseMessage.getId());
    CometChat.editMessage(textMessage, new CometChat.CallbackListener<BaseMessage>() {

        @Override
        public void onSuccess(BaseMessage message) {
            if (messageAdapter != null) {
                Log.e(TAG, "onSuccess: " + message.toString());
                messageAdapter.setUpdatedMessage(message);
            }
        }

        @Override
        public void onError(CometChatException e) {
            Log.d(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) BaseMessage(com.cometchat.pro.models.BaseMessage) CometChat(com.cometchat.pro.core.CometChat) TextMessage(com.cometchat.pro.models.TextMessage)

Example 22 with CometChatException

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

the class CometChatMessageList method createPollDialog.

private void createPollDialog() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(context, R.style.MyDialogTheme);
    View view = LayoutInflater.from(context).inflate(R.layout.add_polls_layout, null);
    alertDialog.setView(view);
    Dialog dialog = alertDialog.create();
    optionsArrayList.clear();
    EditText questionEdt = view.findViewById(R.id.question_edt);
    View option1 = view.findViewById(R.id.option_1);
    View option2 = view.findViewById(R.id.option_2);
    option1.findViewById(R.id.delete_option).setVisibility(GONE);
    option2.findViewById(R.id.delete_option).setVisibility(GONE);
    MaterialCardView addOption = view.findViewById(R.id.add_options);
    LinearLayout optionLayout = view.findViewById(R.id.options_layout);
    MaterialButton addPoll = view.findViewById(R.id.add_poll);
    addPoll.setBackgroundColor(Color.parseColor(UIKitSettings.getColor()));
    ImageView cancelPoll = view.findViewById(R.id.close_poll);
    addOption.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            View optionView = LayoutInflater.from(context).inflate(R.layout.polls_option, null);
            optionsArrayList.add(optionView);
            optionLayout.addView(optionView);
            optionView.findViewById(R.id.delete_option).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    optionsArrayList.remove(optionView);
                    optionLayout.removeView(optionView);
                }
            });
        }
    });
    addPoll.setEnabled(true);
    addPoll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            questionEdt.requestFocus();
            EditText option1Text = option1.findViewById(R.id.option_txt);
            EditText option2Text = option2.findViewById(R.id.option_txt);
            if (questionEdt.getText().toString().trim().isEmpty())
                questionEdt.setError(getString(R.string.fill_this_field));
            else if (option1Text.getText().toString().trim().isEmpty())
                option1Text.setError(getString(R.string.fill_this_field));
            else if (option2Text.getText().toString().trim().isEmpty())
                option2Text.setError(getString(R.string.fill_this_field));
            else {
                ProgressDialog progressDialog;
                progressDialog = ProgressDialog.show(context, "", getResources().getString(R.string.create_a_poll));
                addPoll.setEnabled(false);
                try {
                    JSONArray optionJson = new JSONArray();
                    optionJson.put(option1Text.getText().toString());
                    optionJson.put(option2Text.getText().toString());
                    for (View views : optionsArrayList) {
                        EditText optionsText = views.findViewById(R.id.option_txt);
                        if (!optionsText.getText().toString().trim().isEmpty())
                            optionJson.put(optionsText.getText().toString());
                    }
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("question", questionEdt.getText().toString());
                    jsonObject.put("options", optionJson);
                    jsonObject.put("receiver", Id);
                    jsonObject.put("receiverType", type);
                    CometChat.callExtension("polls", "POST", "/v2/create", jsonObject, new CometChat.CallbackListener<JSONObject>() {

                        @Override
                        public void onSuccess(JSONObject jsonObject) {
                            progressDialog.dismiss();
                            dialog.dismiss();
                        }

                        @Override
                        public void onError(CometChatException e) {
                            progressDialog.dismiss();
                            addPoll.setEnabled(true);
                            Log.e(TAG, "onErrorCallExtension: " + e.getMessage());
                            if (view != null)
                                CometChatSnackBar.show(context, view, CometChatError.Extension.localized(e, "polls"), CometChatSnackBar.ERROR);
                        }
                    });
                } catch (Exception e) {
                    addPoll.setEnabled(true);
                    Log.e(TAG, "onErrorJSON: " + e.getMessage());
                    Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        }
    });
    cancelPoll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditText(android.widget.EditText) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONArray(org.json.JSONArray) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) MaterialCardView(com.google.android.material.card.MaterialCardView) StickerView(com.cometchat.pro.uikit.ui_components.shared.cometchatStickers.StickerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MaterialButton(com.google.android.material.button.MaterialButton) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) MaterialCardView(com.google.android.material.card.MaterialCardView) JSONObject(org.json.JSONObject) Dialog(android.app.Dialog) ProgressDialog(android.app.ProgressDialog) CometChatReactionDialog(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog) AlertDialog(androidx.appcompat.app.AlertDialog) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 23 with CometChatException

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

the class CometChatMessageList method sendMediaMessage.

/**
 * This method is used to send media messages to other users and group.
 *
 * @param file     is an object of File which is been sent within the message.
 * @param filetype is a string which indicate a type of file been sent within the message.
 * @see CometChat#sendMediaMessage(MediaMessage, CometChat.CallbackListener)
 * @see MediaMessage
 */
private void sendMediaMessage(File file, String filetype) {
    MediaMessage mediaMessage;
    if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_USER);
    else
        mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_GROUP);
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("path", file.getAbsolutePath());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    mediaMessage.setMetadata(jsonObject);
    mediaMessage.setMuid("" + System.currentTimeMillis());
    mediaMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
    mediaMessage.setSender(loggedInUser);
    if (messageAdapter != null) {
        messageAdapter.addMessage(mediaMessage);
        scrollToBottom();
    }
    CometChat.sendMediaMessage(mediaMessage, new CometChat.CallbackListener<MediaMessage>() {

        @Override
        public void onSuccess(MediaMessage mediaMessage) {
            Log.d(TAG, "sendMediaMessage onSuccess: " + mediaMessage.toString());
            if (messageAdapter != null) {
                messageAdapter.updateChangedMessage(mediaMessage);
                rvSmartReply.setVisibility(GONE);
            }
        }

        @Override
        public void onError(CometChatException e) {
            e.printStackTrace();
            if (messageAdapter != null) {
                mediaMessage.setSentAt(-1);
                messageAdapter.updateChangedMessage(mediaMessage);
            }
            if (getActivity() != null) {
                CometChatSnackBar.show(context, rvChatListView, e.getMessage(), CometChatSnackBar.ERROR);
            }
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) MediaMessage(com.cometchat.pro.models.MediaMessage) JSONObject(org.json.JSONObject) CometChat(com.cometchat.pro.core.CometChat) JSONException(org.json.JSONException)

Example 24 with CometChatException

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

the class MessageAdapter method setPollsData.

private void setPollsData(PollMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (!baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
        if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
            viewHolder.tvUser.setVisibility(View.GONE);
            viewHolder.ivUser.setVisibility(View.GONE);
        } else if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
            if (isUserDetailVisible) {
                viewHolder.tvUser.setVisibility(View.VISIBLE);
                viewHolder.ivUser.setVisibility(View.VISIBLE);
            } else {
                viewHolder.tvUser.setVisibility(View.GONE);
                viewHolder.ivUser.setVisibility(View.INVISIBLE);
            }
            setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
            viewHolder.tvUser.setText(baseMessage.getSender().getName());
        }
    }
    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

        @Override
        public void onSuccess(Boolean booleanVal) {
            if (baseMessage.getReplyCount() != 0 && booleanVal) {
                viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE);
                viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount() + " " + context.getResources().getString(R.string.replies));
            } else {
                viewHolder.tvThreadReplyCount.setVisibility(View.GONE);
            }
        }
    });
    viewHolder.tvThreadReplyCount.setOnClickListener(view -> {
        Intent intent = new Intent(context, CometChatThreadMessageListActivity.class);
        // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString());
        intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
        intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
        intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount());
        intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getName());
        intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId());
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
        intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
        intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
        try {
            JSONObject option = ((CustomMessage) baseMessage).getCustomData().getJSONObject("options");
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS);
            intent.putExtra(UIKitConstants.IntentStrings.POLL_QUESTION, ((CustomMessage) baseMessage).getCustomData().getString("question"));
            intent.putExtra(UIKitConstants.IntentStrings.POLL_OPTION, option.toString());
            intent.putExtra(UIKitConstants.IntentStrings.POLL_VOTE_COUNT, Extensions.getVoteCount(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.POLL_RESULT, Extensions.getVoterInfo(baseMessage, option.length()));
        } catch (Exception e) {
            Log.e(TAG, "startThreadActivityError: " + e.getMessage());
        }
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
        intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
        if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
            intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid());
        } else {
            if (baseMessage.getReceiverUid().equals(loggedInUser.getUid()))
                intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
            else
                intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid());
        }
        context.startActivity(intent);
    });
    viewHolder.optionGroup.removeAllViews();
    viewHolder.totalCount.setText("0" + context.getString(R.string.votes));
    ArrayList<String> optionList = new ArrayList<>();
    try {
        JSONObject jsonObject = ((CustomMessage) baseMessage).getCustomData();
        JSONObject options = jsonObject.getJSONObject("options");
        ArrayList<String> voterInfo = Extensions.getVoterInfo(baseMessage, options.length());
        viewHolder.tvQuestion.setText(jsonObject.getString("question"));
        for (int k = 0; k < options.length(); k++) {
            int voteCount = Extensions.getVoteCount(baseMessage);
            if (voteCount == 1) {
                viewHolder.totalCount.setText(voteCount + context.getString(R.string.vote));
            } else {
                viewHolder.totalCount.setText(voteCount + context.getString(R.string.votes));
            }
            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.setBackgroundColor(Color.parseColor(UIKitSettings.getColor()));
            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));
            textViewOption.setText(optionStr);
            if (voteCount > 0) {
                int percentage = Math.round((Integer.parseInt(voterInfo.get(k)) * 100) / voteCount);
                if (percentage > 0)
                    textViewPercentage.setText(percentage + "% ");
            }
            if (k + 1 == Extensions.userVotedOn(baseMessage, optionList.size() + 1, loggedInUser.getUid())) {
                textViewPercentage.setCompoundDrawablePadding(8);
                textViewPercentage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_baseline_check_circle_24, 0, 0, 0);
            }
            int finalK = k;
            if (viewHolder.optionGroup.getChildCount() != options.length()) {
                viewHolder.loadingProgress.setVisibility(View.GONE);
                linearLayout.addView(textViewPercentage);
                linearLayout.addView(textViewOption);
                viewHolder.optionGroup.addView(linearLayout);
            }
            linearLayout.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    try {
                        String pollsId = null;
                        if (jsonObject.has("id"))
                            pollsId = jsonObject.getString("id");
                        else
                            pollsId = baseMessage.getId() + "";
                        JSONObject pollsJsonObject = new JSONObject();
                        pollsJsonObject.put("vote", finalK + 1);
                        pollsJsonObject.put("id", pollsId);
                        CometChat.callExtension("polls", "POST", "/v2/vote", pollsJsonObject, new CometChat.CallbackListener<JSONObject>() {

                            @Override
                            public void onSuccess(JSONObject jsonObject) {
                                // Voted successfully
                                viewHolder.loadingProgress.setVisibility(View.VISIBLE);
                                viewHolder.totalCount.setText("0" + context.getString(R.string.votes));
                                Log.e(TAG, "onSuccess: " + jsonObject.toString());
                                Toast.makeText(context, context.getString(R.string.voted_success), Toast.LENGTH_LONG).show();
                            }

                            @Override
                            public void onError(CometChatException e) {
                                // Some error occured
                                Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
                                Log.e(TAG, "onErrorExtension: " + e.getMessage() + "\n" + e.getCode());
                            }
                        });
                    } catch (Exception e) {
                        Log.e(TAG, "onError: " + e.getMessage());
                    }
                }
            });
            optionList.add(options.getString(String.valueOf(k + 1)));
        }
    } catch (Exception e) {
        Log.e(TAG, "setPollsData: " + e.getMessage() + "\n" + viewHolder.totalCount.getText());
    }
    PatternUtils.setHyperLinkSupport(context, viewHolder.tvQuestion);
    showMessageTime(viewHolder, baseMessage);
    // if (messageList.get(messageList.size()-1).equals(baseMessage))
    // {
    // selectedItemList.add(baseMessage.getId());
    // }
    // if (selectedItemList.contains(baseMessage.getId()))
    viewHolder.txtTime.setVisibility(View.VISIBLE);
    // else
    // viewHolder.txtTime.setVisibility(View.GONE);
    setColorFilter(baseMessage, viewHolder.cvMessageView);
    viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

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

Example 25 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException 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)

Aggregations

CometChatException (com.cometchat.pro.exceptions.CometChatException)54 CometChat (com.cometchat.pro.core.CometChat)45 JSONObject (org.json.JSONObject)20 JSONException (org.json.JSONException)19 Intent (android.content.Intent)14 ArrayList (java.util.ArrayList)13 ProgressDialog (android.app.ProgressDialog)12 User (com.cometchat.pro.models.User)10 View (android.view.View)9 TextView (android.widget.TextView)9 TextMessage (com.cometchat.pro.models.TextMessage)9 List (java.util.List)8 ImageView (android.widget.ImageView)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 BaseMessage (com.cometchat.pro.models.BaseMessage)6 Call (com.cometchat.pro.core.Call)5 MediaMessage (com.cometchat.pro.models.MediaMessage)5 UsersRequest (com.cometchat.pro.core.UsersRequest)4 CometChatReactionDialog (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog)4 MaterialCardView (com.google.android.material.card.MaterialCardView)4