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

@ -32,6 +32,7 @@ import android.os.Handler;
import android.os.Looper;
import android.provider.ContactsContract;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
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)
return new ContactInfo();
InternetAddress address = (InternetAddress) addresses[0];
return new ContactInfo[]{new ContactInfo()};
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});
synchronized (emailContactInfo) {
ContactInfo info = emailContactInfo.get(key);

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

Loading…
Cancel
Save