Search in sources :

Example 1 with Call

use of com.cometchat.pro.core.Call 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();
}
Also used : Call(com.cometchat.pro.core.Call) RadioGroup(android.widget.RadioGroup) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONObject(org.json.JSONObject) CustomMessage(com.cometchat.pro.models.CustomMessage) TextMessage(com.cometchat.pro.models.TextMessage)

Example 2 with Call

use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.

the class MissedCall method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_cometchat_missed_call, container, false);
    rvCallList = view.findViewById(R.id.callList_rv);
    CometChatError.init(getContext());
    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.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
                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_OWNER, group.getOwner());
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, group.getGroupType());
                intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, group.getMembersCount());
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD, group.getPassword());
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, group.getDescription());
                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 3 with Call

use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatStartCallActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    setContentView(R.layout.activity_cometchat_start_call);
    ongoingCallService = new OngoingCallService();
    mServiceIntent = new Intent(this, ongoingCallService.getClass());
    isDefaultCall = getIntent().getBooleanExtra(UIKitConstants.IntentStrings.IS_DEFAULT_CALL, false);
    if (isDefaultCall && !isMyServiceRunning(ongoingCallService.getClass())) {
        startService(mServiceIntent);
    }
    mainView = findViewById(R.id.call_view);
    connectingLayout = findViewById(R.id.connecting_to_call);
    sessionID = getIntent().getStringExtra(UIKitConstants.IntentStrings.SESSION_ID);
    type = getIntent().getStringExtra(UIKitConstants.IntentStrings.TYPE);
    if (type != null && type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).setMode(CallSettings.MODE_SINGLE).build();
    else
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).build();
    CometChatError.init(this);
    Log.e("startCallActivity: ", sessionID + " " + type);
    CometChat.startCall(callSettings, new CometChat.OngoingCallListener() {

        @Override
        public void onUserListUpdated(List<User> list) {
            Log.e("onUserListUpdated: ", list.toString());
        }

        @Override
        public void onAudioModesUpdated(List<AudioMode> list) {
            Log.e("onAudioModesUpdated: ", list.toString());
        }

        @Override
        public void onUserJoined(User user) {
            connectingLayout.setVisibility(View.GONE);
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_joined) + ":" + user.getName(), CometChatSnackBar.INFO);
            Log.e("onUserJoined: ", user.getUid());
        }

        @Override
        public void onUserLeft(User user) {
            if (user != null) {
                CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_left) + ":" + user.getName(), CometChatSnackBar.INFO);
                Log.e("onUserLeft: ", user.getUid());
                if (callSettings.getMode().equals(CallSettings.MODE_SINGLE)) {
                    endCall();
                }
            } else {
                Log.e("onUserLeft: ", "triggered");
            }
        }

        @Override
        public void onError(CometChatException e) {
            stopService(mServiceIntent);
            Log.e("onstartcallError: ", e.getMessage());
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }

        @Override
        public void onCallEnded(Call call) {
            stopService(mServiceIntent);
            Log.e("TAG", "onCallEnded: ");
            finish();
        }
    });
}
Also used : OngoingCallService(com.cometchat.pro.uikit.ui_components.calls.call_manager.ongoing_call.OngoingCallService) CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) Intent(android.content.Intent) CallSettings(com.cometchat.pro.core.CallSettings) AudioMode(com.cometchat.pro.models.AudioMode)

Example 4 with Call

use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.

the class CallHistoryAdapter 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;
    boolean isIncoming = false, isVideo = false, isMissed = false;
    String callMessageText = "";
    if (call.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
        if (call.getSender().getUid().equals(loggedInUser)) {
            if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.missed_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.missed_voice_call);
                    isVideo = false;
                }
                isMissed = true;
            } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.rejected_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.rejected_voice_call);
                    isVideo = false;
                }
            } else {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.outgoing_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.outgoing_voice_call);
                    isVideo = false;
                }
            }
            isIncoming = false;
        } else {
            if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.missed_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.missed_voice_call);
                    isVideo = false;
                }
                isMissed = true;
            } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.rejected_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.rejected_voice_call);
                    isVideo = false;
                }
            } else {
                if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
                    callMessageText = context.getResources().getString(R.string.incoming_video_call);
                    isVideo = true;
                } else {
                    callMessageText = context.getResources().getString(R.string.incoming_audio_call);
                    isVideo = false;
                }
            }
            isIncoming = true;
        }
    }
    // }
    if (isVideo) {
        if (isIncoming) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_video_call, 0, 0, 0);
        } else {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_video_call, 0, 0, 0);
        }
    } else {
        if (isIncoming && isMissed) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_incoming_24dp, 0, 0, 0);
        } else if (isIncoming && !isMissed) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_call, 0, 0, 0);
        } else if (!isIncoming && isMissed) {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_outgoing_24dp, 0, 0, 0);
        } else {
            callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_call, 0, 0, 0);
        }
    }
    callViewHolder.callHistoryRowBinding.callTimeTv.setText(Utils.getHeaderDate(call.getInitiatedAt() * 1000));
    callViewHolder.callHistoryRowBinding.callInfoTv.setText(callMessageText);
    callViewHolder.callHistoryRowBinding.callDateTv.setText(Utils.getCallDate(call.getSentAt() * 1000));
    callViewHolder.callHistoryRowBinding.getRoot().setTag(R.string.call, call);
}
Also used : Call(com.cometchat.pro.core.Call) BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 5 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("Answer_")) {
        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, sessionID);
                acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                acceptIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                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(UIKitConstants.Notification.ID);
    } 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(UIKitConstants.Notification.ID);
                if (CometChatCallActivity.callActivity != null)
                    CometChatCallActivity.callActivity.finish();
            }

            @Override
            public void onError(CometChatException e) {
                Toast.makeText(context, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
            }
        });
    } else if (intent.getAction().equals("StartCall")) {
        Log.e(TAG, "onReceive: StartCall");
        Intent acceptIntent = new Intent(context, CometChatStartCallActivity.class);
        acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, sessionID);
        acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        acceptIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(acceptIntent);
    }
}
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