Search in sources :

Example 6 with CometChatException

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

the class CometChatUserDetailScreenActivity method unblockUser.

private void unblockUser() {
    ProgressDialog progressDialog = ProgressDialog.show(CometChatUserDetailScreenActivity.this, null, userName.getText().toString() + " " + getString(R.string.unblocked_successfully));
    ArrayList<String> uids = new ArrayList<>();
    uids.add(uid);
    CometChat.unblockUsers(uids, new CometChat.CallbackListener<HashMap<String, String>>() {

        @Override
        public void onSuccess(HashMap<String, String> stringStringHashMap) {
            // if (tvBlockUser!=null)
            // CometChatSnackBar.show(CometChatUserDetailScreenActivity.this,
            // tvBlockUser,
            // userName.getText().toString()+" "+getResources().getString(R.string.unblocked_successfully),CometChatSnackBar.SUCCESS);
            progressDialog.dismiss();
            isBlocked = false;
            setBlockUnblock();
        }

        @Override
        public void onError(CometChatException e) {
            Log.d(TAG, "onError: " + e.getMessage());
            if (tvBlockUser != null)
                CometChatSnackBar.show(CometChatUserDetailScreenActivity.this, tvBlockUser, getString(R.string.unblock_user_error), CometChatSnackBar.ERROR);
        }
    });
}
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)

Example 7 with CometChatException

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

the class CometChatConversationList method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_cometchat_conversationlist, container, false);
    rvConversationList = view.findViewById(R.id.rv_conversation_list);
    noConversationView = view.findViewById(R.id.no_conversation_view);
    searchEdit = view.findViewById(R.id.search_bar);
    tvTitle = view.findViewById(R.id.tv_title);
    tvTitle.setTypeface(FontUtils.getInstance(getActivity()).getTypeFace(FontUtils.robotoMedium));
    rlSearchBox = view.findViewById(R.id.rl_search_box);
    conversationShimmer = view.findViewById(R.id.shimmer_layout);
    checkDarkMode();
    CometChatError.init(getContext());
    startConversation = view.findViewById(R.id.start_conversation);
    FeatureRestriction.isStartConversationEnabled(new FeatureRestriction.OnSuccessListener() {

        @Override
        public void onSuccess(Boolean booleanVal) {
            if (booleanVal)
                startConversation.setVisibility(View.VISIBLE);
            else
                startConversation.setVisibility(View.GONE);
        }
    });
    startConversation.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CometChatStartConversation.launch(getContext());
        }
    });
    searchEdit.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_SEARCH) {
            if (!textView.getText().toString().isEmpty()) {
                progressDialog = ProgressDialog.show(getContext(), "", getString(R.string.search));
                refreshConversation(new CometChat.CallbackListener<List<Conversation>>() {

                    @Override
                    public void onSuccess(List<Conversation> conversationList) {
                        if (progressDialog != null)
                            progressDialog.dismiss();
                        rvConversationList.searchConversation(textView.getText().toString());
                    }

                    @Override
                    public void onError(CometChatException e) {
                        if (progressDialog != null)
                            progressDialog.dismiss();
                        CometChatSnackBar.show(getContext(), rvConversationList, CometChatError.localized(e), CometChatSnackBar.ERROR);
                    }
                });
            }
            return true;
        }
        return false;
    });
    // clearSearch.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View view) {
    // searchEdit.setText("");
    // clearSearch.setVisibility(View.GONE);
    // refreshConversation();
    // InputMethodManager inputMethodManager = (InputMethodManager)
    // getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    // // Hide the soft keyboard
    // inputMethodManager.hideSoftInputFromWindow(searchEdit.getWindowToken(),0);
    // }
    // });
    // Uses to fetch next list of conversations if rvConversationList (RecyclerView) is scrolled in upward direction.
    rvConversationList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (!recyclerView.canScrollVertically(1)) {
                makeConversationList();
            }
        }
    });
    // Used to trigger event on click of conversation item in rvConversationList (RecyclerView)
    rvConversationList.setItemClickListener(new OnItemClickListener<Conversation>() {

        @Override
        public void OnItemClick(Conversation conversation, int position) {
            if (events != null)
                events.OnItemClick(conversation, position);
        }
    });
    RecyclerViewSwipeListener swipeHelper = new RecyclerViewSwipeListener(getContext()) {

        @Override
        public void instantiateUnderlayButton(RecyclerView.ViewHolder viewHolder, List<UnderlayButton> underlayButtons) {
            Bitmap deleteBitmap = Utils.drawableToBitmap(getResources().getDrawable(R.drawable.ic_delete_conversation));
            FeatureRestriction.isDeleteConversationEnabled(new FeatureRestriction.OnSuccessListener() {

                @Override
                public void onSuccess(Boolean booleanVal) {
                    if (booleanVal) {
                        underlayButtons.add(new RecyclerViewSwipeListener.UnderlayButton("Delete", deleteBitmap, getResources().getColor(R.color.red), new RecyclerViewSwipeListener.UnderlayButtonClickListener() {

                            @Override
                            public void onClick(final int pos) {
                                Conversation conversation = rvConversationList.getConversation(pos);
                                if (conversation != null) {
                                    String conversationUid = "";
                                    String type = "";
                                    if (conversation.getConversationType().equalsIgnoreCase(CometChatConstants.CONVERSATION_TYPE_GROUP)) {
                                        conversationUid = ((Group) conversation.getConversationWith()).getGuid();
                                        type = CometChatConstants.CONVERSATION_TYPE_GROUP;
                                    } else {
                                        conversationUid = ((User) conversation.getConversationWith()).getUid();
                                        type = CometChatConstants.CONVERSATION_TYPE_USER;
                                    }
                                    String finalConversationUid = conversationUid;
                                    String finalType = type;
                                    new CustomAlertDialogHelper(getContext(), getString(R.string.delete_conversation_message), null, getString(R.string.yes), "", getString(R.string.no), new OnAlertDialogButtonClickListener() {

                                        @Override
                                        public void onButtonClick(AlertDialog alertDialog, View v, int which, int popupId) {
                                            if (which == DialogInterface.BUTTON_POSITIVE) {
                                                ProgressDialog progressDialog = ProgressDialog.show(getContext(), null, getString(R.string.deleting_conversation));
                                                CometChat.deleteConversation(finalConversationUid, finalType, new CometChat.CallbackListener<String>() {

                                                    @Override
                                                    public void onSuccess(String s) {
                                                        Handler handler = new Handler();
                                                        handler.postDelayed(new Runnable() {

                                                            public void run() {
                                                                alertDialog.dismiss();
                                                                progressDialog.dismiss();
                                                            }
                                                        }, 1500);
                                                        rvConversationList.remove(conversation);
                                                    }

                                                    @Override
                                                    public void onError(CometChatException e) {
                                                        progressDialog.dismiss();
                                                        e.printStackTrace();
                                                    }
                                                });
                                            } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                                                alertDialog.dismiss();
                                            }
                                        }
                                    }, 1, true);
                                }
                            }
                        }));
                    }
                }
            });
        }
    };
    swipeHelper.attachToRecyclerView(rvConversationList);
    return view;
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) AlertDialog(androidx.appcompat.app.AlertDialog) ViewGroup(android.view.ViewGroup) Group(com.cometchat.pro.models.Group) User(com.cometchat.pro.models.User) Conversation(com.cometchat.pro.models.Conversation) ProgressDialog(android.app.ProgressDialog) Bitmap(android.graphics.Bitmap) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) CustomAlertDialogHelper(com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.CustomAlertDialogHelper) List(java.util.List) ArrayList(java.util.ArrayList) OnAlertDialogButtonClickListener(com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.OnAlertDialogButtonClickListener) CometChat(com.cometchat.pro.core.CometChat) Handler(android.os.Handler) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerViewSwipeListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerViewSwipeListener) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 8 with CometChatException

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

the class CometChatAddMembers method searchUser.

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) {
            if (userListAdapter != null)
                userListAdapter.searchUser(users);
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(getContext(), 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) ArrayList(java.util.ArrayList) List(java.util.List) UsersRequest(com.cometchat.pro.core.UsersRequest)

Example 9 with CometChatException

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

the class CallBroadcast method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String ourCode = "*007#";
    String dialNumber = intent.getData().toString();
    if (dialNumber.contains(ourCode)) {
        setResultData(null);
        String phoneNumber = dialNumber.replace(ourCode, "");
        UsersRequest usersRequest = new UsersRequest.UsersRequestBuilder().setTags(Arrays.asList(phoneNumber)).setLimit(10).build();
        usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {

            @Override
            public void onSuccess(List<User> users) {
                if (!users.isEmpty()) {
                    User user = users.get(0);
                    Intent userDetail = new Intent(context, CometChatUserDetailScreenActivity.class);
                    userDetail.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
                    userDetail.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
                    userDetail.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                    context.startActivity(userDetail);
                }
            }

            @Override
            public void onError(CometChatException e) {
                Toast.makeText(context, "Unable to find user", Toast.LENGTH_LONG).show();
                context.startActivity(new Intent(context, CometChatUI.class));
            }
        });
    }
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) List(java.util.List) Intent(android.content.Intent) UsersRequest(com.cometchat.pro.core.UsersRequest) CometChatUserDetailScreenActivity(com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity)

Example 10 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("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

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