Search in sources :

Example 1 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class AddContactActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setDisplayShowCustomEnabled(false);
    getSupportActionBar().setTitle(R.string.add_contact_title);
    helper = new KeyboardHelper(this);
    setContentView(R.layout.activity_add);
    findViewById(R.id.container).setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    searchQuery = (EditText) findViewById(R.id.searchField);
    searchQuery.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    searchQuery.setHintTextColor(ActorSDK.sharedActor().style.getTextHintColor());
    findViewById(R.id.dividerTop).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    findViewById(R.id.dividerBot).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    ((TextView) findViewById(R.id.cancel)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            finish();
        }
    });
    ((TextView) findViewById(R.id.ok)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final String query = searchQuery.getText().toString();
            if (query.length() == 0) {
                return;
            }
            execute(messenger().findUsers(query), R.string.progress_common, new CommandCallback<UserVM[]>() {

                @Override
                public void onResult(final UserVM[] res) {
                    if (res.length == 0) {
                        new AlertDialog.Builder(AddContactActivity.this).setMessage(getString(R.string.alert_invite_text).replace("{0}", query).replace("{appName}", ActorSDK.sharedActor().getAppName())).setPositiveButton(R.string.alert_invite_yes, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                String inviteMessage = getString(R.string.invite_message).replace("{inviteUrl}", ActorSDK.sharedActor().getInviteUrl()).replace("{appName}", ActorSDK.sharedActor().getAppName());
                                Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                                sendIntent.setData(Uri.parse("sms:" + query));
                                sendIntent.putExtra("sms_body", inviteMessage);
                                startActivity(sendIntent);
                                finish();
                            }
                        }).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
                    } else {
                        execute(messenger().addContact(res[0].getId()), R.string.progress_common, new CommandCallback<Boolean>() {

                            @Override
                            public void onResult(Boolean res2) {
                                startActivity(Intents.openPrivateDialog(res[0].getId(), true, AddContactActivity.this));
                                finish();
                            }

                            @Override
                            public void onError(Exception e) {
                                startActivity(Intents.openPrivateDialog(res[0].getId(), true, AddContactActivity.this));
                                finish();
                            }
                        });
                    }
                }

                @Override
                public void onError(Exception e) {
                // Never happens
                }
            });
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) KeyboardHelper(im.actor.sdk.util.KeyboardHelper) CommandCallback(im.actor.core.viewmodel.CommandCallback)

Example 2 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class InviteLinkFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    chatId = getArguments().getInt(EXTRA_GROUP_ID);
    Command<String> cmd = messenger().requestInviteLink(chatId);
    if (cmd != null)
        cmd.start(new CommandCallback<String>() {

            @Override
            public void onResult(String res) {
                link = res;
                adapter.notifyDataSetChanged();
                hideView(emptyView);
                showView(listView);
            }

            @Override
            public void onError(Exception e) {
                Toast.makeText(getActivity(), getString(R.string.invite_link_error_get_link), Toast.LENGTH_SHORT).show();
                adapter.notifyDataSetChanged();
            }
        });
    final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    View res = inflater.inflate(R.layout.fragment_list, container, false);
    res.setBackgroundColor(ActorSDK.sharedActor().style.getBackyardBackgroundColor());
    listView = (ListView) res.findViewById(R.id.listView);
    listView.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    emptyView = (TextView) res.findViewById(R.id.emptyView);
    emptyView.setText(getString(R.string.invite_link_empty_view));
    emptyView.setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    adapter = new InviteLincActionsAdapter(getActivity());
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (link != null && !link.isEmpty()) {
                switch(position) {
                    case 0:
                        //Link itself
                        clipboard.setPrimaryClip(ClipData.newPlainText(null, link));
                        Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        //Hint
                        break;
                    case 2:
                        //Copy
                        clipboard.setPrimaryClip(ClipData.newPlainText(null, link));
                        Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
                        break;
                    case 3:
                        //Revoke
                        new AlertDialog.Builder(getActivity()).setMessage(R.string.alert_revoke_link_message).setNegativeButton(R.string.dialog_cancel, null).setPositiveButton(R.string.alert_revoke_link_yes, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface d, int which) {
                                execute(messenger().revokeInviteLink(chatId), R.string.invite_link_action_revoke, new CommandCallback<String>() {

                                    @Override
                                    public void onResult(String res) {
                                        link = res;
                                        adapter.notifyDataSetChanged();
                                    }

                                    @Override
                                    public void onError(Exception e) {
                                        Toast.makeText(getActivity(), getString(R.string.invite_link_error_revoke_link), Toast.LENGTH_SHORT).show();
                                    }
                                });
                            }
                        }).show();
                        break;
                    case 4:
                        //Share
                        Intent i = new Intent(Intent.ACTION_SEND);
                        i.setType("text/plain");
                        i.putExtra(Intent.EXTRA_TEXT, link);
                        Intent chooser = Intent.createChooser(i, getString(R.string.invite_link_chooser_title));
                        if (i.resolveActivity(getActivity().getPackageManager()) != null) {
                            startActivity(chooser);
                        }
                        break;
                }
            }
        }
    });
    View footer = inflater.inflate(R.layout.fragment_link_item_footer, listView, false);
    footer.setBackgroundColor(ActorSDK.sharedActor().style.getBackyardBackgroundColor());
    listView.addFooterView(footer, null, false);
    return res;
}
Also used : ClipboardManager(android.content.ClipboardManager) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) CommandCallback(im.actor.core.viewmodel.CommandCallback)

Example 3 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback 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)

Example 4 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class EditNameFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    type = getArguments().getInt("EXTRA_TYPE");
    id = getArguments().getInt("EXTRA_ID");
    helper = new KeyboardHelper(getActivity());
    View res = inflater.inflate(R.layout.fragment_edit_name, container, false);
    res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    nameEdit = (EditText) res.findViewById(R.id.nameEdit);
    nameEdit.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    hintTv = (TextView) res.findViewById(R.id.hint);
    hintTv.setTextColor(ActorSDK.sharedActor().style.getTextHintColor());
    if (type == EditNameActivity.TYPE_ME) {
        UserVM userModel = users().get(myUid());
        nameEdit.setText(userModel.getName().get());
    } else if (type == EditNameActivity.TYPE_NICK) {
        UserVM userModel = users().get(myUid());
        nameEdit.setText(userModel.getNick().get());
        nameEdit.setHint(getString(R.string.nickname_edittext_hint));
        hintTv.setText(getString(R.string.nickname_hint).replace("{appName}", ActorSDK.sharedActor().getAppName()));
    } else if (type == EditNameActivity.TYPE_USER) {
        UserVM userModel = users().get(id);
        nameEdit.setText(userModel.getName().get());
    } else if (type == EditNameActivity.TYPE_GROUP) {
        GroupVM group = groups().get(id);
        nameEdit.setText(group.getName().get());
    } else if (type == EditNameActivity.TYPE_GROUP_THEME) {
        GroupVM group = groups().get(id);
        nameEdit.setText(group.getTheme().get());
    }
    res.findViewById(R.id.dividerTop).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    res.findViewById(R.id.dividerBot).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    res.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    ((TextView) res.findViewById(R.id.cancel)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    res.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String name = nameEdit.getText().toString().trim();
            if (name.length() == 0) {
                Toast.makeText(getActivity(), R.string.toast_empty_name, Toast.LENGTH_SHORT).show();
                return;
            }
            if (type == EditNameActivity.TYPE_ME) {
                execute(messenger().editMyName(name), R.string.edit_name_process, new CommandCallback<Boolean>() {

                    @Override
                    public void onResult(Boolean res) {
                        getActivity().finish();
                    }

                    @Override
                    public void onError(Exception e) {
                        Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
                    }
                });
            } else if (type == EditNameActivity.TYPE_NICK) {
                execute(messenger().editMyNick(name), R.string.edit_nick_process, new CommandCallback<Boolean>() {

                    @Override
                    public void onResult(Boolean res) {
                        getActivity().finish();
                    }

                    @Override
                    public void onError(Exception e) {
                        Toast.makeText(getActivity(), R.string.toast_unable_change_nick, Toast.LENGTH_SHORT).show();
                    }
                });
            } else if (type == EditNameActivity.TYPE_USER) {
                execute(messenger().editName(id, name), R.string.edit_name_process, new CommandCallback<Boolean>() {

                    @Override
                    public void onResult(Boolean res) {
                        getActivity().finish();
                    }

                    @Override
                    public void onError(Exception e) {
                        Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
                    }
                });
            } else if (type == EditNameActivity.TYPE_GROUP_THEME) {
                execute(messenger().editGroupTheme(id, name), R.string.edit_theme_process, new CommandCallback<Void>() {

                    @Override
                    public void onResult(Void res) {
                        getActivity().finish();
                    }

                    @Override
                    public void onError(Exception e) {
                        Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    });
    ((TextView) res.findViewById(R.id.ok)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    return res;
}
Also used : GroupVM(im.actor.core.viewmodel.GroupVM) TextView(android.widget.TextView) View(android.view.View) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) KeyboardHelper(im.actor.sdk.util.KeyboardHelper) CommandCallback(im.actor.core.viewmodel.CommandCallback) Void(im.actor.runtime.actors.messages.Void)

Example 5 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class JsFacade method doCall.

// Calls
@UsedByApp
public JsPromise doCall(final int uid) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            messenger.doCall(uid).start(new CommandCallback<Long>() {

                @Override
                public void onResult(Long res) {
                    Log.d(TAG, "doCall:result");
                    resolve();
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "doCall:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) CommandCallback(im.actor.core.viewmodel.CommandCallback) RpcException(im.actor.core.network.RpcException) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Aggregations

CommandCallback (im.actor.core.viewmodel.CommandCallback)37 UsedByApp (im.actor.core.js.annotations.UsedByApp)28 RpcException (im.actor.core.network.RpcException)28 JsPromiseExecutor (im.actor.runtime.js.utils.JsPromiseExecutor)28 Void (im.actor.runtime.actors.messages.Void)13 UserVM (im.actor.core.viewmodel.UserVM)8 ArrayList (java.util.ArrayList)8 View (android.view.View)7 TextView (android.widget.TextView)7 List (java.util.List)7 AlertDialog (android.app.AlertDialog)5 Intent (android.content.Intent)4 GroupVM (im.actor.core.viewmodel.GroupVM)4 DialogInterface (android.content.DialogInterface)3 ViewGroup (android.view.ViewGroup)3 Toast (android.widget.Toast)3 MessageSearchEntity (im.actor.core.entity.MessageSearchEntity)3 ActorSDK (im.actor.sdk.ActorSDK)3 R (im.actor.sdk.R)3 ActorSDKMessenger.messenger (im.actor.sdk.util.ActorSDKMessenger.messenger)3