use of com.cometchat.pro.models.CustomMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class PushNotificationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_push_notification);
if (!Utils.hasPermissions(this, permissions)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(permissions, UIKitConstants.RequestCode.RECORD);
}
}
progressDialog = new ProgressDialog(this);
progressDialog.setTitle(getResources().getString(R.string.please_wait));
progressDialog.setMessage(getResources().getString(R.string.media_uploading));
progressDialog.setCancelable(false);
moreBtn = findViewById(R.id.more_btn);
titleTv = findViewById(R.id.title_tv);
messageTv = findViewById(R.id.message_tv);
uid = findViewById(R.id.uid);
uidLayout = findViewById(R.id.uid_layout);
recieverType = findViewById(R.id.reciever_type);
user = findViewById(R.id.users);
group = findViewById(R.id.groups);
message = findViewById(R.id.message);
textMessage = findViewById(R.id.text_message);
mediaMessage = findViewById(R.id.media_message);
audioCall = findViewById(R.id.audio_call);
videoCall = findViewById(R.id.video_call);
customMessage = findViewById(R.id.custom_message);
recieverType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup g, int checkedId) {
if (user.isChecked()) {
uidLayout.setHint(getResources().getString(R.string.enter_uid));
receiver = CometChatConstants.RECEIVER_TYPE_USER;
}
if (group.isChecked()) {
uidLayout.setHint(getResources().getString(R.string.enter_guid));
receiver = CometChatConstants.RECEIVER_TYPE_GROUP;
}
}
});
moreBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MoreActionFragment moreActionFragment = new MoreActionFragment();
moreActionFragment.show(getSupportFragmentManager(), moreActionFragment.getTag());
}
});
textMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().trim().isEmpty()) {
uid.setError(getResources().getString(R.string.fill_this_field));
} else if (message.getText().toString().isEmpty()) {
message.setError(getResources().getString(R.string.fill_this_field));
} else {
// subscribePushNotification();
TextMessage textMessage = new TextMessage(uid.getText().toString(), message.getText().toString(), receiver);
sendMessage(textMessage);
message.setText("");
}
}
});
mediaMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty())
uid.setError(getResources().getString(R.string.fill_this_field));
else {
if (Utils.hasPermissions(PushNotificationActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE })) {
startActivityForResult(MediaUtils.openGallery(PushNotificationActivity.this), UIKitConstants.RequestCode.GALLERY);
} else {
requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, UIKitConstants.RequestCode.GALLERY);
}
}
}
});
customMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty())
uid.setError(getResources().getString(R.string.fill_this_field));
else {
try {
// subscribePushNotification();
JSONObject customData = new JSONObject();
customData.put("latitude", "19.0760");
customData.put("longitude", "72.8777");
CustomMessage customMessage = new CustomMessage(uid.getText().toString(), receiver, "location", customData);
JSONObject metaData = new JSONObject();
metaData.put("pushNotification", "You Received Custom Message");
customMessage.setMetadata(metaData);
sendMessage(customMessage);
} catch (Exception e) {
Log.e(TAG, "onClick: " + e.getMessage());
}
}
}
});
audioCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty()) {
uid.setError(getResources().getString(R.string.fill_this_field));
} else {
Call call = new Call(uid.getText().toString(), receiver, CometChatConstants.CALL_TYPE_AUDIO);
initiateCall(call);
}
}
});
videoCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty()) {
uid.setError(getResources().getString(R.string.fill_this_field));
} else {
Call call = new Call(uid.getText().toString(), receiver, CometChatConstants.CALL_TYPE_VIDEO);
initiateCall(call);
}
}
});
checkDarkMode();
}
use of com.cometchat.pro.models.CustomMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class MessageAdapter method setStickerData.
/**
* This method is called whenever viewType of item is sticker. It is used to bind StickerMessageViewHolder
* contents with CustomMessage at a given position.
* It loads image from url availabl in CustomMessage.
*
* @param viewHolder is a object of StickerMessageViewHolder.
* @param i is a position of item in recyclerView.
* @see CustomMessage
* @see BaseMessage
*/
private void setStickerData(StickerMessageViewHolder 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());
}
}
viewHolder.stickerView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_defaulf_image));
try {
Glide.with(context).load(((CustomMessage) baseMessage).getCustomData().getString("sticker_url")).into(viewHolder.stickerView);
} catch (JSONException e) {
e.printStackTrace();
}
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);
}
}
});
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, UIKitConstants.IntentStrings.STICKERS);
intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
try {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((CustomMessage) baseMessage).getCustomData().getString("name"));
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((CustomMessage) baseMessage).getCustomData().getString("url"));
} catch (JSONException e) {
e.printStackTrace();
}
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.stickerView.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);
}
use of com.cometchat.pro.models.CustomMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class MessageAdapter method setGroupCallMessageData.
private void setGroupCallMessageData(GroupCallMessageViewHolder viewHolder, int i) {
BaseMessage baseMessage = messageList.get(i);
if (baseMessage != null) {
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());
}
viewHolder.groupCallMessage.setText(baseMessage.getSender().getName() + " " + context.getString(R.string.has_shared_group_call));
} else {
viewHolder.groupCallMessage.setText(context.getString(R.string.you_created_group_call));
}
viewHolder.joinBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((CustomMessage) baseMessage).getCustomData() != null) {
if (CometChat.getActiveCall() == null)
CallUtils.startDirectCall(context, Utils.getDirectCallData(baseMessage));
else {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle(context.getResources().getString(R.string.ongoing_call)).setMessage(context.getResources().getString(R.string.ongoing_call_message)).setPositiveButton(context.getResources().getString(R.string.join), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
CallUtils.joinOnGoingCall(context, CometChat.getActiveCall());
}
}).setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
}
}
}
});
if (baseMessage.getReplyCount() != 0) {
viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE);
viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount() + " " + context.getResources().getString(R.string.replies));
} else {
viewHolder.tvThreadReplyCount.setVisibility(View.GONE);
}
viewHolder.tvThreadReplyCount.setOnClickListener(view -> {
Intent intent = new Intent(context, CometChatThreadMessageListActivity.class);
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.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage));
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
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);
viewHolder.txtTime.setVisibility(View.VISIBLE);
setColorFilter(baseMessage, viewHolder.messageContainer);
viewHolder.rlMessageBubble.setOnClickListener(view -> {
if (baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
if (isLongClickEnabled && !isImageMessageClick) {
setLongClickSelectedItem(baseMessage);
messageLongClick.setLongMessageClick(longselectedItemList);
} else {
setSelectedMessage(baseMessage.getId());
}
notifyItemChanged(i);
}
});
viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (!isImageMessageClick && !isTextMessageClick) {
isLongClickEnabled = true;
setLongClickSelectedItem(baseMessage);
messageLongClick.setLongMessageClick(longselectedItemList);
notifyItemChanged(i);
}
return true;
}
});
setReactionSupport(baseMessage, viewHolder.reactionLayout);
}
}
use of com.cometchat.pro.models.CustomMessage in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method startForwardMessageActivity.
private void startForwardMessageActivity() {
Intent intent = new Intent(getContext(), CometChatForwardMessageActivity.class);
if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_MESSAGE)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, CometChatConstants.CATEGORY_MESSAGE);
if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
intent.putExtra(CometChatConstants.MESSAGE_TYPE_TEXT, ((TextMessage) baseMessage).getText());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.MESSAGE_TYPE_TEXT);
} else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_AUDIO) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_VIDEO) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_FILE)) {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_MIME_TYPE, ((MediaMessage) baseMessage).getAttachment().getFileMimeType());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getType());
}
} else {
intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, CometChatConstants.CATEGORY_CUSTOM);
intent.putExtra(UIKitConstants.IntentStrings.TYPE, UIKitConstants.IntentStrings.LOCATION);
try {
intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LATITUDE, ((CustomMessage) baseMessage).getCustomData().getDouble("latitude"));
intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LONGITUDE, ((CustomMessage) baseMessage).getCustomData().getDouble("longitude"));
} catch (Exception e) {
Log.e(TAG, "startForwardMessageActivityError: " + e.getMessage());
}
}
startActivity(intent);
}
use of com.cometchat.pro.models.CustomMessage 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