mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-25 07:01:50 -05:00
Optimized getEmailFromContactPicker()
This commit is contained in:
parent
2d13b0f36c
commit
3b5492f5fc
@ -195,34 +195,41 @@ public class ContactsSdk5 extends com.fsck.k9.helper.Contacts {
|
|||||||
@Override
|
@Override
|
||||||
public ContactItem getEmailFromContactPicker(final Intent data) {
|
public ContactItem getEmailFromContactPicker(final Intent data) {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
Cursor cursor2 = null;
|
|
||||||
ContactItem item = new ContactItem();
|
|
||||||
ArrayList<String> email = new ArrayList<String>();
|
ArrayList<String> email = new ArrayList<String>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uri result = data.getData();
|
Uri result = data.getData();
|
||||||
String displayName = null;
|
String displayName = null;
|
||||||
|
|
||||||
cursor = mContentResolver.query(result, null, null, null, null);
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
displayName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
|
|
||||||
}
|
|
||||||
// Get the contact id from the Uri
|
// Get the contact id from the Uri
|
||||||
String id = result.getLastPathSegment();
|
String id = result.getLastPathSegment();
|
||||||
cursor2 = mContentResolver.query(Email.CONTENT_URI,
|
|
||||||
null, Email.CONTACT_ID + "=?", new String[] { id },
|
|
||||||
null);
|
|
||||||
|
|
||||||
if (cursor2 != null) {
|
cursor = mContentResolver.query(Email.CONTENT_URI, PROJECTION,
|
||||||
int emailIdx = cursor2.getColumnIndex(Email.DATA);
|
Email.CONTACT_ID + "=?", new String[] { id }, null);
|
||||||
|
|
||||||
while (cursor2.moveToNext()) {
|
if (cursor != null) {
|
||||||
email.add(cursor2.getString(emailIdx));
|
while (cursor.moveToNext()) {
|
||||||
|
String address = cursor.getString(EMAIL_INDEX);
|
||||||
|
if (address != null) {
|
||||||
|
email.add(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (displayName == null) {
|
||||||
|
displayName = cursor.getString(NAME_INDEX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return 'null' if no email addresses have been found
|
||||||
if (email.size() == 0) {
|
if (email.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the first email address found as display name
|
||||||
|
if (displayName == null) {
|
||||||
|
displayName = email.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ContactItem item = new ContactItem();
|
||||||
item.setDisplayName(displayName);
|
item.setDisplayName(displayName);
|
||||||
item.setEmailAddresses(email);
|
item.setEmailAddresses(email);
|
||||||
return item;
|
return item;
|
||||||
@ -231,7 +238,6 @@ public class ContactsSdk5 extends com.fsck.k9.helper.Contacts {
|
|||||||
Log.e(K9.LOG_TAG, "Failed to get email data", e);
|
Log.e(K9.LOG_TAG, "Failed to get email data", e);
|
||||||
} finally {
|
} finally {
|
||||||
Utility.closeQuietly(cursor);
|
Utility.closeQuietly(cursor);
|
||||||
Utility.closeQuietly(cursor2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user