use of com.xabber.android.data.roster.StructuredName 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.StructuredName in project xabber-android by redsolution.
the class VCardManager method onLoad.
@Override
public void onLoad() {
final Map<String, StructuredName> names = new HashMap<>();
Cursor cursor = VCardTable.getInstance().list();
try {
if (cursor.moveToFirst()) {
do {
names.put(VCardTable.getUser(cursor), new StructuredName(VCardTable.getNickName(cursor), VCardTable.getFormattedName(cursor), VCardTable.getFirstName(cursor), VCardTable.getMiddleName(cursor), VCardTable.getLastName(cursor)));
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
onLoaded(names);
}
});
}
Aggregations