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();
}
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();
}
Aggregations