Search in sources :

Example 46 with CometChatException

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

the class CometChatNewCallList 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) {
            rvUserList.searchUserList(users);
        }

        @Override
        public void onError(CometChatException e) {
            if (rvUserList != null)
                CometChatSnackBar.show(CometChatNewCallList.this, rvUserList, 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) ColorStateList(android.content.res.ColorStateList) List(java.util.List) UsersRequest(com.cometchat.pro.core.UsersRequest)

Example 47 with CometChatException

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

the class UIKitApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    AppSettings appSettings = new AppSettings.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(AppConfig.AppDetails.REGION).build();
    CometChat.init(this, AppConfig.AppDetails.APP_ID, appSettings, new CometChat.CallbackListener<String>() {

        @Override
        public void onSuccess(String s) {
            CometChat.setSource("push-notification", "android", "java");
            Log.d(TAG, "onSuccess: " + s);
        }

        @Override
        public void onError(CometChatException e) {
            Toast.makeText(UIKitApplication.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
    CometChatCallListener.addCallListener(TAG, this);
    createNotificationChannel();
    ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) AppSettings(com.cometchat.pro.core.AppSettings) CometChat(com.cometchat.pro.core.CometChat)

Example 48 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException 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)

Example 49 with CometChatException

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

the class CreateUserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_user);
    inputUid = findViewById(R.id.inputUID);
    inputName = findViewById(R.id.inputName);
    title = findViewById(R.id.tvTitle);
    des1 = findViewById(R.id.tvDes1);
    des2 = findViewById(R.id.tvDes2);
    progressBar = findViewById(R.id.createUser_pb);
    uid = findViewById(R.id.etUID);
    name = findViewById(R.id.etName);
    createUserBtn = findViewById(R.id.create_user_btn);
    createUserBtn.setTextColor(getResources().getColor(R.color.textColorWhite));
    createUserBtn.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 (name.getText().toString().isEmpty())
                name.setError(getResources().getString(R.string.fill_this_field));
            else {
                progressBar.setVisibility(View.VISIBLE);
                createUserBtn.setClickable(false);
                User user = new User();
                user.setUid(uid.getText().toString());
                user.setName(name.getText().toString());
                CometChat.createUser(user, AppConfig.AppDetails.AUTH_KEY, new CometChat.CallbackListener<User>() {

                    @Override
                    public void onSuccess(User user) {
                        login(user);
                    }

                    @Override
                    public void onError(CometChatException e) {
                        createUserBtn.setClickable(true);
                        Toast.makeText(CreateUserActivity.this, "Failed to create user", Toast.LENGTH_LONG).show();
                    }
                });
            }
        }
    });
    checkDarkMode();
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) TextView(android.widget.TextView) View(android.view.View)

Example 50 with CometChatException

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

the class CometChatBlockUserList method unBlockUser.

private void unBlockUser(User user, View var1) {
    ProgressDialog progressDialog = ProgressDialog.show(getContext(), null, user.getName() + " " + getResources().getString(R.string.unblocked_successfully));
    ArrayList<String> uids = new ArrayList<>();
    uids.add(user.getUid());
    CometChat.unblockUsers(uids, new CometChat.CallbackListener<HashMap<String, String>>() {

        @Override
        public void onSuccess(HashMap<String, String> stringStringHashMap) {
            if (userList.contains(user))
                userList.remove(user);
            blockedUserAdapter.removeUser(user);
            progressDialog.dismiss();
            // CometChatSnackBar.show(getContext(),var1,
            // ,CometChatSnackBar.SUCCESS);
            checkIfNoUserVisible();
        }

        @Override
        public void onError(CometChatException e) {
            progressDialog.dismiss();
            CometChatSnackBar.show(getContext(), var1, CometChatError.localized(e), CometChatSnackBar.ERROR);
            Log.e(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) HashMap(java.util.HashMap) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) ProgressDialog(android.app.ProgressDialog)

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