Search in sources :

Example 1 with ReactionClickListener

use of com.cometchat.pro.uikit.ui_components.messages.live_reaction.ReactionClickListener 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 2 with ReactionClickListener

use of com.cometchat.pro.uikit.ui_components.messages.live_reaction.ReactionClickListener in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatMessageList 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());
    backIcon = view.findViewById(R.id.back_action);
    infoAction = view.findViewById(R.id.info_action);
    audioCallAction = view.findViewById(R.id.audio_call_action);
    videoCallAction = view.findViewById(R.id.video_call_action);
    backIcon.setOnClickListener(this);
    infoAction.setOnClickListener(this);
    audioCallAction.setOnClickListener(this);
    videoCallAction.setOnClickListener(this);
    bottomLayout = view.findViewById(R.id.bottom_layout);
    messageShimmer = view.findViewById(R.id.shimmer_layout);
    composeBox = view.findViewById(R.id.message_box);
    composeBox.usedIn(CometChatMessageListActivity.class.getName());
    if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        composeBox.hideGroupCallOption(true);
    setComposeBoxListener();
    if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER)) {
        FeatureRestriction.isOneOnOneChatEnabled(new FeatureRestriction.OnSuccessListener() {

            @Override
            public void onSuccess(Boolean booleanVal) {
                if (booleanVal)
                    composeBox.setVisibility(View.VISIBLE);
                else
                    composeBox.setVisibility(View.GONE);
            }
        });
    } else if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP)) {
        FeatureRestriction.isGroupChatEnabled(new FeatureRestriction.OnSuccessListener() {

            @Override
            public void onSuccess(Boolean booleanVal) {
                if (booleanVal)
                    composeBox.setVisibility(View.VISIBLE);
                else
                    composeBox.setVisibility(GONE);
            }
        });
    }
    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);
        }
    }));
    newMessageLayout = view.findViewById(R.id.new_message_layout);
    newMessageLayoutText = view.findViewById(R.id.new_message_tv);
    newMessageLayout.setVisibility(GONE);
    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);
    stickersView = view.findViewById(R.id.stickersView);
    stickerLayout = view.findViewById(R.id.sticker_layout);
    closeStickerView = view.findViewById(R.id.close_sticker_layout);
    closeStickerView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            stickerLayout.setVisibility(GONE);
        }
    });
    stickersView.setStickerClickListener(new StickerClickListener() {

        @Override
        public void onClickListener(Sticker sticker) {
            JSONObject stickerData = new JSONObject();
            try {
                stickerData.put("sticker_url", sticker.getUrl());
                stickerData.put("sticker_name", sticker.getName());
            } catch (JSONException e) {
                e.printStackTrace();
            }
            sendCustomMessage(UIKitConstants.IntentStrings.STICKERS, stickerData);
            stickerLayout.setVisibility(GONE);
        }
    });
    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);
    if (repliedMessage != null) {
        baseMessage = repliedMessage;
        replyMessage();
    }
    rvChatListView = view.findViewById(R.id.rv_message_list);
    MaterialButton unblockUserBtn = view.findViewById(R.id.btn_unblock_user);
    unblockUserBtn.setOnClickListener(this);
    blockedUserName = view.findViewById(R.id.tv_blocked_user_name);
    unblockBtn = view.findViewById(R.id.btn_unblock_user);
    blockUserLayout = view.findViewById(R.id.blocked_user_layout);
    tvName = view.findViewById(R.id.tv_name);
    tvStatus = view.findViewById(R.id.tv_status);
    userAvatar = view.findViewById(R.id.iv_chat_avatar);
    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(name);
    setAvatar();
    rvChatListView.setLayoutManager(linearLayoutManager);
    if (Utils.isDarkMode(context)) {
        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 {
        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 -> {
        isKeyboardVisible = keyboardVisible;
        if (keyboardVisible) {
            scrollToBottom();
            composeBox.ivMic.setVisibility(GONE);
            composeBox.ivSend.setVisibility(View.VISIBLE);
        } else {
            if (isEdit) {
                composeBox.ivMic.setVisibility(GONE);
                composeBox.ivSend.setVisibility(View.VISIBLE);
            } else {
                FeatureRestriction.isVoiceNotesEnabled(new FeatureRestriction.OnSuccessListener() {

                    @Override
                    public void onSuccess(Boolean booleanVal) {
                        if (booleanVal) {
                            composeBox.ivMic.setVisibility(View.VISIBLE);
                            composeBox.ivSend.setVisibility(GONE);
                        } else {
                            composeBox.ivMic.setVisibility(GONE);
                            composeBox.ivSend.setVisibility(View.VISIBLE);
                        }
                    }
                });
            }
        }
    });
    // 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();
                }
            }
            if (messageAdapter != null && ((messageAdapter.getItemCount() - 1) - linearLayoutManager.findLastVisibleItemPosition() < 5)) {
                newMessageLayout.setVisibility(GONE);
                newMessageCount = 0;
            }
        }
    });
    rvSmartReply.setItemClickListener(new OnItemClickListener<String>() {

        @Override
        public void OnItemClick(String var, int position) {
            if (!isSmartReplyClicked) {
                isSmartReplyClicked = true;
                rvSmartReply.setVisibility(GONE);
                sendMessage(var);
            }
        }
    });
    fetchSettings();
    // 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 : LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialButton(com.google.android.material.button.MaterialButton) Sticker(com.cometchat.pro.uikit.ui_components.shared.cometchatStickers.model.Sticker) TimerTask(java.util.TimerTask) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ImageView(android.widget.ImageView) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) StickerClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatStickers.listener.StickerClickListener) ReactionClickListener(com.cometchat.pro.uikit.ui_components.messages.live_reaction.ReactionClickListener) OnReactionClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener) ObjectAnimator(android.animation.ObjectAnimator) Handler(android.os.Handler) JSONException(org.json.JSONException) 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) 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)

Aggregations

Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 ObjectAnimator (android.animation.ObjectAnimator)2 ValueAnimator (android.animation.ValueAnimator)2 Handler (android.os.Handler)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 TypingIndicator (com.cometchat.pro.models.TypingIndicator)2 LiveReactionListener (com.cometchat.pro.uikit.ui_components.messages.live_reaction.LiveReactionListener)2 ReactionClickListener (com.cometchat.pro.uikit.ui_components.messages.live_reaction.ReactionClickListener)2 OnReactionClickListener (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener)2 MaterialButton (com.google.android.material.button.MaterialButton)2 TimerTask (java.util.TimerTask)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 LinearLayout (android.widget.LinearLayout)1