Search in sources :

Example 6 with MediaMessage

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

the class CometChatThreadMessageList method sendMediaMessage.

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

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

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

Example 7 with MediaMessage

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

the class ThreadAdapter method openMediaViewActivity.

private void openMediaViewActivity(BaseMessage baseMessage) {
    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 8 with MediaMessage

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

the class ThreadAdapter 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) {
        setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
        viewHolder.tvUser.setText(baseMessage.getSender().getName());
        Attachment attachement = ((MediaMessage) baseMessage).getAttachment();
        if (attachement != null) {
            viewHolder.fileName.setText(attachement.getFileName());
            viewHolder.fileExt.setText(attachement.getFileExtension());
            int fileSize = attachement.getFileSize();
            viewHolder.fileSize.setText(Utils.getFileSize(fileSize));
        }
        showMessageTime(viewHolder, baseMessage);
        // 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 {
            setSelectedMessage(baseMessage.getId());
            // }
            notifyDataSetChanged();
        });
        viewHolder.fileName.setOnClickListener(view -> MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(), context));
        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 : MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) 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)

Example 9 with MediaMessage

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

the class ThreadAdapter method setVideoData.

private void setVideoData(VideoMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
    viewHolder.tvUser.setText(baseMessage.getSender().getName());
    if (((MediaMessage) baseMessage).getAttachment() != null)
        Glide.with(context).load(((MediaMessage) baseMessage).getAttachment().getFileUrl()).into(viewHolder.imageView);
    showMessageTime(viewHolder, baseMessage);
    // if (selectedItemList.contains(baseMessage.getId()))
    // viewHolder.txtTime.setVisibility(View.VISIBLE);
    // else
    // viewHolder.txtTime.setVisibility(View.GONE);
    // 
    viewHolder.rlMessageBubble.setOnClickListener(view -> {
        setSelectedMessage(baseMessage.getId());
        notifyDataSetChanged();
    });
    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.playBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(), context);
        }
    });
    viewHolder.reactionLayout.setVisibility(View.GONE);
    setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) 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 10 with MediaMessage

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

the class CometChatMessageList method sendMediaMessage.

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

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

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

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