Search in sources :

Example 1 with OnPhoneContactsLoadedListener

use of de.pixart.messenger.utils.OnPhoneContactsLoadedListener in project Pix-Art-Messenger by kriztan.

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");
                    mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
                    updateAccountUi();
                }
            });
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Bundle(android.os.Bundle) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OnPhoneContactsLoadedListener(de.pixart.messenger.utils.OnPhoneContactsLoadedListener) Contact(de.pixart.messenger.entities.Contact)

Aggregations

Bundle (android.os.Bundle)1 Account (de.pixart.messenger.entities.Account)1 Contact (de.pixart.messenger.entities.Contact)1 OnPhoneContactsLoadedListener (de.pixart.messenger.utils.OnPhoneContactsLoadedListener)1 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)1 Jid (de.pixart.messenger.xmpp.jid.Jid)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1