Search in sources :

Example 1 with StructuredName

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);
    }
}
Also used : OnRosterChangedListener(com.xabber.android.data.roster.OnRosterChangedListener) RosterContact(com.xabber.android.data.roster.RosterContact) StructuredName(com.xabber.android.data.roster.StructuredName) NetworkException(com.xabber.android.data.NetworkException)

Example 2 with StructuredName

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);
        }
    });
}
Also used : HashMap(java.util.HashMap) Cursor(android.database.Cursor) StructuredName(com.xabber.android.data.roster.StructuredName)

Aggregations

StructuredName (com.xabber.android.data.roster.StructuredName)2 Cursor (android.database.Cursor)1 NetworkException (com.xabber.android.data.NetworkException)1 OnRosterChangedListener (com.xabber.android.data.roster.OnRosterChangedListener)1 RosterContact (com.xabber.android.data.roster.RosterContact)1 HashMap (java.util.HashMap)1