Search in sources :

Example 1 with OnPhoneContactsLoadedListener

use of eu.siacs.conversations.utils.OnPhoneContactsLoadedListener in project Conversations by siacs.

the class XmppConnectionService method loadPhoneContacts.

public void loadPhoneContacts() {
    mContactMergerExecutor.execute(new Runnable() {

        @Override
        public void run() {
            PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {

                @Override
                public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
                    Log.d(Config.LOGTAG, "start merging phone contacts with roster");
                    for (Account account : accounts) {
                        List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
                        for (Bundle phoneContact : phoneContacts) {
                            Jid jid;
                            try {
                                jid = Jid.fromString(phoneContact.getString("jid"));
                            } catch (final InvalidJidException e) {
                                continue;
                            }
                            final Contact contact = account.getRoster().getContact(jid);
                            String systemAccount = phoneContact.getInt("phoneid") + "#" + phoneContact.getString("lookup");
                            contact.setSystemAccount(systemAccount);
                            boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
                            needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                            withSystemAccounts.remove(contact);
                        }
                        for (Contact contact : withSystemAccounts) {
                            contact.setSystemAccount(null);
                            boolean needsCacheClean = contact.setPhotoUri(null);
                            needsCacheClean |= contact.setSystemName(null);
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                        }
                    }
                    Log.d(Config.LOGTAG, "finished merging phone contacts");
                    updateAccountUi();
                }
            });
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Bundle(android.os.Bundle) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OnPhoneContactsLoadedListener(eu.siacs.conversations.utils.OnPhoneContactsLoadedListener) Contact(eu.siacs.conversations.entities.Contact)

Aggregations

Bundle (android.os.Bundle)1 Account (eu.siacs.conversations.entities.Account)1 Contact (eu.siacs.conversations.entities.Contact)1 OnPhoneContactsLoadedListener (eu.siacs.conversations.utils.OnPhoneContactsLoadedListener)1 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1