diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index b9083191d2..bb2f55bf3a 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -73,7 +73,6 @@ import org.xml.sax.XMLReader; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.text.Collator; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -414,9 +413,7 @@ public class AdapterMessage extends RecyclerView.Adapter 0) - aargs.putString("from", message.from[0].toString()); + aargs.putSerializable("addresses", message.from); new SimpleTask() { @Override @@ -428,39 +425,16 @@ public class AdapterMessage extends RecyclerView.Adapter messageFrom = new HashMap<>(); + // Get contact info + Map messageContact = new HashMap<>(); for (TupleMessageEx message : messages) { - String from = null; - if (!TextUtils.isEmpty(message.avatar) && contacts) { - Cursor cursor = null; - try { - cursor = getContentResolver().query( - Uri.parse(message.avatar), - new String[]{ContactsContract.Contacts.DISPLAY_NAME}, - null, null, null); - if (cursor != null && cursor.moveToNext()) - from = cursor.getString(0); - } finally { - if (cursor != null) - cursor.close(); - } - } - - if (from == null) - from = MessageHelper.formatAddressesShort(message.from); - - messageFrom.put(message, from); + ContactInfo info = ContactInfo.get(this, message.from); + if (info == null) + info = new ContactInfo(MessageHelper.formatAddressesShort(message.from)); + messageContact.put(message, info); } // Build pending intent @@ -596,7 +571,7 @@ public class ServiceSynchronize extends LifecycleService { DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); StringBuilder sb = new StringBuilder(); for (EntityMessage message : messages) { - sb.append("").append(messageFrom.get(message)).append(""); + sb.append("").append(messageContact.get(message).getDisplayName()).append(""); if (!TextUtils.isEmpty(message.subject)) sb.append(": ").append(message.subject); sb.append(" ").append(df.format(message.received)); @@ -611,6 +586,8 @@ public class ServiceSynchronize extends LifecycleService { notifications.add(builder.build()); for (TupleMessageEx message : messages) { + ContactInfo info = messageContact.get(message); + Bundle args = new Bundle(); args.putLong("id", message.content ? message.id : -message.id); @@ -667,7 +644,7 @@ public class ServiceSynchronize extends LifecycleService { mbuilder .addExtras(args) .setSmallIcon(R.drawable.baseline_email_white_24) - .setContentTitle(messageFrom.get(message)) + .setContentTitle(info.getDisplayName()) .setSubText(message.accountName + " ยท " + folderName) .setContentIntent(piContent) .setWhen(message.received) @@ -702,47 +679,16 @@ public class ServiceSynchronize extends LifecycleService { mbuilder.setStyle(new Notification.BigTextStyle().bigText(ex.toString())); } - if (!TextUtils.isEmpty(message.avatar)) { - if (contacts) { - Cursor cursor = null; - try { - cursor = getContentResolver().query( - Uri.parse(message.avatar), - new String[]{ - ContactsContract.Contacts._ID, - ContactsContract.Contacts.LOOKUP_KEY - }, - null, null, null); - if (cursor != null && cursor.moveToNext()) { - if (true || Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - Uri uri = ContactsContract.Contacts.getLookupUri( - cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID)), - cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY))); - InputStream is = ContactsContract.Contacts.openContactPhotoInputStream( - getContentResolver(), uri); - mbuilder.setLargeIcon(BitmapFactory.decodeStream(is)); - } else { - Uri photo = Uri.withAppendedPath( - ContactsContract.Contacts.CONTENT_URI, - cursor.getLong(0) + "/photo"); - mbuilder.setLargeIcon(Icon.createWithContentUri(photo)); - } - } - } catch (Throwable ex) { - Log.e(ex); - } finally { - if (cursor != null) - cursor.close(); - } - } + if (info.hasPhoto()) + mbuilder.setLargeIcon(info.getPhotoBitmap()); + if (info.hasLookupUri()) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mbuilder.addPerson(new Person.Builder() - .setUri(message.avatar) + .setUri(info.getLookupUri().toString()) .build()); else - mbuilder.addPerson(message.avatar); - } + mbuilder.addPerson(info.getLookupUri().toString()); if (message.accountColor != null) { mbuilder.setColor(message.accountColor); @@ -2638,12 +2584,6 @@ public class ServiceSynchronize extends LifecycleService { if (message == null) return; - if (message.avatar == null && !folder.isOutgoing()) { - message.avatar = EntityMessage.getLookupUri(context, message.from); - if (message.avatar != null) - db.message().updateMessage(message); - } - if (download) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); long maxSize = prefs.getInt("download", 32768);