Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 7d11244d authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #3508 from k9mail/contacts_cache

Cache contact names
parents b3c0021e 4ecb0d14
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ import android.provider.ContactsContract.CommonDataKinds.Photo;

import com.fsck.k9.mail.Address;

import java.util.HashMap;

/**
 * Helper class to access the contacts stored on the device.
 */
@@ -64,6 +66,7 @@ public class Contacts {

    protected Context mContext;
    protected ContentResolver mContentResolver;
    private static HashMap<String, String> nameCache = new HashMap<>();


    /**
@@ -103,6 +106,7 @@ public class Contacts {
        }

        mContext.startActivity(contactIntent);
        clearCache();
    }

    /**
@@ -117,6 +121,7 @@ public class Contacts {
        addIntent.putExtra(ContactsContract.Intents.Insert.PHONE, Uri.decode(phoneNumber));
        addIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(addIntent);
        clearCache();
    }

    /**
@@ -171,6 +176,8 @@ public class Contacts {
    public String getNameForAddress(String address) {
        if (address == null) {
            return null;
        } else if (nameCache.containsKey(address)) {
            return nameCache.get(address);
        }

        final Cursor c = getContactByAddress(address);
@@ -184,6 +191,7 @@ public class Contacts {
            c.close();
        }

        nameCache.put(address, name);
        return name;
    }

@@ -273,4 +281,11 @@ public class Contacts {
                SORT_ORDER);
    }

    /**
     * Clears the cache for names and photo uris
     */
    public static void clearCache() {
        nameCache.clear();
    }

}
+0 −1
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ public class MessageHelper {
            return address.getAddress();
        } else if (contacts != null) {
            final String name = contacts.getNameForAddress(address.getAddress());
            // TODO: The results should probably be cached for performance reasons.
            if (name != null) {
                if (changeContactNameColor) {
                    final SpannableString coloredName = new SpannableString(name);
+7 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.fsck.k9.K9;
import com.fsck.k9.K9.SplitViewMode;
import com.fsck.k9.Preferences;
import com.fsck.k9.controller.MessageReference;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.ui.R;
import com.fsck.k9.activity.compose.MessageActions;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
@@ -543,6 +544,12 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
        StorageManager.getInstance(getApplication()).addListener(mStorageListener);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Contacts.clearCache();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);