Search in sources :

Example 51 with CometChatException

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

the class CometChatUserDetailScreenActivity method kickGroupMember.

private void kickGroupMember() {
    ProgressDialog progressDialog = ProgressDialog.show(this, null, String.format(getResources().getString(R.string.user_removed_from_group), userName.getText().toString(), groupName));
    CometChat.kickGroupMember(uid, guid, new CometChat.CallbackListener<String>() {

        @Override
        public void onSuccess(String s) {
            progressDialog.dismiss();
            addBtn.setText(String.format(getResources().getString(R.string.add_in), groupName));
            addBtn.setVisibility(View.VISIBLE);
            isAlreadyAdded = false;
        }

        @Override
        public void onError(CometChatException e) {
            progressDialog.dismiss();
            if (tvBlockUser != null)
                CometChatSnackBar.show(CometChatUserDetailScreenActivity.this, tvBlockUser, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) CometChat(com.cometchat.pro.core.CometChat) ProgressDialog(android.app.ProgressDialog)

Example 52 with CometChatException

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

the class CometChatUserDetailScreenActivity method addMember.

private void addMember() {
    ProgressDialog progressDialog = ProgressDialog.show(this, null, String.format(getResources().getString(R.string.user_added_to_group), userName.getText().toString(), groupName));
    List<GroupMember> userList = new ArrayList<>();
    userList.add(new GroupMember(uid, CometChatConstants.SCOPE_PARTICIPANT));
    CometChat.addMembersToGroup(guid, userList, null, new CometChat.CallbackListener<HashMap<String, String>>() {

        @Override
        public void onSuccess(HashMap<String, String> stringStringHashMap) {
            Log.e(TAG, "onSuccess: " + uid + "Group" + guid);
            progressDialog.dismiss();
            // if(tvBlockUser!=null) {
            // CometChatSnackBar.show(CometChatUserDetailScreenActivity.this,
            // tvBlockUser, String.format(getResources().getString(R.string.user_added_to_group), userName.getText().toString(), groupName),
            // CometChatSnackBar.SUCCESS);
            // }
            addBtn.setText(String.format(getResources().getString(R.string.remove_from_group), groupName));
            isAlreadyAdded = true;
        }

        @Override
        public void onError(CometChatException e) {
            progressDialog.dismiss();
            CometChatSnackBar.show(CometChatUserDetailScreenActivity.this, historyRv, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) GroupMember(com.cometchat.pro.models.GroupMember) HashMap(java.util.HashMap) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) ProgressDialog(android.app.ProgressDialog)

Example 53 with CometChatException

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

the class CometChatUserList method searchUser.

/**
 * This method is used to search users present in your App_ID.
 * For more detail please visit our official documentation {@link "https://prodocs.cometchat.com/docs/android-users-retrieve-users#section-retrieve-list-of-users" }
 *
 * @param s is a string used to get users matches with this string.
 * @see UsersRequest
 */
private void searchUser(String s) {
    UsersRequest usersRequest = new UsersRequest.UsersRequestBuilder().setSearchKeyword(s).setLimit(100).build();
    usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {

        @Override
        public void onSuccess(List<User> users) {
            // set the users to rvUserList i.e CometChatUserList Component.
            rvUserList.searchUserList(users);
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(context, rlSearchBox, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) List(java.util.List) UsersRequest(com.cometchat.pro.core.UsersRequest)

Example 54 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException 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();
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat)

Aggregations

CometChatException (com.cometchat.pro.exceptions.CometChatException)54 CometChat (com.cometchat.pro.core.CometChat)45 JSONObject (org.json.JSONObject)20 JSONException (org.json.JSONException)19 Intent (android.content.Intent)14 ArrayList (java.util.ArrayList)13 ProgressDialog (android.app.ProgressDialog)12 User (com.cometchat.pro.models.User)10 View (android.view.View)9 TextView (android.widget.TextView)9 TextMessage (com.cometchat.pro.models.TextMessage)9 List (java.util.List)8 ImageView (android.widget.ImageView)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 BaseMessage (com.cometchat.pro.models.BaseMessage)6 Call (com.cometchat.pro.core.Call)5 MediaMessage (com.cometchat.pro.models.MediaMessage)5 UsersRequest (com.cometchat.pro.core.UsersRequest)4 CometChatReactionDialog (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog)4 MaterialCardView (com.google.android.material.card.MaterialCardView)4