Search in sources :

Example 41 with CometChatException

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

the class CometChatCreateGroup method createGroup.

private void createGroup(Group group) {
    ProgressDialog progressDialog = ProgressDialog.show(getContext(), null, getString(R.string.creating_group));
    CometChat.createGroup(group, new CometChat.CallbackListener<Group>() {

        @Override
        public void onSuccess(Group group) {
            progressDialog.dismiss();
            Intent intent = new Intent(getActivity(), CometChatMessageListActivity.class);
            intent.putExtra(UIKitConstants.IntentStrings.NAME, group.getName());
            intent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, group.getOwner());
            intent.putExtra(UIKitConstants.IntentStrings.GUID, group.getGuid());
            intent.putExtra(UIKitConstants.IntentStrings.AVATAR, group.getIcon());
            intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, group.getGroupType());
            intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_GROUP);
            intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, group.getMembersCount());
            intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, group.getDescription());
            intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD, group.getPassword());
            if (getActivity() != null)
                getActivity().finish();
            startActivity(intent);
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(getContext(), etGroupName.getRootView(), CometChatError.localized(e), CometChatSnackBar.ERROR);
            Log.e(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup) CometChat(com.cometchat.pro.core.CometChat) CometChatMessageListActivity(com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog)

Example 42 with CometChatException

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

the class CometChatGroupDetailActivity method banMember.

/**
 * This method is used to ban group member from the group. It is used only if loggedIn user is admin.
 *
 * @see CometChat#banGroupMember(String, String, CometChat.CallbackListener)
 */
private void banMember() {
    ProgressDialog progressDialog = ProgressDialog.show(CometChatGroupDetailActivity.this, null, groupMember.getName() + " " + getString(R.string.banned_successfully));
    CometChat.banGroupMember(groupMember.getUid(), guid, new CometChat.CallbackListener<String>() {

        @Override
        public void onSuccess(String s) {
            progressDialog.dismiss();
            Log.e(TAG, "onSuccess: " + s);
            tvMemberCount.setText((groupMemberCount - 1) + " " + getString(R.string.members));
            // int count = Integer.parseInt(tvBanMemberCount.getText().toString());
            // tvBanMemberCount.setText(String.valueOf(++count));
            groupMemberUids.remove(groupMember.getUid());
            groupMemberAdapter.removeGroupMember(groupMember);
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(CometChatGroupDetailActivity.this, rvMemberList, String.format(getResources().getString(R.string.cannot_remove_member), groupMember.getName()) + "," + CometChatError.localized(e), CometChatSnackBar.ERROR);
            Log.e(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) CometChat(com.cometchat.pro.core.CometChat) ProgressDialog(android.app.ProgressDialog)

Example 43 with CometChatException

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

the class CometChatGroupDetailActivity method kickMember.

/**
 * This method is used to kick group member from the group. It is used only if loggedIn user is admin.
 *
 * @see CometChat#kickGroupMember(String, String, CometChat.CallbackListener)
 */
private void kickMember() {
    ProgressDialog progressDialog = ProgressDialog.show(CometChatGroupDetailActivity.this, null, String.format(getString(R.string.user_removed_from_group), groupMember.getName(), gName));
    CometChat.kickGroupMember(groupMember.getUid(), guid, new CometChat.CallbackListener<String>() {

        @Override
        public void onSuccess(String s) {
            progressDialog.dismiss();
            Log.e(TAG, "onSuccess: " + s);
            tvMemberCount.setText((groupMemberCount - 1) + " " + getString(R.string.members));
            groupMemberUids.remove(groupMember.getUid());
            groupMemberAdapter.removeGroupMember(groupMember);
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(CometChatGroupDetailActivity.this, rvMemberList, String.format(getResources().getString(R.string.cannot_remove_member), groupMember.getName()) + "," + CometChatError.localized(e), CometChatSnackBar.ERROR);
            Log.e(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) CometChat(com.cometchat.pro.core.CometChat) ProgressDialog(android.app.ProgressDialog)

Example 44 with CometChatException

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

the class CometChatGroupMemberList method searchUser.

/**
 * This method is used to perform search operation on list of group members.
 *
 * @param s is a String which is used to search group members.
 *
 * @see GroupMembersRequest
 */
private void searchUser(String s) {
    GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder(guid).setSearchKeyword(s).setLimit(10).build();
    groupMembersRequest.fetchNext(new CometChat.CallbackListener<List<GroupMember>>() {

        @Override
        public void onSuccess(List<GroupMember> groupMembers) {
            if (groupMemberListAdapter != null) {
                List<GroupMember> filterlist = new ArrayList<>();
                for (GroupMember gmember : groupMembers) {
                    if (gmember.getScope().equals(CometChatConstants.SCOPE_PARTICIPANT)) {
                        filterlist.add(gmember);
                    }
                }
                groupMemberListAdapter.searchGroupMembers(filterlist);
            }
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(context, rvGroupMemberList, CometChatError.localized(e), CometChatSnackBar.ERROR);
            Log.e(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) GroupMember(com.cometchat.pro.models.GroupMember) GroupMembersRequest(com.cometchat.pro.core.GroupMembersRequest) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with CometChatException

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

the class CometChatUserProfile method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == UIKitConstants.RequestCode.GALLERY) {
            if (data != null) {
                File file = MediaUtils.getRealPath(getContext(), data.getData(), false);
                ContentResolver cr = getActivity().getContentResolver();
                String mimeType = cr.getType(data.getData());
                if (mimeType != null && mimeType.contains("image")) {
                    // encode image to base64 string
                    JSONObject body = new JSONObject();
                    try {
                        // You can get an inputStream using any I/O API
                        InputStream inputStream = new FileInputStream(file.getPath());
                        byte[] bytes;
                        byte[] buffer = new byte[10240];
                        int bytesRead;
                        ByteArrayOutputStream output = new ByteArrayOutputStream();
                        while ((bytesRead = inputStream.read(buffer)) != -1) {
                            output.write(buffer, 0, bytesRead);
                        }
                        bytes = output.toByteArray();
                        String imageString = Base64.encodeToString(bytes, Base64.NO_WRAP);
                        body.put("avatar", "data:image/png;base64," + imageString);
                    // body.put("avatar", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABzCAMAAAB3qnbXAAACTFBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAD+/v4AAAAAAAAlJCQAAAAAAAAAAAAAAAAAAAAAAABRUVEAAAAAAAAAAAABAAAAAAAwMDAAAAASEhIAAAAAAAACAgICAAAAAAD/AAAAAABVZmb///9WZmYzM0T+AACqu7s0NEQzM0UxMUL9AABDAAAyM0P/iIiru7v/QkJDQ0Pv7+9VVVX/RET/u7tUZWX/EBCIAAC9AAD/IyMEBAT/jIz3AAC+vr5GVFX/d3Y1QkQyNkH/mJj/SUn+bGy2tbX/ZGRNVln+3NwTAAA/QkvvAgL/q6tUAABYZGSNAAAGAACLioz+U1P/vb2tvb3MEBBlMjJSYmP/MjJISEirAADZAgGcnZ2aICH39/dra2v/8PCEAAD/zs7e39/b29vLAAAyQkJ8fH78//+IIyX/nJw1MkMhAABTVWb/aGj+y8svAAD+2NiYAADdEhKrq6v/hYX/+PhERlPmBQZiY2R2dXU7AAD/Wlr/k5NhAQFEMj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qQAvGES1IyBk8Jr+BFTL98IxCVfRD9R0rU2dj2lFf5TWZSAQbxK4x+mFpN5r/qat6yAqpZjDkxhUB++TuoszwaPBDr34E3+Kg+Dbi4AcGUYlX2pVygPQF9gDPi3WhT46tFpwYk8G6awHeE+FKDpBL94QyRnnc4sb6zlfZqFkUEYx8FcLNgyx+SqM8mLvg19KRwPenujVOtiUyDFPJT3+y1e2A7uheYV0hc24BkDHlN5PKGN7rt3if8aKJ8fWvbHgoNLwyHvFjkS2P0Ce4oiRm9lAewEfKGMgBS0hQ1d8dLYVSKRLBEak2aTKur6W3wwIaPNMaYRhFpXjFxbQMDA5l2URRdrm3o3m2XRhM/+J9ubXkyuwsLC7vpNCmysdxZGHWL4lQW9bwLqjPp3QWAHqk92N39THDAks0GsA7gcYpiZntra/k+VNtovxjTdLKMwXOYKrszMCB7Gw8RHCR+eOj3P9zZWlgYfUuQCzRU7/3eoAX43/oxvMSy088Buru7ScQi0HzvdaFzB7/J864/JXV02d7KgeLZXwlCSX+Xw+Fobu5vaHgQj98XhKIiQagKlJ7hngYcePWf5jiOdHqf1Is/wP0XljsCJWSjEMAbpz4QhJr+fppdXkraYFvys6qf9tvcf0Y4rqa5nMs/ruVu070Vnv2Rm4RRqKgTCYI4pQ55nrK8AlrOFbIHyT+R9yHt5VTBBx+x+lxhWcFxTf/zi4tzEroLyXX06IcnTxZ8/LGc3V1WSDavR8j9oqKi/DJdPbW8kNUoKjhLOyvLpyUnsE0h2/iW5RfRi9QoLj4gLf5d0tt/Wtt37v+XXf8HYpztme1nOY8AAAAASUVORK5CYII=");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    // Bitmap bm = BitmapFactory.decodeFile(file.getPath());
                    // ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    // bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
                    // byte[] b = baos.toByteArray();
                    // return Base64.encodeToString(b, Base64.NO_WRAP);
                    Log.e("File Info", body.toString());
                    CometChat.callExtension("avatar", "POST", "/v1/upload", body, new CometChat.CallbackListener<JSONObject>() {

                        @Override
                        public void onSuccess(JSONObject jsonObject) {
                            try {
                                avatarUrl = jsonObject.getJSONObject("data").getString("avatarURL");
                                if (avatar != null)
                                    avatar.setAvatar(avatarUrl);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        // {avatarURL: "https://data-us.cometchat.io/avatars/1a2b3c.jpg"}
                        }

                        @Override
                        public void onError(CometChatException e) {
                            e.printStackTrace();
                        }
                    });
                }
            }
        }
    }
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CometChat(com.cometchat.pro.core.CometChat) JSONException(org.json.JSONException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ContentResolver(android.content.ContentResolver) JSONObject(org.json.JSONObject) File(java.io.File)

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