Search in sources :

Example 11 with MediaMessage

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

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

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

the class MessageAdapter method openMediaViewActivity.

private void openMediaViewActivity(BaseMessage baseMessage) {
    if (((MediaMessage) baseMessage).getAttachment() != null) {
        Intent intent = new Intent(context, CometChatMediaViewActivity.class);
        intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
        intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
        intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
        intent.putExtra(UIKitConstants.IntentStrings.INTENT_MEDIA_MESSAGE, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
        context.startActivity(intent);
    }
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) Intent(android.content.Intent)

Example 14 with MediaMessage

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

the class MessageAdapter method setAudioData.

/**
 * This method is called whenever viewType of item is file. It is used to bind AudioMessageViewHolder
 * contents with MediaMessage at a given position.
 *
 * @param viewHolder is a object of AudioMessageViewHolder.
 * @param i is a position of item in recyclerView.
 * @see MediaMessage
 * @see BaseMessage
 */
private void setAudioData(AudioMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (baseMessage != null && baseMessage.getDeletedAt() == 0) {
        if (!baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
            viewHolder.playBtn.setImageTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.textColorWhite)));
            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());
            }
        } else {
            viewHolder.playBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
        }
        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.rlMessageBubble);
        // if (selectedItemList.contains(baseMessage.getId()))
        viewHolder.txtTime.setVisibility(View.VISIBLE);
        // viewHolder.txtTime.setVisibility(View.GONE);
        if (((MediaMessage) baseMessage).getAttachment() != null) {
            viewHolder.length.setText(Utils.getFileSize(((MediaMessage) baseMessage).getAttachment().getFileSize()));
            viewHolder.playBtn.setVisibility(View.VISIBLE);
        } else {
            viewHolder.length.setText("-");
            viewHolder.playBtn.setVisibility(View.GONE);
        }
        viewHolder.playBtn.setImageResource(R.drawable.ic_play_arrow_black_24dp);
        viewHolder.playBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CometChatMediaViewActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.MEDIA_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, CometChatConstants.MESSAGE_TYPE_AUDIO);
                intent.putExtra(UIKitConstants.IntentStrings.INTENT_MEDIA_MESSAGE, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
                intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
                context.startActivity(intent);
            }
        });
        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) CometChatMediaViewActivity(com.cometchat.pro.uikit.ui_components.messages.media_view.CometChatMediaViewActivity) 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 15 with MediaMessage

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

the class ThreadAdapter 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);
    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);
    viewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_defaulf_image));
    Attachment attachment = ((MediaMessage) baseMessage).getAttachment();
    if (attachment != null) {
        if (smallUrl != null) {
            if (((MediaMessage) baseMessage).getAttachment().getFileExtension().equalsIgnoreCase(".gif")) {
                setImageDrawable(viewHolder, smallUrl, true, false);
            } else {
                setImageDrawable(viewHolder, smallUrl, false, isImageNotSafe);
            }
        } else {
            if (((MediaMessage) baseMessage).getAttachment().getFileExtension().equalsIgnoreCase(".gif"))
                setImageDrawable(viewHolder, ((MediaMessage) baseMessage).getAttachment().getFileUrl(), true, false);
            else
                setImageDrawable(viewHolder, ((MediaMessage) baseMessage).getAttachment().getFileUrl(), false, isImageNotSafe);
        }
    }
    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();
        }
    }
    if (isImageNotSafe) {
        viewHolder.sensitiveLayout.setVisibility(View.VISIBLE);
    } else {
        viewHolder.sensitiveLayout.setVisibility(View.GONE);
    }
    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);
                notifyDataSetChanged();
            }
            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) 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)

Aggregations

MediaMessage (com.cometchat.pro.models.MediaMessage)25 Intent (android.content.Intent)16 BaseMessage (com.cometchat.pro.models.BaseMessage)14 JSONException (org.json.JSONException)11 View (android.view.View)10 ImageView (android.widget.ImageView)10 RecyclerView (androidx.recyclerview.widget.RecyclerView)10 CometChatException (com.cometchat.pro.exceptions.CometChatException)10 TextView (android.widget.TextView)9 CardView (androidx.cardview.widget.CardView)9 MaterialCardView (com.google.android.material.card.MaterialCardView)9 JSONObject (org.json.JSONObject)8 Attachment (com.cometchat.pro.models.Attachment)6 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)6 TextMessage (com.cometchat.pro.models.TextMessage)5 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)3