Search in sources :

Example 11 with Call

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);
            }
        });
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) DialogInterface(android.content.DialogInterface) CometChat(com.cometchat.pro.core.CometChat)

Example 12 with Call

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();
}
Also used : Call(com.cometchat.pro.core.Call)

Example 13 with Call

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())));
}
Also used : Call(com.cometchat.pro.core.Call) Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup) User(com.cometchat.pro.models.User) BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 14 with Call

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;
}
Also used : Call(com.cometchat.pro.core.Call) Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup) User(com.cometchat.pro.models.User) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CometChatGroupDetailActivity(com.cometchat.pro.uikit.ui_components.groups.group_details.CometChatGroupDetailActivity) RecyclerView(androidx.recyclerview.widget.RecyclerView) CometChatUserDetailScreenActivity(com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity)

Example 15 with Call

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();
            }
        });
    }
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) CometChat(com.cometchat.pro.core.CometChat) CometChatStartCallActivity(com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Intent(android.content.Intent)

Aggregations

Call (com.cometchat.pro.core.Call)19 CometChatException (com.cometchat.pro.exceptions.CometChatException)6 User (com.cometchat.pro.models.User)6 Intent (android.content.Intent)5 View (android.view.View)5 CometChat (com.cometchat.pro.core.CometChat)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 BaseMessage (com.cometchat.pro.models.BaseMessage)4 ViewGroup (android.view.ViewGroup)3 Group (com.cometchat.pro.models.Group)3 JSONObject (org.json.JSONObject)3 Bundle (android.os.Bundle)2 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 CustomMessage (com.cometchat.pro.models.CustomMessage)2 CometChatStartCallActivity (com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity)2 CometChatGroupDetailActivity (com.cometchat.pro.uikit.ui_components.groups.group_details.CometChatGroupDetailActivity)2 CometChatUserDetailScreenActivity (com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity)2 OnItemClickListener (com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener)2 ClickListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)2