Underline known contacts

This commit is contained in:
M66B 2019-10-02 13:36:07 +02:00
parent c380f7f683
commit fda65c1f24
3 changed files with 28 additions and 5 deletions

View File

@ -36,6 +36,7 @@ import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.AnimatedImageDrawable;
@ -189,6 +190,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean date;
private boolean threading;
private boolean distinguish_contacts;
private boolean name_email;
private boolean subject_top;
private boolean subject_italic;
@ -737,6 +739,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
outgoing = true;
Address[] addresses = (outgoing ? message.to : message.senders);
tvFrom.setText(MessageHelper.formatAddresses(addresses, name_email, false));
tvFrom.setPaintFlags(tvFrom.getPaintFlags() & ~Paint.UNDERLINE_TEXT_FLAG);
Long size = ("size".equals(sort) ? message.totalSize : message.size);
tvSize.setText(size == null ? null : Helper.humanReadableByteCount(size, true));
tvSize.setVisibility(size == null || (message.content && !"size".equals(sort)) ? View.GONE : View.VISIBLE);
@ -834,10 +837,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
// Contact info
ContactInfo info = ContactInfo.get(context, addresses, true);
ContactInfo info = ContactInfo.get(context, message.account, addresses, true);
if (info == null) {
Bundle aargs = new Bundle();
aargs.putLong("id", message.id);
aargs.putLong("account", message.account);
aargs.putSerializable("addresses", addresses);
new SimpleTask<ContactInfo>() {
@ -850,8 +854,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override
protected ContactInfo onExecute(Context context, Bundle args) {
long account = args.getLong("account");
Address[] addresses = (Address[]) args.getSerializable("addresses");
return ContactInfo.get(context, addresses, false);
return ContactInfo.get(context, account, addresses, false);
}
@Override
@ -987,6 +993,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ivAvatar.setVisibility(View.VISIBLE);
} else
ivAvatar.setVisibility(View.GONE);
if (distinguish_contacts && info.isKnown())
tvFrom.setPaintFlags(tvFrom.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
//tvFrom.setText(info.getDisplayName(name_email));
}
@ -3286,6 +3295,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.date = prefs.getBoolean("date", true);
this.threading = prefs.getBoolean("threading", true);
this.distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);
this.name_email = prefs.getBoolean("name_email", false);
this.subject_top = prefs.getBoolean("subject_top", false);
this.subject_italic = prefs.getBoolean("subject_italic", true);

View File

@ -57,10 +57,11 @@ public class ContactInfo {
private Bitmap bitmap;
private String displayName;
private Uri lookupUri;
private boolean known;
private long time;
private static Map<String, Uri> emailLookup = new ConcurrentHashMap<>();
private static Map<String, ContactInfo> emailContactInfo = new HashMap<>();
private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>();
private static final ExecutorService executor =
Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
@ -95,6 +96,10 @@ public class ContactInfo {
return lookupUri;
}
boolean isKnown() {
return known;
}
private boolean isExpired() {
return (new Date().getTime() - time > CACHE_CONTACT_DURATION);
}
@ -105,7 +110,7 @@ public class ContactInfo {
}
}
static ContactInfo get(Context context, Address[] addresses, boolean cacheOnly) {
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];
@ -155,6 +160,7 @@ public class ContactInfo {
info.displayName = cursor.getString(colDisplayName);
info.lookupUri = lookupUri;
info.known = true;
}
} catch (Throwable ex) {
Log.e(ex);
@ -216,6 +222,13 @@ public class ContactInfo {
if (info.displayName == null)
info.displayName = address.getPersonal();
if (!info.known) {
DB db = DB.getInstance(context);
EntityContact contact = db.contact().getContact(account, EntityContact.TYPE_TO, info.email);
info.known = (contact != null);
}
synchronized (emailContactInfo) {
emailContactInfo.put(key, info);
}

View File

@ -2682,7 +2682,7 @@ class Core {
// Get contact info
Map<TupleMessageEx, ContactInfo> messageContact = new HashMap<>();
for (TupleMessageEx message : messages)
messageContact.put(message, ContactInfo.get(context, message.from, false));
messageContact.put(message, ContactInfo.get(context, message.account, message.from, false));
// Summary notification
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || notify_summary) {