use of im.actor.sdk.util.AlertListBuilder in project actor-platform by actorapp.
the class MembersAdapter method onMemberClick.
public void onMemberClick(GroupVM groupVM, UserVM userVM, boolean isAdministrator, boolean isInvitedByMe, BaseActivity activity) {
AlertListBuilder alertListBuilder = new AlertListBuilder();
final ArrayList<UserPhone> phones = userVM.getPhones().get();
alertListBuilder.addItem(activity.getString(R.string.group_context_message).replace("{0}", userVM.getName().get()), () -> activity.startActivity(Intents.openPrivateDialog(userVM.getId(), true, activity)));
if (phones.size() != 0) {
alertListBuilder.addItem(activity.getString(R.string.group_context_call).replace("{0}", userVM.getName().get()), () -> {
if (phones.size() == 1) {
activity.startActivity(Intents.call(phones.get(0).getPhone()));
} else {
CharSequence[] sequences = new CharSequence[phones.size()];
for (int i = 0; i < sequences.length; i++) {
try {
Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + phones.get(i).getPhone(), "us");
sequences[i] = phones.get(i).getTitle() + ": " + PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
sequences[i] = phones.get(i).getTitle() + ": +" + phones.get(i).getPhone();
}
}
new AlertDialog.Builder(activity).setItems(sequences, (dialog1, which1) -> {
activity.startActivity(Intents.call(phones.get(which1).getPhone()));
}).show().setCanceledOnTouchOutside(true);
}
});
}
alertListBuilder.addItem(activity.getString(R.string.group_context_view).replace("{0}", userVM.getName().get()), () -> ActorSDKLauncher.startProfileActivity(activity, userVM.getId()));
if (groupVM.getIsCanKickAnyone().get() || (groupVM.getIsCanKickInvited().get() && isInvitedByMe)) {
alertListBuilder.addItem(activity.getString(R.string.group_context_remove).replace("{0}", userVM.getName().get()), () -> {
new AlertDialog.Builder(activity).setMessage(activity.getString(R.string.alert_group_remove_text).replace("{0}", userVM.getName().get())).setPositiveButton(R.string.alert_group_remove_yes, (dialog2, which1) -> {
activity.execute(messenger().kickMember(groupVM.getId(), userVM.getId()), R.string.progress_common, new CommandCallback<Void>() {
@Override
public void onResult(Void res1) {
}
@Override
public void onError(Exception e) {
Toast.makeText(activity, R.string.toast_unable_kick, Toast.LENGTH_SHORT).show();
}
});
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
});
}
if (groupVM.getIsCanEditAdmins().get() && !userVM.isBot()) {
alertListBuilder.addItem(!isAdministrator ? activity.getResources().getString(R.string.group_make_admin) : activity.getResources().getString(R.string.group_revoke_admin), () -> {
if (!isAdministrator) {
messenger().makeAdmin(groupVM.getId(), userVM.getId()).start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
} else {
messenger().revokeAdmin(groupVM.getId(), userVM.getId()).start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
}
});
}
alertListBuilder.build(activity).show().setCanceledOnTouchOutside(true);
}
Aggregations