Search in sources :

Example 1 with CometChatAvatar

use of com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatGroupDetailActivity method updateGroupDialog.

private void updateGroupDialog() {
    dialog = new AlertDialog.Builder(this);
    View view = LayoutInflater.from(this).inflate(R.layout.cometchat_update_group_dialog, null);
    CometChatAvatar avatar = view.findViewById(R.id.group_icon);
    TextInputEditText avatar_url = view.findViewById(R.id.icon_url_edt);
    if (groupIcon.getAvatarUrl() != null) {
        avatar.setVisibility(View.VISIBLE);
        avatar.setAvatar(groupIcon.getAvatarUrl());
        avatar_url.setText(groupIcon.getAvatarUrl());
    } else {
        avatar.setVisibility(View.GONE);
    }
    TextInputEditText groupName = view.findViewById(R.id.groupname_edt);
    TextInputEditText groupDesc = view.findViewById(R.id.groupdesc_edt);
    TextInputEditText groupOldPwd = view.findViewById(R.id.group_old_pwd);
    TextInputEditText groupNewPwd = view.findViewById(R.id.group_new_pwd);
    TextInputLayout groupOldPwdLayout = view.findViewById(R.id.input_group_old_pwd);
    TextInputLayout groupNewPwdLayout = view.findViewById(R.id.input_group_new_pwd);
    Spinner groupTypeSp = view.findViewById(R.id.groupTypes);
    MaterialButton updateGroupBtn = view.findViewById(R.id.updateGroupBtn);
    MaterialButton cancelBtn = view.findViewById(R.id.cancelBtn);
    groupName.setText(gName);
    groupDesc.setText(gDesc);
    if (groupType != null && groupType.equals(CometChatConstants.GROUP_TYPE_PUBLIC)) {
        groupTypeSp.setSelection(0);
        groupOldPwdLayout.setVisibility(View.GONE);
        groupNewPwdLayout.setVisibility(View.GONE);
    } else if (groupType != null && groupType.equals(CometChatConstants.GROUP_TYPE_PRIVATE)) {
        groupTypeSp.setSelection(1);
        groupOldPwdLayout.setVisibility(View.GONE);
        groupNewPwdLayout.setVisibility(View.GONE);
    } else {
        groupTypeSp.setSelection(2);
        groupOldPwdLayout.setVisibility(View.VISIBLE);
        groupNewPwdLayout.setVisibility(View.VISIBLE);
    }
    groupTypeSp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (parent.getSelectedItemPosition() == 2) {
                if (gPassword == null) {
                    groupOldPwdLayout.setVisibility(View.GONE);
                } else
                    groupOldPwdLayout.setVisibility(View.VISIBLE);
                groupNewPwdLayout.setVisibility(View.VISIBLE);
            } else {
                groupOldPwdLayout.setVisibility(View.GONE);
                groupNewPwdLayout.setVisibility(View.GONE);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    avatar_url.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (!s.toString().isEmpty()) {
                avatar.setVisibility(View.VISIBLE);
                avatar.setAvatar(s.toString());
            } else
                avatar.setVisibility(View.GONE);
        }
    });
    AlertDialog alertDialog = dialog.create();
    alertDialog.setView(view);
    updateGroupBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Group group = new Group();
            group.setDescription(groupDesc.getText().toString().trim());
            if (groupName.getText().toString().isEmpty()) {
                groupName.setError(getString(R.string.fill_this_field));
            } else if (groupTypeSp.getSelectedItemPosition() == 2) {
                if (gPassword != null && groupOldPwd.getText().toString().trim().isEmpty()) {
                    groupOldPwd.setError(getResources().getString(R.string.fill_this_field));
                } else if (gPassword != null && !groupOldPwd.getText().toString().trim().equals(gPassword.trim())) {
                    groupOldPwd.setError(getResources().getString(R.string.password_not_matched));
                } else if (groupNewPwd.getText().toString().trim().isEmpty()) {
                    groupNewPwd.setError(getResources().getString(R.string.fill_this_field));
                } else {
                    group.setName(groupName.getText().toString());
                    group.setGuid(guid);
                    group.setGroupType(CometChatConstants.GROUP_TYPE_PASSWORD);
                    group.setPassword(groupNewPwd.getText().toString());
                    group.setIcon(avatar_url.getText().toString());
                    updateGroup(group, alertDialog);
                }
            } else if (groupTypeSp.getSelectedItemPosition() == 1) {
                group.setName(groupName.getText().toString());
                group.setGuid(guid);
                group.setGroupType(CometChatConstants.GROUP_TYPE_PRIVATE);
                group.setIcon(avatar_url.getText().toString());
            } else {
                group.setName(groupName.getText().toString());
                group.setGroupType(CometChatConstants.GROUP_TYPE_PUBLIC);
                group.setIcon(avatar_url.getText().toString());
            }
            group.setGuid(guid);
            updateGroup(group, alertDialog);
        }
    });
    cancelBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) Group(com.cometchat.pro.models.Group) Spinner(android.widget.Spinner) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) MaterialButton(com.google.android.material.button.MaterialButton) TextInputEditText(com.google.android.material.textfield.TextInputEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AdapterView(android.widget.AdapterView) CometChatAvatar(com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar) TextInputLayout(com.google.android.material.textfield.TextInputLayout)

Example 2 with CometChatAvatar

use of com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatUserProfile method updateUserDialog.

private void updateUserDialog() {
    dialog = new AlertDialog.Builder(getContext());
    View view = LayoutInflater.from(getContext()).inflate(R.layout.cometchat_update_user_dialog, null);
    CometChatAvatar avatar = view.findViewById(R.id.user_avatar);
    avatar.setAvatar(CometChat.getLoggedInUser());
    TextInputEditText avatar_url = view.findViewById(R.id.avatar_url_edt);
    avatar_url.setText(CometChat.getLoggedInUser().getAvatar());
    TextInputEditText username = view.findViewById(R.id.username_edt);
    username.setText(CometChat.getLoggedInUser().getName());
    MaterialButton updateUserBtn = view.findViewById(R.id.updateUserBtn);
    MaterialButton cancelBtn = view.findViewById(R.id.cancelBtn);
    if (CometChat.getLoggedInUser().getAvatar() == null) {
        avatar.setVisibility(View.GONE);
        avatar_url.setVisibility(View.GONE);
    } else {
        avatar.setVisibility(View.VISIBLE);
        avatar_url.setVisibility(View.VISIBLE);
    }
    avatar_url.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (!s.toString().isEmpty()) {
                avatar.setVisibility(View.VISIBLE);
                avatar.setAvatar(s.toString());
            } else
                avatar.setVisibility(View.GONE);
        }
    });
    AlertDialog alertDialog = dialog.create();
    alertDialog.setView(view);
    updateUserBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            User user = new User();
            if (username.getText().toString().isEmpty())
                username.setError(getString(R.string.fill_this_field));
            else {
                user.setName(username.getText().toString());
                user.setUid(CometChat.getLoggedInUser().getUid());
                user.setAvatar(avatar_url.getText().toString());
                updateUser(user);
                alertDialog.dismiss();
            }
        }
    });
    cancelBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) User(com.cometchat.pro.models.User) View(android.view.View) MaterialButton(com.google.android.material.button.MaterialButton) TextInputEditText(com.google.android.material.textfield.TextInputEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) CometChatAvatar(com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar)

Aggregations

AlertDialog (android.app.AlertDialog)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 View (android.view.View)2 CometChatAvatar (com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar)2 MaterialButton (com.google.android.material.button.MaterialButton)2 TextInputEditText (com.google.android.material.textfield.TextInputEditText)2 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Group (com.cometchat.pro.models.Group)1 User (com.cometchat.pro.models.User)1 TextInputLayout (com.google.android.material.textfield.TextInputLayout)1