use of com.cometchat.pro.core.Call 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.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatCallsAdapter method update.
/**
* This method is used to update call in callList.
*
* @param call is an object of Call. It is used to update the previous call
* in list
* @see Call
*/
public void update(Call call) {
if (callList.contains(call)) {
Call oldCall = (Call) callList.get(callList.indexOf(call));
callList.remove(oldCall);
callList.add(0, call);
} else {
callList.add(0, call);
}
notifyDataSetChanged();
}
use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatCallsAdapter method onBindViewHolder.
/**
* This method is used to bind the ConversationViewHolder contents with conversation at given
* position. It set avatar, name, lastMessage, unreadMessageCount and messageTime of conversation
* in a respective ConversationViewHolder content. It checks whether conversation type is user
* or group and set name and avatar as accordingly. It also checks whether last message is text, media
* or file and modify txtUserMessage view accordingly.
*
* @param callViewHolder is a object of ConversationViewHolder.
* @param position is a position of item in recyclerView.
*
* @see Conversation
*/
@Override
public void onBindViewHolder(@NonNull CallViewHolder callViewHolder, int position) {
BaseMessage baseMessage = callList.get(position);
Call call = (Call) baseMessage;
String avatar;
String uid;
String type;
boolean isIncoming, isVideo, isMissed = false;
String name;
String callMessageText;
String callType;
String callCategory;
if (call.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
String callName = ((User) call.getCallReceiver()).getName();
callViewHolder.callListRowBinding.callSenderName.setText(callName);
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar(((User) call.getCallReceiver()).getAvatar());
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED) || call.getCallStatus().equals(CometChatConstants.CALL_STATUS_CANCELLED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.outgoing);
uid = ((User) call.getCallReceiver()).getUid();
isIncoming = false;
} else {
String callName = ((User) call.getCallInitiator()).getName();
callViewHolder.callListRowBinding.callSenderName.setText(callName);
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar((User) call.getCallInitiator());
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED) || call.getCallStatus().equals(CometChatConstants.CALL_STATUS_CANCELLED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.incoming);
uid = call.getSender().getUid();
isIncoming = true;
}
type = CometChatConstants.RECEIVER_TYPE_USER;
} else {
callViewHolder.callListRowBinding.callSenderName.setText(((Group) call.getCallReceiver()).getName());
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar(((Group) call.getCallReceiver()));
if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.incoming);
isIncoming = false;
} else {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.incoming);
isIncoming = true;
}
uid = ((Group) call.getCallReceiver()).getGuid();
type = CometChatConstants.RECEIVER_TYPE_GROUP;
}
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = callMessageText + " " + context.getResources().getString(R.string.video_call);
isVideo = true;
} else {
callMessageText = callMessageText + " " + context.getResources().getString(R.string.audio_call);
isVideo = false;
}
if (isVideo) {
if (isIncoming) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_video_call, 0, 0, 0);
} else {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_video_call, 0, 0, 0);
}
} else {
if (isIncoming && isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_incoming_24dp, 0, 0, 0);
} else if (isIncoming && !isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_call, 0, 0, 0);
} else if (!isIncoming && isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_outgoing_24dp, 0, 0, 0);
} else {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_call, 0, 0, 0);
}
}
callViewHolder.callListRowBinding.calltimeTv.setText(Utils.getLastMessageDate(context, call.getInitiatedAt()));
callViewHolder.callListRowBinding.callMessage.setText(callMessageText);
callViewHolder.callListRowBinding.getRoot().setTag(R.string.call, call);
if (call.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER)) {
// if(FeatureRestriction.isOneOnOneAudioCallEnabled() ||
// FeatureRestriction.isOneOnOneVideoCallEnabled())
callViewHolder.callListRowBinding.callIv.setVisibility(View.VISIBLE);
// else
// callViewHolder.callListRowBinding.callIv.setVisibility(View.GONE);
}
callViewHolder.callListRowBinding.callIv.setImageTintList(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
}
use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class AllCall method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_cometchat_all_call, container, false);
fetchSettings();
CometChatError.init(getContext());
rvCallList = view.findViewById(R.id.callList_rv);
linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
rvCallList.setLayoutManager(linearLayoutManager);
noCallView = view.findViewById(R.id.no_call_vw);
rvCallList.setItemClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
if (var.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
User user;
if (((User) var.getCallInitiator()).getUid().equals(CometChat.getLoggedInUser().getUid())) {
user = ((User) var.getCallReceiver());
} else {
user = (User) var.getCallInitiator();
}
Intent intent = new Intent(getContext(), CometChatUserDetailScreenActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.IS_BLOCKED_BY_ME, user.isBlockedByMe());
intent.putExtra(UIKitConstants.IntentStrings.FROM_CALL_LIST, true);
startActivity(intent);
} else {
Group group;
group = ((Group) var.getCallReceiver());
Intent intent = new Intent(getContext(), CometChatGroupDetailActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.GUID, group.getGuid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, group.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, group.getIcon());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_SCOPE, group.getScope());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, group.getGroupType());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, group.getOwner());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, group.getDescription());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD, group.getPassword());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, group.getMembersCount());
startActivity(intent);
}
}
});
rvCallList.setItemCallClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
checkOnGoingCall(var);
}
});
rvCallList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (!rvCallList.canScrollVertically(1)) {
getCallList();
}
}
});
return view;
}
use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class CallNotificationAction method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
String sessionID = intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID);
Log.e(TAG, "onReceive: " + intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID));
if (intent.getAction().equals("Answers")) {
CometChat.acceptCall(sessionID, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
Intent acceptIntent = new Intent(context, CometChatStartCallActivity.class);
acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, call.getSessionId());
acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(acceptIntent);
}
@Override
public void onError(CometChatException e) {
Toast.makeText(context, "Error " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(05);
} else if (intent.getAction().equals("Decline")) {
CometChat.rejectCall(sessionID, CometChatConstants.CALL_STATUS_REJECTED, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(05);
if (CometChatCallActivity.callActivity != null)
CometChatCallActivity.callActivity.finish();
}
@Override
public void onError(CometChatException e) {
Toast.makeText(context, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
Aggregations