Search in sources :

Example 1 with AlertListBuilder

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);
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) Arrays(java.util.Arrays) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) GroupVM(im.actor.core.viewmodel.GroupVM) ArrayList(java.util.ArrayList) Screen(im.actor.sdk.util.Screen) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) Toast(android.widget.Toast) AvatarView(im.actor.sdk.view.avatar.AvatarView) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) HolderAdapter(im.actor.sdk.view.adapters.HolderAdapter) Intents(im.actor.sdk.controllers.Intents) ActorSDK(im.actor.sdk.ActorSDK) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) Void(im.actor.runtime.actors.messages.Void) Collection(java.util.Collection) GroupMember(im.actor.core.entity.GroupMember) im.actor.runtime.actors.messages(im.actor.runtime.actors.messages) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) UserPhone(im.actor.core.viewmodel.UserPhone) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) AlertDialog(android.app.AlertDialog) R(im.actor.sdk.R) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Optional(java.util.Optional) Activity(android.app.Activity) ViewHolder(im.actor.sdk.view.adapters.ViewHolder) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) UserPhone(im.actor.core.viewmodel.UserPhone) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) CommandCallback(im.actor.core.viewmodel.CommandCallback) Void(im.actor.runtime.actors.messages.Void) Phonenumber(com.google.i18n.phonenumbers.Phonenumber)

Aggregations

Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)1 PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)1 Phonenumber (com.google.i18n.phonenumbers.Phonenumber)1 GroupMember (im.actor.core.entity.GroupMember)1 CommandCallback (im.actor.core.viewmodel.CommandCallback)1 GroupVM (im.actor.core.viewmodel.GroupVM)1 UserPhone (im.actor.core.viewmodel.UserPhone)1 UserVM (im.actor.core.viewmodel.UserVM)1 im.actor.runtime.actors.messages (im.actor.runtime.actors.messages)1 Void (im.actor.runtime.actors.messages.Void)1 ActorSDK (im.actor.sdk.ActorSDK)1 ActorSDKLauncher (im.actor.sdk.ActorSDKLauncher)1 R (im.actor.sdk.R)1