|
|
@ -54,6 +54,7 @@ import java.util.List;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.mail.Address;
|
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
@ -153,27 +154,31 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|
|
|
|
|
|
|
|
|
|
|
if (avatars && message.from != null && message.from.length > 0) {
|
|
|
|
if (avatars && message.from != null && message.from.length > 0) {
|
|
|
|
final long id = message.id;
|
|
|
|
final long id = message.id;
|
|
|
|
final String email = ((InternetAddress) message.from[0]).getAddress();
|
|
|
|
final Address[] froms = message.from;
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Cursor cursor = null;
|
|
|
|
for (Address from : froms) {
|
|
|
|
try {
|
|
|
|
String email = ((InternetAddress) from).getAddress();
|
|
|
|
ContentResolver resolver = context.getContentResolver();
|
|
|
|
Cursor cursor = null;
|
|
|
|
cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
|
|
|
try {
|
|
|
|
new String[]{ContactsContract.CommonDataKinds.Photo.CONTACT_ID},
|
|
|
|
ContentResolver resolver = context.getContentResolver();
|
|
|
|
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
|
|
|
|
cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
|
|
|
new String[]{email}, null);
|
|
|
|
new String[]{ContactsContract.CommonDataKinds.Photo.CONTACT_ID},
|
|
|
|
if (cursor.moveToNext()) {
|
|
|
|
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
|
|
|
|
int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
|
|
|
|
new String[]{email}, null);
|
|
|
|
long contactId = cursor.getLong(colContactId);
|
|
|
|
if (cursor.moveToNext()) {
|
|
|
|
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
|
|
|
|
int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
|
|
|
|
DB.getInstance(context).message().setMessageAvatar(id, uri.toString());
|
|
|
|
long contactId = cursor.getLong(colContactId);
|
|
|
|
|
|
|
|
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
|
|
|
|
|
|
|
|
DB.getInstance(context).message().setMessageAvatar(id, uri.toString());
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
|
|
|
cursor.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|