Resolve all contact info

pull/174/head
M66B 5 years ago
parent b62c9b4ab8
commit 48d0a13229

@ -1036,7 +1036,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
// Contact info // Contact info
ContactInfo info = ContactInfo.get(context, message.account, addresses, true); ContactInfo[] info = ContactInfo.getCached(context, message.account, addresses);
if (info == null) { if (info == null) {
if (taskContactInfo != null) if (taskContactInfo != null)
taskContactInfo.cancel(context); taskContactInfo.cancel(context);
@ -1046,17 +1046,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
aargs.putLong("account", message.account); aargs.putLong("account", message.account);
aargs.putSerializable("addresses", addresses); aargs.putSerializable("addresses", addresses);
taskContactInfo = new SimpleTask<ContactInfo>() { taskContactInfo = new SimpleTask<ContactInfo[]>() {
@Override @Override
protected ContactInfo onExecute(Context context, Bundle args) { protected ContactInfo[] onExecute(Context context, Bundle args) {
long account = args.getLong("account"); long account = args.getLong("account");
Address[] addresses = (Address[]) args.getSerializable("addresses"); Address[] addresses = (Address[]) args.getSerializable("addresses");
return ContactInfo.get(context, account, addresses, false); return ContactInfo.get(context, account, addresses);
} }
@Override @Override
protected void onExecuted(Bundle args, ContactInfo info) { protected void onExecuted(Bundle args, ContactInfo[] info) {
taskContactInfo = null; taskContactInfo = null;
long id = args.getLong("id"); long id = args.getLong("id");
@ -1207,33 +1207,40 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibFlagged.setVisibility(View.GONE); ibFlagged.setVisibility(View.GONE);
} }
private void bindContactInfo(ContactInfo info, Address[] addresses, boolean name_email) { private void bindContactInfo(ContactInfo[] info, Address[] addresses, boolean name_email) {
if (info.hasPhoto()) { if (info[0].hasPhoto()) {
ibAvatar.setImageBitmap(info.getPhotoBitmap()); ibAvatar.setImageBitmap(info[0].getPhotoBitmap());
ibAvatar.setVisibility(View.VISIBLE); ibAvatar.setVisibility(View.VISIBLE);
} else } else
ibAvatar.setVisibility(View.GONE); ibAvatar.setVisibility(View.GONE);
Uri lookupUri = info.getLookupUri(); Uri lookupUri = info[0].getLookupUri();
ibAvatar.setTag(lookupUri); ibAvatar.setTag(lookupUri);
ibAvatar.setEnabled(lookupUri != null); ibAvatar.setEnabled(lookupUri != null);
String displayName = info.getDisplayName(); boolean known = false;
if (!TextUtils.isEmpty(displayName) && boolean updated = false;
addresses != null && addresses.length == 1) { for (int i = 0; i < info.length; i++) {
String email = ((InternetAddress) addresses[0]).getAddress(); if (info[i].isKnown())
String personal = ((InternetAddress) addresses[0]).getPersonal(); known = true;
String displayName = info[i].getDisplayName();
if (!TextUtils.isEmpty(displayName)) {
String email = ((InternetAddress) addresses[i]).getAddress();
String personal = ((InternetAddress) addresses[i]).getPersonal();
if (TextUtils.isEmpty(personal) || if (TextUtils.isEmpty(personal) ||
(prefer_contact && !personal.equals(displayName))) (prefer_contact && !personal.equals(displayName)))
try { try {
InternetAddress a = new InternetAddress(email, displayName, StandardCharsets.UTF_8.name()); addresses[i] = new InternetAddress(email, displayName, StandardCharsets.UTF_8.name());
tvFrom.setText(MessageHelper.formatAddresses(new Address[]{a}, name_email, false)); updated = true;
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
Log.w(ex); Log.w(ex);
} }
} }
}
if (updated)
tvFrom.setText(MessageHelper.formatAddresses(addresses, name_email, false));
if (distinguish_contacts && info.isKnown()) if (distinguish_contacts && known)
tvFrom.setPaintFlags(tvFrom.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); tvFrom.setPaintFlags(tvFrom.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
} }

@ -32,6 +32,7 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.io.IOException; import java.io.IOException;
@ -111,11 +112,30 @@ public class ContactInfo {
} }
} }
static ContactInfo get(Context context, long account, Address[] addresses, boolean cacheOnly) { @NonNull
static ContactInfo[] get(Context context, long account, Address[] addresses) {
return get(context, account, addresses, false);
}
static ContactInfo[] getCached(Context context, long account, Address[] addresses) {
return get(context, account, addresses, true);
}
private static ContactInfo[] get(Context context, long account, Address[] addresses, boolean cacheOnly) {
if (addresses == null || addresses.length == 0) if (addresses == null || addresses.length == 0)
return new ContactInfo(); return new ContactInfo[]{new ContactInfo()};
InternetAddress address = (InternetAddress) addresses[0];
ContactInfo[] result = new ContactInfo[addresses.length];
for (int i = 0; i < addresses.length; i++) {
result[i] = _get(context, account, (InternetAddress) addresses[i], cacheOnly);
if (result[i] == null)
return null;
}
return result;
}
private static ContactInfo _get(Context context, long account, InternetAddress address, boolean cacheOnly) {
String key = MessageHelper.formatAddresses(new Address[]{address}); String key = MessageHelper.formatAddresses(new Address[]{address});
synchronized (emailContactInfo) { synchronized (emailContactInfo) {
ContactInfo info = emailContactInfo.get(key); ContactInfo info = emailContactInfo.get(key);

@ -2864,9 +2864,9 @@ class Core {
boolean alert_once = prefs.getBoolean("alert_once", true); boolean alert_once = prefs.getBoolean("alert_once", true);
// Get contact info // Get contact info
Map<Long, ContactInfo> messageContact = new HashMap<>(); Map<Long, ContactInfo[]> messageContact = new HashMap<>();
for (TupleMessageEx message : messages) for (TupleMessageEx message : messages)
messageContact.put(message.id, ContactInfo.get(context, message.account, message.from, false)); messageContact.put(message.id, ContactInfo.get(context, message.account, message.from));
// Summary notification // Summary notification
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || notify_summary) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || notify_summary) {
@ -2939,8 +2939,8 @@ class Core {
DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (EntityMessage message : messages) { for (EntityMessage message : messages) {
ContactInfo info = messageContact.get(message.id); ContactInfo[] info = messageContact.get(message.id);
sb.append("<strong>").append(info.getDisplayName(name_email)).append("</strong>"); sb.append("<strong>").append(info[0].getDisplayName(name_email)).append("</strong>");
if (!TextUtils.isEmpty(message.subject)) if (!TextUtils.isEmpty(message.subject))
sb.append(": ").append(message.subject); sb.append(": ").append(message.subject);
sb.append(" ").append(DTF.format(message.received)); sb.append(" ").append(DTF.format(message.received));
@ -2964,7 +2964,7 @@ class Core {
// Message notifications // Message notifications
for (TupleMessageEx message : messages) { for (TupleMessageEx message : messages) {
ContactInfo info = messageContact.get(message.id); ContactInfo[] info = messageContact.get(message.id);
// Build arguments // Build arguments
long id = (message.content ? message.id : -message.id); long id = (message.content ? message.id : -message.id);
@ -3031,7 +3031,7 @@ class Core {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
setLightAndSound(mbuilder, light, sound); setLightAndSound(mbuilder, light, sound);
mbuilder.setContentTitle(info.getDisplayName(name_email)) mbuilder.setContentTitle(info[0].getDisplayName(name_email))
.setSubText(message.accountName + " · " + message.getFolderName(context)); .setSubText(message.accountName + " · " + message.getFolderName(context));
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -3239,11 +3239,11 @@ class Core {
mbuilder.setContentText(message.subject); mbuilder.setContentText(message.subject);
} }
if (info.hasPhoto()) if (info[0].hasPhoto())
mbuilder.setLargeIcon(info.getPhotoBitmap()); mbuilder.setLargeIcon(info[0].getPhotoBitmap());
if (info.hasLookupUri()) if (info[0].hasLookupUri())
mbuilder.addPerson(info.getLookupUri().toString()); mbuilder.addPerson(info[0].getLookupUri().toString());
if (pro && message.accountColor != null) { if (pro && message.accountColor != null) {
mbuilder.setColor(message.accountColor); mbuilder.setColor(message.accountColor);

Loading…
Cancel
Save