Search in sources :

Example 1 with ExtensionResponseListener

use of com.cometchat.pro.uikit.ui_components.messages.extensions.ExtensionResponseListener 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

Editable (android.text.Editable)1 EditText (android.widget.EditText)1 InputContentInfoCompat (androidx.core.view.inputmethod.InputContentInfoCompat)1 CometChatException (com.cometchat.pro.exceptions.CometChatException)1 Attachment (com.cometchat.pro.models.Attachment)1 MediaMessage (com.cometchat.pro.models.MediaMessage)1 ExtensionResponseListener (com.cometchat.pro.uikit.ui_components.messages.extensions.ExtensionResponseListener)1 ComposeActionListener (com.cometchat.pro.uikit.ui_components.shared.cometchatComposeBox.listener.ComposeActionListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 File (java.io.File)1 Timer (java.util.Timer)1 JSONObject (org.json.JSONObject)1