use of com.cometchat.pro.core.CometChat 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.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatGroupDetailActivity method banMember.
/**
* This method is used to ban group member from the group. It is used only if loggedIn user is admin.
*
* @see CometChat#banGroupMember(String, String, CometChat.CallbackListener)
*/
private void banMember() {
ProgressDialog progressDialog = ProgressDialog.show(CometChatGroupDetailActivity.this, null, groupMember.getName() + " " + getString(R.string.banned_successfully));
CometChat.banGroupMember(groupMember.getUid(), guid, new CometChat.CallbackListener<String>() {
@Override
public void onSuccess(String s) {
progressDialog.dismiss();
Log.e(TAG, "onSuccess: " + s);
tvMemberCount.setText((groupMemberCount - 1) + " " + getString(R.string.members));
// int count = Integer.parseInt(tvBanMemberCount.getText().toString());
// tvBanMemberCount.setText(String.valueOf(++count));
groupMemberUids.remove(groupMember.getUid());
groupMemberAdapter.removeGroupMember(groupMember);
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(CometChatGroupDetailActivity.this, rvMemberList, String.format(getResources().getString(R.string.cannot_remove_member), groupMember.getName()) + "," + CometChatError.localized(e), CometChatSnackBar.ERROR);
Log.e(TAG, "onError: " + e.getMessage());
}
});
}
use of com.cometchat.pro.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatGroupDetailActivity method kickMember.
/**
* This method is used to kick group member from the group. It is used only if loggedIn user is admin.
*
* @see CometChat#kickGroupMember(String, String, CometChat.CallbackListener)
*/
private void kickMember() {
ProgressDialog progressDialog = ProgressDialog.show(CometChatGroupDetailActivity.this, null, String.format(getString(R.string.user_removed_from_group), groupMember.getName(), gName));
CometChat.kickGroupMember(groupMember.getUid(), guid, new CometChat.CallbackListener<String>() {
@Override
public void onSuccess(String s) {
progressDialog.dismiss();
Log.e(TAG, "onSuccess: " + s);
tvMemberCount.setText((groupMemberCount - 1) + " " + getString(R.string.members));
groupMemberUids.remove(groupMember.getUid());
groupMemberAdapter.removeGroupMember(groupMember);
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(CometChatGroupDetailActivity.this, rvMemberList, String.format(getResources().getString(R.string.cannot_remove_member), groupMember.getName()) + "," + CometChatError.localized(e), CometChatSnackBar.ERROR);
Log.e(TAG, "onError: " + e.getMessage());
}
});
}
use of com.cometchat.pro.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.
the class CallUtils method initiateCall.
/**
* This method is used to initiate a call for user or a group.
* @param context is a object of Context
* @param recieverID is String - It can be either uid or guid
* @param receiverType is String - It can be either user or group
* [<code>CometChatConstants.RECEIVER_TYPE_USER</code> or
* <code>CometChatConstants.RECEIVER_TYPE_GROUP</code>]
* @param callType is String - It can be either audio or video
* [<code>CometChatConstants.CALL_TYPE_AUDIO</code> or
* <code>CometChatConstants.CALL_TYPE_VIDEO</code>]
*
* @see CometChat#initiateCall(Call, CometChat.CallbackListener)
*/
public static void initiateCall(Context context, String recieverID, String receiverType, String callType) {
Call call = new Call(recieverID, receiverType, callType);
CometChat.initiateCall(call, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER))
startCallIntent(context, ((User) call.getCallReceiver()), call.getType(), true, call.getSessionId());
else if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_GROUP))
startGroupCallIntent(context, ((Group) call.getCallReceiver()), call.getType(), true, call.getSessionId());
}
@Override
public void onError(CometChatException e) {
Log.e(TAG, "onError: " + e.getMessage());
Snackbar.make(((Activity) context).getWindow().getDecorView().getRootView(), context.getResources().getString(R.string.call_initiate_error) + ":" + e.getMessage(), Snackbar.LENGTH_LONG).show();
}
});
}
Aggregations