Loading app/core/src/main/java/com/fsck/k9/helper/Contacts.java +15 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -64,6 +66,7 @@ public class Contacts { protected Context mContext; protected ContentResolver mContentResolver; private static HashMap<String, String> nameCache = new HashMap<>(); /** Loading Loading @@ -103,6 +106,7 @@ public class Contacts { } mContext.startActivity(contactIntent); clearCache(); } /** Loading @@ -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(); } /** Loading Loading @@ -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); Loading @@ -184,6 +191,7 @@ public class Contacts { c.close(); } nameCache.put(address, name); return name; } Loading Loading @@ -273,4 +281,11 @@ public class Contacts { SORT_ORDER); } /** * Clears the cache for names and photo uris */ public static void clearCache() { nameCache.clear(); } } app/core/src/main/java/com/fsck/k9/helper/MessageHelper.java +0 −1 Original line number Diff line number Diff line Loading @@ -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); Loading app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +7 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading
app/core/src/main/java/com/fsck/k9/helper/Contacts.java +15 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -64,6 +66,7 @@ public class Contacts { protected Context mContext; protected ContentResolver mContentResolver; private static HashMap<String, String> nameCache = new HashMap<>(); /** Loading Loading @@ -103,6 +106,7 @@ public class Contacts { } mContext.startActivity(contactIntent); clearCache(); } /** Loading @@ -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(); } /** Loading Loading @@ -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); Loading @@ -184,6 +191,7 @@ public class Contacts { c.close(); } nameCache.put(address, name); return name; } Loading Loading @@ -273,4 +281,11 @@ public class Contacts { SORT_ORDER); } /** * Clears the cache for names and photo uris */ public static void clearCache() { nameCache.clear(); } }
app/core/src/main/java/com/fsck/k9/helper/MessageHelper.java +0 −1 Original line number Diff line number Diff line Loading @@ -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); Loading
app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +7 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading