use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class MessageAdapter method setReactionSupport.
private void setReactionSupport(BaseMessage baseMessage, ChipGroup reactionLayout) {
HashMap<String, String> reactionOnMessage = Extensions.getReactionsOnMessage(baseMessage);
if (reactionOnMessage != null && reactionOnMessage.size() > 0) {
reactionLayout.setVisibility(View.VISIBLE);
reactionLayout.removeAllViews();
for (String str : reactionOnMessage.keySet()) {
// if (reactionLayout.getChildCount()<reactionOnMessage.size()) {
Chip chip = new Chip(context);
chip.setChipStrokeWidth(2f);
chip.setChipBackgroundColor(ColorStateList.valueOf(context.getResources().getColor(android.R.color.transparent)));
chip.setChipStrokeColor(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
chip.setText(str + " " + reactionOnMessage.get(str));
reactionLayout.addView(chip);
chip.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
Intent intent = new Intent(context, CometChatReactionInfoActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, baseMessage.getMetadata().toString());
context.startActivity(intent);
return true;
}
});
chip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
JSONObject body = new JSONObject();
try {
body.put("msgId", baseMessage.getId());
body.put("emoji", str);
} catch (Exception e) {
e.printStackTrace();
}
CometChat.callExtension("reactions", "POST", "/v1/react", body, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject responseObject) {
// ReactionModel added successfully.
}
@Override
public void onError(CometChatException e) {
// Some error occured.
}
});
}
});
// }
}
}
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method showBottomSheet.
private void showBottomSheet(CometChatMessageActions messageActionFragment) {
messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {
@Override
public void onPrivateReplyToUser() {
if (baseMessage != null) {
User user = baseMessage.getSender();
Intent intent = new Intent(context, CometChatMessageListActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
startActivity(intent);
if (getActivity() != null)
getActivity().finish();
}
}
@Override
public void onThreadMessageClick() {
}
@Override
public void onEditMessageClick() {
if (isParent)
editParentMessage();
else
editThreadMessage();
}
@Override
public void onReplyMessageClick() {
}
@Override
public void onReplyMessagePrivately() {
}
@Override
public void onForwardMessageClick() {
if (isParent)
startForwardThreadActivity();
else
startForwardMessageActivity();
}
@Override
public void onDeleteMessageClick() {
deleteMessage(baseMessage);
if (messageAdapter != null) {
messageAdapter.clearLongClickSelectedItem();
messageAdapter.notifyDataSetChanged();
}
}
@Override
public void onCopyMessageClick() {
String copyMessage = "";
if (isParent) {
copyMessage = message;
isParent = true;
} else {
for (BaseMessage bMessage : baseMessages) {
if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
copyMessage = copyMessage + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
}
}
isParent = false;
}
Log.e(TAG, "onCopy: " + message);
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("ThreadMessageAdapter", copyMessage);
clipboardManager.setPrimaryClip(clipData);
Toast.makeText(context, getResources().getString(R.string.text_copied), Toast.LENGTH_LONG).show();
if (messageAdapter != null) {
messageAdapter.clearLongClickSelectedItem();
messageAdapter.notifyDataSetChanged();
}
}
@Override
public void onShareMessageClick() {
shareMessage();
}
@Override
public void onMessageInfoClick() {
Intent intent = new Intent(context, CometChatMessageInfoScreenActivity.class);
if (isParent) {
} else {
intent.putExtra(UIKitConstants.IntentStrings.ID, baseMessage.getId());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.checkProfanityMessage(context, baseMessage));
} else if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_CUSTOM)) {
if (((CustomMessage) baseMessage).getCustomData() != null)
intent.putExtra(UIKitConstants.IntentStrings.CUSTOM_MESSAGE, ((CustomMessage) baseMessage).getCustomData().toString());
if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION);
}
} else {
boolean isImageNotSafe = Extensions.getImageModeration(context, baseMessage);
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
intent.putExtra(UIKitConstants.IntentStrings.IMAGE_MODERATION, isImageNotSafe);
}
}
context.startActivity(intent);
}
@Override
public void onReactionClick(Reaction reaction) {
if (reaction.getName().equals("add_emoji")) {
CometChatReactionDialog reactionDialog = new CometChatReactionDialog();
reactionDialog.setOnEmojiClick(new OnReactionClickListener() {
@Override
public void onEmojiClicked(Reaction emojicon) {
sendReaction(emojicon);
reactionDialog.dismiss();
}
});
reactionDialog.show(getFragmentManager(), "ReactionDialog");
} else {
sendReaction(reaction);
}
}
@Override
public void onTranslateMessageClick() {
try {
String localeLanguage = Locale.getDefault().getLanguage();
JSONObject body = new JSONObject();
JSONArray languages = new JSONArray();
languages.put(localeLanguage);
if (isParent) {
body.put("msgId", parentId);
body.put("text", textMessage.getText().toString());
} else {
body.put("msgId", baseMessage.getId());
body.put("text", ((TextMessage) baseMessage).getText());
}
body.put("languages", languages);
CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject jsonObject) {
if (isParent) {
if (Extensions.isMessageTranslated(jsonObject, textMessage.getText().toString())) {
String translatedMessage = Extensions.getTextFromTranslatedMessage(jsonObject, textMessage.getText().toString());
textMessage.setText(translatedMessage);
} else {
CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
}
} else {
if (Extensions.isMessageTranslated(jsonObject, ((TextMessage) baseMessage).getText())) {
if (baseMessage.getMetadata() != null) {
JSONObject meta = baseMessage.getMetadata();
try {
meta.accumulate("values", jsonObject);
baseMessage.setMetadata(meta);
updateMessage(baseMessage);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
baseMessage.setMetadata(jsonObject);
updateMessage(baseMessage);
}
} else {
CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
}
}
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "message-translation"), CometChatSnackBar.ERROR);
}
});
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onRetryClick() {
}
});
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList 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);
textMessage.setParentMessageId(parentId);
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();
}
noReplyMessages.setVisibility(GONE);
isSmartReplyClicked = false;
CometChat.sendMessage(textMessage, new CometChat.CallbackListener<TextMessage>() {
@Override
public void onSuccess(TextMessage textMessage) {
if (messageAdapter != null) {
setReply();
messageAdapter.updateChangedMessage(textMessage);
}
}
@Override
public void onError(CometChatException e) {
if (messageAdapter != null) {
textMessage.setSentAt(-1);
messageAdapter.updateChangedMessage(textMessage);
}
if (getActivity() != null) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
Log.d(TAG, "onError: " + e.getMessage());
}
});
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method sendReaction.
private void sendReaction(Reaction reaction) {
JSONObject body = new JSONObject();
try {
body.put("msgId", baseMessage.getId());
body.put("emoji", reaction.getName());
} catch (JSONException e) {
e.printStackTrace();
}
CometChat.callExtension("reactions", "POST", "/v1/react", body, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject responseObject) {
Log.e(TAG, "onSuccess: " + responseObject.toString());
// ReactionModel added successfully.
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "reactions"), CometChatSnackBar.ERROR);
Log.e(TAG, "onError: " + e.getCode() + e.getMessage() + e.getDetails());
}
});
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method sendCustomMessage.
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);
customMessage.setParentMessageId(parentId);
CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener<CustomMessage>() {
@Override
public void onSuccess(CustomMessage customMessage) {
noReplyMessages.setVisibility(GONE);
if (messageAdapter != null) {
messageAdapter.addMessage(customMessage);
setReply();
scrollToBottom();
}
}
@Override
public void onError(CometChatException e) {
if (getActivity() != null) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
}
});
}
Aggregations