use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class VCardManager method onVCardReceived.
private void onVCardReceived(final String account, final String bareAddress, final VCard vCard) {
final StructuredName name;
if (vCard.getType() == Type.error) {
onVCardFailed(account, bareAddress);
if (names.containsKey(bareAddress)) {
return;
}
name = EMPTY_STRUCTURED_NAME;
} else {
for (OnVCardListener listener : Application.getInstance().getUIListeners(OnVCardListener.class)) {
listener.onVCardReceived(account, bareAddress, vCard);
}
String hash = vCard.getAvatarHash();
AvatarManager.getInstance().onAvatarReceived(bareAddress, hash, vCard.getAvatar());
name = new StructuredName(vCard.getNickName(), vCard.getField(VCardProperty.FN.name()), vCard.getFirstName(), vCard.getMiddleName(), vCard.getLastName());
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
try {
if (Jid.getBareAddress(account).equals(bareAddress)) {
PresenceManager.getInstance().resendPresence(account);
}
} catch (NetworkException e) {
e.printStackTrace();
}
}
});
}
names.put(bareAddress, name);
for (RosterContact rosterContact : RosterManager.getInstance().getContacts()) {
if (rosterContact.getUser().equals(bareAddress)) {
for (OnRosterChangedListener listener : Application.getInstance().getManagers(OnRosterChangedListener.class)) {
listener.onContactStructuredInfoChanged(rosterContact, name);
}
}
}
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
VCardTable.getInstance().write(bareAddress, name);
}
});
if (vCard.getFrom() == null) {
// account it self
AccountManager.getInstance().onAccountChanged(account);
} else {
RosterManager.getInstance().onContactChanged(account, bareAddress);
}
}
use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class ContactListActivity method openChat.
/**
* Open chat with specified contact.
* <p/>
* Show dialog to choose account if necessary.
*
* @param user
* @param text can be <code>null</code>.
*/
private void openChat(UserJid user, String text) {
UserJid bareAddress = user.getBareUserJid();
ArrayList<BaseEntity> entities = new ArrayList<>();
for (AbstractChat check : MessageManager.getInstance().getChats()) {
if (check.isActive() && check.getUser().equals(bareAddress)) {
entities.add(check);
}
}
if (entities.size() == 1) {
openChat(entities.get(0), text);
return;
}
entities.clear();
Collection<AccountJid> enabledAccounts = AccountManager.getInstance().getEnabledAccounts();
RosterManager rosterManager = RosterManager.getInstance();
for (AccountJid accountJid : enabledAccounts) {
RosterContact rosterContact = rosterManager.getRosterContact(accountJid, user);
if (rosterContact != null && rosterContact.isEnabled()) {
entities.add(rosterContact);
}
}
if (entities.size() == 1) {
openChat(entities.get(0), text);
return;
}
if (enabledAccounts.isEmpty()) {
return;
}
if (enabledAccounts.size() == 1) {
openChat(rosterManager.getBestContact(enabledAccounts.iterator().next(), bareAddress), text);
return;
}
AccountChooseDialogFragment.newInstance(bareAddress, text).show(getFragmentManager(), "OPEN_WITH_ACCOUNT");
}
use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class ChatActivity method editAlias.
private void editAlias() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.edit_alias);
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, user);
if (rosterContact != null)
input.setText(rosterContact.getName());
builder.setView(input);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
RosterManager.getInstance().setName(account, user, input.getText().toString());
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class ContactEditActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toolbar toolbar = getToolbar();
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(getAccount(), getUser());
if (rosterContact != null) {
toolbar.inflateMenu(R.menu.toolbar_contact);
toolbar.setOnMenuItemClickListener(this);
toolbar.setOverflowIcon(getResources().getDrawable(R.drawable.ic_overflow_menu_white_24dp));
onCreateOptionsMenu(toolbar.getMenu());
}
}
use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class ContactEditActivity method sendContact.
private void sendContact() {
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(getAccount(), getUser());
String text = rosterContact != null ? rosterContact.getName() + "\nxmpp:" + getUser().toString() : "xmpp:" + getUser().toString();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
}
Aggregations