use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageList method checkOnGoingCall.
private void checkOnGoingCall(String callType) {
if (CometChat.getActiveCall() != null && CometChat.getActiveCall().getCallStatus().equals(CometChatConstants.CALL_STATUS_ONGOING) && CometChat.getActiveCall().getSessionId() != null) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle(getResources().getString(R.string.ongoing_call)).setMessage(getResources().getString(R.string.ongoing_call_message)).setPositiveButton(getResources().getString(R.string.join), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
CallUtils.joinOnGoingCall(context, CometChat.getActiveCall());
}
}).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
audioCallAction.setClickable(true);
videoCallAction.setClickable(true);
}
}).create().show();
} else {
Call call = null;
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP))
call = new Call(Id, CometChatConstants.RECEIVER_TYPE_GROUP, callType);
else
call = new Call(Id, CometChatConstants.RECEIVER_TYPE_USER, callType);
CometChat.initiateCall(call, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
CallUtils.startCallIntent(context, ((User) call.getCallReceiver()), call.getType(), true, call.getSessionId());
}
@Override
public void onError(CometChatException e) {
audioCallAction.setClickable(true);
videoCallAction.setClickable(true);
Log.e(TAG, "onError: " + e.getMessage());
CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
});
}
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageList method replyMessage.
/**
* This method is used to send reply message by link previous message with new message.
* @param baseMessage is a linked message
* @param message is a String. It will be new message sent as reply.
*/
private void replyMessage(BaseMessage baseMessage, String message) {
isReply = false;
try {
TextMessage textMessage;
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
textMessage = new TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_USER);
else
textMessage = new TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_GROUP);
JSONObject replyObject = new JSONObject();
replyObject.put("reply-message", baseMessage.getRawMessage());
textMessage.setMetadata(replyObject);
sendTypingIndicator(true);
textMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
textMessage.setSender(loggedInUser);
textMessage.setMuid(System.currentTimeMillis() + "");
if (messageAdapter != null) {
MediaUtils.playSendSound(context, R.raw.outgoing_message);
messageAdapter.addMessage(textMessage);
scrollToBottom();
}
isSmartReplyClicked = false;
rvSmartReply.setVisibility(GONE);
CometChat.sendMessage(textMessage, new CometChat.CallbackListener<TextMessage>() {
@Override
public void onSuccess(TextMessage textMessage) {
if (messageAdapter != null) {
MediaUtils.playSendSound(context, R.raw.outgoing_message);
messageAdapter.updateChangedMessage(textMessage);
scrollToBottom();
}
}
@Override
public void onError(CometChatException e) {
if (e.getCode().equalsIgnoreCase("ERROR_INTERNET_UNAVAILABLE")) {
CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_internet_available), CometChatSnackBar.ERROR);
} else if (!e.getCode().equalsIgnoreCase("ERR_BLOCKED_BY_EXTENSION")) {
if (messageAdapter == null) {
Log.e(TAG, "onError: MessageAdapter is null");
} else {
textMessage.setSentAt(-1);
messageAdapter.updateChangedMessage(textMessage);
}
} else if (messageAdapter != null) {
messageAdapter.remove(textMessage);
}
}
});
} catch (Exception e) {
Log.e(TAG, "replyMessage: " + e.getMessage());
}
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageList method sendMessage.
/**
* This method is used to send Text Message to other users and groups.
*
* @param message is a String which is been sent as message.
* @see TextMessage
* @see CometChat#sendMessage(TextMessage, CometChat.CallbackListener)
*/
private void sendMessage(String message) {
TextMessage textMessage;
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
textMessage = new TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_USER);
else
textMessage = new TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_GROUP);
sendTypingIndicator(true);
Log.e(TAG, "sendMessage: " + textMessage);
textMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
textMessage.setSender(loggedInUser);
textMessage.setMuid(System.currentTimeMillis() + "");
if (messageAdapter != null) {
MediaUtils.playSendSound(context, R.raw.outgoing_message);
messageAdapter.addMessage(textMessage);
scrollToBottom();
}
isSmartReplyClicked = false;
rvSmartReply.setVisibility(GONE);
CometChat.sendMessage(textMessage, new CometChat.CallbackListener<TextMessage>() {
@Override
public void onSuccess(TextMessage textMessage) {
if (messageAdapter != null)
messageAdapter.updateChangedMessage(textMessage);
}
@Override
public void onError(CometChatException e) {
if (e.getCode().equalsIgnoreCase("ERROR_INTERNET_UNAVAILABLE")) {
CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_internet_available), CometChatSnackBar.ERROR);
} else if (!e.getCode().equalsIgnoreCase("ERR_BLOCKED_BY_EXTENSION")) {
if (messageAdapter == null) {
Log.e(TAG, "onError: MessageAdapter is null");
} else {
e.printStackTrace();
textMessage.setSentAt(-1);
messageAdapter.updateChangedMessage(textMessage);
}
} else if (messageAdapter != null) {
messageAdapter.remove(textMessage);
}
}
});
}
use of com.cometchat.pro.exceptions.CometChatException 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);
}
});
}
});
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageList method sendCustomMessage.
/**
* This method sends custom message based on parameter received
* @param customType
* @param customData
*/
private void sendCustomMessage(String customType, JSONObject customData) {
CustomMessage customMessage;
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
customMessage = new CustomMessage(Id, CometChatConstants.RECEIVER_TYPE_USER, customType, customData);
else
customMessage = new CustomMessage(Id, CometChatConstants.RECEIVER_TYPE_GROUP, customType, customData);
String pushNotificationMessage = "";
if (customType.equalsIgnoreCase(UIKitConstants.IntentStrings.LOCATION))
pushNotificationMessage = getString(R.string.shared_location);
else if (customType.equalsIgnoreCase(UIKitConstants.IntentStrings.STICKERS))
pushNotificationMessage = getString(R.string.shared_a_sticker);
try {
JSONObject jsonObject = customMessage.getMetadata();
if (jsonObject == null) {
jsonObject = new JSONObject();
jsonObject.put("incrementUnreadCount", true);
jsonObject.put("pushNotification", pushNotificationMessage);
} else {
jsonObject.accumulate("incrementUnreadCount", true);
}
customMessage.setMetadata(jsonObject);
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener<CustomMessage>() {
@Override
public void onSuccess(CustomMessage customMessage) {
Log.e(TAG, "onSuccessCustomMesage: " + customMessage.toString());
if (customType.equalsIgnoreCase(UIKitConstants.IntentStrings.GROUP_CALL)) {
rvSmartReply.setVisibility(GONE);
if (CometChat.getActiveCall() == null)
CallUtils.startDirectCall(context, Utils.getDirectCallData(customMessage));
}
if (messageAdapter != null) {
messageAdapter.addMessage(customMessage);
scrollToBottom();
}
}
@Override
public void onError(CometChatException e) {
if (getActivity() != null) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
Aggregations