use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.
the class JsFacade method editMyName.
// Profile
@UsedByApp
public JsPromise editMyName(final String newName) {
return JsPromise.create(new JsPromiseExecutor() {
@Override
public void execute() {
//noinspection ConstantConditions
messenger.editMyName(newName).start(new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
Log.d(TAG, "editMyName:result");
resolve();
}
@Override
public void onError(Exception e) {
Log.d(TAG, "editMyName:error");
reject(e.getMessage());
}
});
}
});
}
use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.
the class JsFacade method findAllLinks.
@UsedByApp
public JsPromise findAllLinks(final JsPeer peer) {
return JsPromise.create(new JsPromiseExecutor() {
@Override
public void execute() {
messenger.findAllLinks(peer.convert()).start(new CommandCallback<List<MessageSearchEntity>>() {
@Override
public void onResult(List<MessageSearchEntity> res) {
resolve(convertSearchRes(res));
}
@Override
public void onError(Exception e) {
Log.d(TAG, "findAllText:error");
reject(e.getMessage());
}
});
}
});
}
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
}
});
}
});
}
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;
}
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);
}
Aggregations