Search in sources :

Example 26 with BaseMessage

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

the class MessageAdapter method setImageData.

/**
 * This method is called whenever viewType of item is media. It is used to bind ImageMessageViewHolder
 * contents with MediaMessage at a given position.
 * It loads image of MediaMessage using its url.
 *
 * @param viewHolder is a object of ImageMessageViewHolder.
 * @param i is a position of item in recyclerView.
 * @see MediaMessage
 * @see BaseMessage
 */
private void setImageData(ImageMessageViewHolder 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());
        }
    }
    boolean isImageNotSafe = Extensions.getImageModeration(context, baseMessage);
    String smallUrl = Extensions.getThumbnailGeneration(context, baseMessage);
    Attachment attachment = ((MediaMessage) baseMessage).getAttachment();
    if (attachment != null) {
        if (smallUrl != null) {
            if (attachment.getFileExtension().equalsIgnoreCase(".gif")) {
                setImageDrawable(viewHolder, smallUrl, true, false);
            } else {
                setImageDrawable(viewHolder, smallUrl, false, isImageNotSafe);
            }
        } else {
            if (attachment.getFileExtension().equalsIgnoreCase(".gif"))
                setImageDrawable(viewHolder, ((MediaMessage) baseMessage).getAttachment().getFileUrl(), true, false);
            else
                setImageDrawable(viewHolder, ((MediaMessage) baseMessage).getAttachment().getFileUrl(), false, isImageNotSafe);
        }
    }
    if (isImageNotSafe) {
        viewHolder.sensitiveLayout.setVisibility(View.VISIBLE);
    } else {
        viewHolder.sensitiveLayout.setVisibility(View.GONE);
    }
    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);
            }
        }
    });
    if (baseMessage.getMetadata() != null) {
        try {
            String filePath = baseMessage.getMetadata().getString("path");
            Glide.with(context).load(filePath).diskCacheStrategy(DiskCacheStrategy.NONE).into(viewHolder.imageView);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    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.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
        intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
        intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
        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);
    });
    showMessageTime(viewHolder, baseMessage);
    // if (selectedItemList.contains(baseMessage.getId()))
    viewHolder.txtTime.setVisibility(View.VISIBLE);
    // else
    // viewHolder.txtTime.setVisibility(View.GONE);
    viewHolder.rlMessageBubble.setOnClickListener(view -> {
        if (isImageNotSafe) {
            AlertDialog.Builder alert = new AlertDialog.Builder(context);
            alert.setTitle("Unsafe Content");
            alert.setIcon(R.drawable.ic_hand);
            alert.setMessage("Are you surely want to see this unsafe content");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(), context);
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            alert.create().show();
        } else {
            setSelectedMessage(baseMessage.getId());
            notifyDataSetChanged();
            openMediaViewActivity(baseMessage);
        }
    });
    viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (!isLongClickEnabled && !isTextMessageClick) {
                isImageMessageClick = true;
                setLongClickSelectedItem(baseMessage);
                messageLongClick.setLongMessageClick(longselectedItemList);
                notifyItemChanged(i);
            }
            return true;
        }
    });
    viewHolder.reactionLayout.setVisibility(View.GONE);
    setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
Also used : AlertDialog(android.app.AlertDialog) MediaMessage(com.cometchat.pro.models.MediaMessage) DialogInterface(android.content.DialogInterface) JSONException(org.json.JSONException) Attachment(com.cometchat.pro.models.Attachment) 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) BaseMessage(com.cometchat.pro.models.BaseMessage) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction)

Example 27 with BaseMessage

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

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

the class MessageAdapter method setLocationData.

/**
 * This method is called whenever viewType of item is customMessage and customType is Location.
 * It is used to bind LocationMessageViewHolder
 * contents with CustomMessage at a given position.
 *
 * @param viewHolder is a object of LocationMessageViewHolder.
 * @param i is a position of item in recyclerView.
 * @see CustomMessage
 * @see BaseMessage
 */
private void setLocationData(LocationMessageViewHolder 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.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
        intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
        try {
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION);
            intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LATITUDE, ((CustomMessage) baseMessage).getCustomData().getDouble("latitude"));
            intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LONGITUDE, ((CustomMessage) baseMessage).getCustomData().getDouble("longitude"));
        } 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);
    });
    try {
        LATITUDE = ((CustomMessage) baseMessage).getCustomData().getDouble("latitude");
        LONGITUDE = ((CustomMessage) baseMessage).getCustomData().getDouble("longitude");
        viewHolder.tvAddress.setText(Utils.getAddress(context, LATITUDE, LONGITUDE));
        String mapUrl = UIKitConstants.MapUrl.MAPS_URL + LATITUDE + "," + LONGITUDE + "&key=" + UIKitConstants.MapUrl.MAP_ACCESS_KEY;
        Glide.with(context).load(mapUrl).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.default_map).into(viewHolder.ivMap);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    viewHolder.senderTxt.setText(String.format(context.getString(R.string.shared_location), baseMessage.getSender().getName()));
    viewHolder.ivMap.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                double latitude = ((CustomMessage) baseMessage).getCustomData().getDouble("latitude");
                double longitude = ((CustomMessage) baseMessage).getCustomData().getDouble("longitude");
                ;
                String label = Utils.getAddress(context, latitude, longitude);
                String uriBegin = "geo:" + latitude + "," + longitude;
                String query = label;
                String encodedQuery = Uri.encode(query);
                String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
                Uri uri = Uri.parse(uriString);
                Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
                // mapIntent.setPackage("com.google.android.apps.maps");
                context.startActivity(mapIntent);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    showMessageTime(viewHolder, baseMessage);
    setColorFilter(baseMessage, viewHolder.cvMessageView);
    // 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);
    viewHolder.rlMessageBubble.setOnClickListener(view -> {
        if (isLongClickEnabled && !isImageMessageClick) {
            setLongClickSelectedItem(baseMessage);
            messageLongClick.setLongMessageClick(longselectedItemList);
        } else {
            setSelectedMessage(baseMessage.getId());
        }
        notifyItemChanged(i);
    });
    viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            if (!isImageMessageClick && !isTextMessageClick) {
                isLongClickEnabled = true;
                isLocationMessageClick = true;
                setLongClickSelectedItem(baseMessage);
                messageLongClick.setLongMessageClick(longselectedItemList);
                notifyItemChanged(i);
            }
            return true;
        }
    });
    viewHolder.reactionLayout.setVisibility(View.GONE);
    setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
Also used : JSONException(org.json.JSONException) 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) Uri(android.net.Uri) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) BaseMessage(com.cometchat.pro.models.BaseMessage) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) CustomMessage(com.cometchat.pro.models.CustomMessage)

Example 29 with BaseMessage

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

the class MessageAdapter method setFileData.

/**
 * This method is called whenever viewType of item is file. It is used to bind FileMessageViewHolder
 * contents with MediaMessage at a given position.
 * It shows FileName, FileType, FileSize.
 *
 * @param viewHolder is a object of FileMessageViewHolder.
 * @param i is a position of item in recyclerView.
 * @see MediaMessage
 * @see BaseMessage
 */
private void setFileData(FileMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (baseMessage != null && baseMessage.getDeletedAt() == 0) {
        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());
            }
        }
        if (((MediaMessage) baseMessage).getAttachment() != null) {
            viewHolder.fileName.setText(((MediaMessage) baseMessage).getAttachment().getFileName());
            viewHolder.fileExt.setText(((MediaMessage) baseMessage).getAttachment().getFileExtension());
            int fileSize = ((MediaMessage) baseMessage).getAttachment().getFileSize();
            viewHolder.fileSize.setText(Utils.getFileSize(fileSize));
        } else {
            viewHolder.fileName.setText(context.getString(R.string.uploading));
            viewHolder.fileExt.setText("-");
            viewHolder.fileSize.setText("-");
        }
        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.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
            intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
            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);
        });
        showMessageTime(viewHolder, baseMessage);
        setColorFilter(baseMessage, viewHolder.cvMessageView);
        // if (selectedItemList.contains(baseMessage.getId()))
        viewHolder.txtTime.setVisibility(View.VISIBLE);
        // else
        // viewHolder.txtTime.setVisibility(View.GONE);
        viewHolder.rlMessageBubble.setOnClickListener(view -> {
            // if (isLongClickEnabled && !isTextMessageClick) {
            // setLongClickSelectedItem(baseMessage);
            // }
            // else {
            MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(), context);
            setSelectedMessage(baseMessage.getId());
            // }
            notifyItemChanged(i);
        });
        viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                if (!isLongClickEnabled && !isTextMessageClick) {
                    isImageMessageClick = true;
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                    notifyItemChanged(i);
                }
                return true;
            }
        });
    }
    viewHolder.reactionLayout.setVisibility(View.GONE);
    setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) 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)

Example 30 with BaseMessage

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

the class MessageAdapter method setWhiteBoardData.

private void setWhiteBoardData(WhiteBoardViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (baseMessage != null) {
        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());
            }
            viewHolder.whiteBoardMessage.setText(baseMessage.getSender().getName() + " " + context.getString(R.string.has_shared_whiteboard));
        } else {
            viewHolder.whiteBoardMessage.setText(context.getString(R.string.you_created_whiteboard));
        }
        JSONObject jsonObject = baseMessage.getMetadata();
        viewHolder.joinBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Extensions.openWhiteBoard(baseMessage, context);
            }
        });
        if (baseMessage.getReplyCount() != 0) {
            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(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.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
            intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage));
            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);
        });
        showMessageTime(viewHolder, baseMessage);
        viewHolder.txtTime.setVisibility(View.VISIBLE);
        setColorFilter(baseMessage, viewHolder.messageContainer);
        viewHolder.rlMessageBubble.setOnClickListener(view -> {
            if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
                if (isLongClickEnabled && !isImageMessageClick) {
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                } else {
                    setSelectedMessage(baseMessage.getId());
                }
                notifyItemChanged(i);
            }
        });
        viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                if (!isImageMessageClick && !isTextMessageClick) {
                    isLongClickEnabled = true;
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                    notifyItemChanged(i);
                }
                return true;
            }
        });
        setReactionSupport(baseMessage, viewHolder.reactionLayout);
    }
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) JSONObject(org.json.JSONObject) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView)

Aggregations

BaseMessage (com.cometchat.pro.models.BaseMessage)53 View (android.view.View)19 ImageView (android.widget.ImageView)19 TextView (android.widget.TextView)19 CardView (androidx.cardview.widget.CardView)19 RecyclerView (androidx.recyclerview.widget.RecyclerView)19 MaterialCardView (com.google.android.material.card.MaterialCardView)19 Intent (android.content.Intent)18 MediaMessage (com.cometchat.pro.models.MediaMessage)14 JSONException (org.json.JSONException)14 CometChatException (com.cometchat.pro.exceptions.CometChatException)11 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)11 JSONObject (org.json.JSONObject)10 TextMessage (com.cometchat.pro.models.TextMessage)8 User (com.cometchat.pro.models.User)7 AlertDialog (android.app.AlertDialog)6 DialogInterface (android.content.DialogInterface)6 CustomMessage (com.cometchat.pro.models.CustomMessage)5 Call (com.cometchat.pro.core.Call)4 Attachment (com.cometchat.pro.models.Attachment)4