Search in sources :

Example 1 with Attachment

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

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

use of com.cometchat.pro.models.Attachment 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)

Example 4 with Attachment

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

the class ThreadAdapter method setAudioData.

private void setAudioData(AudioMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (baseMessage != null && baseMessage.getDeletedAt() == 0) {
        viewHolder.playBtn.setImageTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.textColorWhite)));
        setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
        viewHolder.tvUser.setText(baseMessage.getSender().getName());
        showMessageTime(viewHolder, baseMessage);
        // if (selectedItemList.contains(baseMessage.getId()))
        // viewHolder.txtTime.setVisibility(View.VISIBLE);
        // else
        // viewHolder.txtTime.setVisibility(View.GONE);
        Attachment attachment = ((MediaMessage) baseMessage).getAttachment();
        if (attachment != null) {
            viewHolder.playBtn.setVisibility(View.VISIBLE);
            viewHolder.length.setText(Utils.getFileSize(((MediaMessage) baseMessage).getAttachment().getFileSize()));
        } 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) {
                // MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(),context);
                mediaPlayer.reset();
                if (messagePosition != i) {
                    notifyItemChanged(messagePosition);
                    messagePosition = i;
                }
                try {
                    mediaPlayer.setDataSource(((MediaMessage) baseMessage).getAttachment().getFileUrl());
                    mediaPlayer.prepare();
                    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                        @Override
                        public void onCompletion(MediaPlayer mp) {
                            viewHolder.playBtn.setImageResource(R.drawable.ic_play_arrow_black_24dp);
                        }
                    });
                } catch (Exception e) {
                    Log.e(TAG, "MediaPlayerError: " + e.getMessage());
                }
                if (!mediaPlayer.isPlaying()) {
                    mediaPlayer.start();
                    viewHolder.playBtn.setImageResource(R.drawable.ic_pause_24dp);
                } else {
                    mediaPlayer.pause();
                    viewHolder.playBtn.setImageResource(R.drawable.ic_play_arrow_black_24dp);
                }
            }
        });
        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) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) MediaPlayer(android.media.MediaPlayer)

Example 5 with Attachment

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

the class CometChatMessageList method setComposeBoxListener.

private void setComposeBoxListener() {
    composeBox.setComposeBoxListener(new ComposeActionListener() {

        @Override
        public void onEditTextMediaSelected(InputContentInfoCompat inputContentInfo) {
            Log.e(TAG, "onEditTextMediaSelected: Path=" + inputContentInfo.getLinkUri().getPath() + "\nHost=" + inputContentInfo.getLinkUri().getFragment());
            String messageType = inputContentInfo.getLinkUri().toString().substring(inputContentInfo.getLinkUri().toString().lastIndexOf('.'));
            MediaMessage mediaMessage = new MediaMessage(Id, null, CometChatConstants.MESSAGE_TYPE_IMAGE, type);
            Attachment attachment = new Attachment();
            attachment.setFileUrl(inputContentInfo.getLinkUri().toString());
            attachment.setFileMimeType(inputContentInfo.getDescription().getMimeType(0));
            attachment.setFileExtension(messageType);
            attachment.setFileName(inputContentInfo.getDescription().getLabel().toString());
            mediaMessage.setAttachment(attachment);
            Log.e(TAG, "onClick: " + attachment.toString());
            sendMediaMessage(mediaMessage);
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.length() > 0) {
                sendTypingIndicator(false);
            } else {
                sendTypingIndicator(true);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (!editable.toString().isEmpty()) {
                composeBox.hideSendButton(false);
                composeBox.hideRecordOption(true);
            } else {
                composeBox.hideSendButton(true);
                composeBox.hideRecordOption(false);
            }
            if (typingTimer == null) {
                typingTimer = new Timer();
            }
            endTypingTimer();
        }

        @Override
        public void onAudioActionClicked() {
            if (Utils.hasPermissions(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                startActivityForResult(MediaUtils.openAudio(getActivity()), UIKitConstants.RequestCode.AUDIO);
            } else {
                requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, UIKitConstants.RequestCode.AUDIO);
            }
        }

        @Override
        public void onCameraActionClicked() {
            if (Utils.hasPermissions(getContext(), CAMERA_PERMISSION)) {
                startActivityForResult(MediaUtils.openCamera(getContext()), UIKitConstants.RequestCode.CAMERA);
            } else {
                requestPermissions(CAMERA_PERMISSION, UIKitConstants.RequestCode.CAMERA);
            }
        }

        @Override
        public void onGalleryActionClicked() {
            if (Utils.hasPermissions(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                startActivityForResult(MediaUtils.openGallery(getActivity()), UIKitConstants.RequestCode.GALLERY);
            } else {
                requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, UIKitConstants.RequestCode.GALLERY);
            }
        }

        @Override
        public void onFileActionClicked() {
            if (Utils.hasPermissions(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                startActivityForResult(MediaUtils.getFileIntent(UIKitConstants.IntentStrings.EXTRA_MIME_DOC), UIKitConstants.RequestCode.FILE);
            } else {
                requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, UIKitConstants.RequestCode.FILE);
            }
        }

        @Override
        public void onSendActionClicked(EditText editText) {
            String message = editText.getText().toString().trim();
            String filterEmojiMessage = PatternUtils.removeEmojiAndSymbol(message);
            editText.setText("");
            editText.setHint(getString(R.string.message));
            FeatureRestriction.isEmojisEnabled(new FeatureRestriction.OnSuccessListener() {

                @Override
                public void onSuccess(Boolean booleanVal) {
                    if (!booleanVal) {
                        if (filterEmojiMessage.trim().length() > 0) {
                            if (isEdit) {
                                editMessage(baseMessage, message);
                                editMessageLayout.setVisibility(GONE);
                            } else if (isReply) {
                                replyMessage(baseMessage, message);
                                replyMessageLayout.setVisibility(GONE);
                            } else if (!message.isEmpty())
                                sendMessage(message);
                        } else {
                            Toast.makeText(getContext(), "Emoji Support is not enabled", Toast.LENGTH_LONG).show();
                        }
                    } else {
                        if (isEdit) {
                            editMessage(baseMessage, message);
                            editMessageLayout.setVisibility(GONE);
                        } else if (isReply) {
                            replyMessage(baseMessage, message);
                            replyMessageLayout.setVisibility(GONE);
                        } else if (!message.isEmpty())
                            sendMessage(message);
                    }
                }
            });
        }

        @Override
        public void onVoiceNoteComplete(String string) {
            if (string != null) {
                File audioFile = new File(string);
                sendMediaMessage(audioFile, CometChatConstants.MESSAGE_TYPE_AUDIO);
            }
        }

        @Override
        public void onLocationActionClicked() {
            if (Utils.hasPermissions(getContext(), Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)) {
                initLocation();
                // locationManager = (LocationManager) Objects.requireNonNull(getContext()).getSystemService(Context.LOCATION_SERVICE);
                boolean gpsprovider = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
                if (!gpsprovider) {
                    turnOnLocation();
                } else {
                    getLocation();
                }
            } else {
                requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }, UIKitConstants.RequestCode.LOCATION);
                if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
                    checkBackgroundLocationPermissionAPI30(UIKitConstants.RequestCode.LOCATION);
                }
            }
        }

        @Override
        public void onPollActionClicked() {
            createPollDialog();
        }

        @Override
        public void onStickerClicked() {
            stickerLayout.setVisibility(View.VISIBLE);
            Extensions.fetchStickers(new ExtensionResponseListener() {

                @Override
                public void OnResponseSuccess(Object var) {
                    JSONObject stickersJSON = (JSONObject) var;
                    stickersView.setData(Id, type, Extensions.extractStickersFromJSON(stickersJSON));
                }

                @Override
                public void OnResponseFailed(CometChatException e) {
                    CometChatSnackBar.show(context, stickersView, CometChatError.localized(e), CometChatSnackBar.ERROR);
                }
            });
        }

        @Override
        public void onWhiteboardClicked() {
            Extensions.callWhiteBoardExtension(Id, type, new ExtensionResponseListener() {

                @Override
                public void OnResponseSuccess(Object var) {
                    JSONObject jsonObject = (JSONObject) var;
                }

                @Override
                public void OnResponseFailed(CometChatException e) {
                    CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
                }
            });
        }

        @Override
        public void onWriteboardClicked() {
            Extensions.callWriteBoardExtension(Id, type, new ExtensionResponseListener() {

                @Override
                public void OnResponseSuccess(Object var) {
                    JSONObject jsonObject = (JSONObject) var;
                }

                @Override
                public void OnResponseFailed(CometChatException e) {
                    CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
                }
            });
        }
    });
}
Also used : EditText(android.widget.EditText) CometChatException(com.cometchat.pro.exceptions.CometChatException) MediaMessage(com.cometchat.pro.models.MediaMessage) Attachment(com.cometchat.pro.models.Attachment) ComposeActionListener(com.cometchat.pro.uikit.ui_components.shared.cometchatComposeBox.listener.ComposeActionListener) InputContentInfoCompat(androidx.core.view.inputmethod.InputContentInfoCompat) ExtensionResponseListener(com.cometchat.pro.uikit.ui_components.messages.extensions.ExtensionResponseListener) Timer(java.util.Timer) JSONObject(org.json.JSONObject) Editable(android.text.Editable) JSONObject(org.json.JSONObject) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) File(java.io.File)

Aggregations

Attachment (com.cometchat.pro.models.Attachment)6 MediaMessage (com.cometchat.pro.models.MediaMessage)6 View (android.view.View)5 ImageView (android.widget.ImageView)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 TextView (android.widget.TextView)4 CardView (androidx.cardview.widget.CardView)4 BaseMessage (com.cometchat.pro.models.BaseMessage)4 MaterialCardView (com.google.android.material.card.MaterialCardView)4 JSONException (org.json.JSONException)4 CometChatException (com.cometchat.pro.exceptions.CometChatException)3 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Editable (android.text.Editable)2 File (java.io.File)2 JSONObject (org.json.JSONObject)2 Drawable (android.graphics.drawable.Drawable)1 MediaPlayer (android.media.MediaPlayer)1 TextWatcher (android.text.TextWatcher)1