Underline known contacts

pull/162/head
M66B 6 years ago
parent c380f7f683
commit fda65c1f24

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

@ -57,10 +57,11 @@ public class ContactInfo {
private Bitmap bitmap; private Bitmap bitmap;
private String displayName; private String displayName;
private Uri lookupUri; private Uri lookupUri;
private boolean known;
private long time; private long time;
private static Map<String, Uri> emailLookup = new ConcurrentHashMap<>(); 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 = private static final ExecutorService executor =
Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
@ -95,6 +96,10 @@ public class ContactInfo {
return lookupUri; return lookupUri;
} }
boolean isKnown() {
return known;
}
private boolean isExpired() { private boolean isExpired() {
return (new Date().getTime() - time > CACHE_CONTACT_DURATION); 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) if (addresses == null || addresses.length == 0)
return new ContactInfo(); return new ContactInfo();
InternetAddress address = (InternetAddress) addresses[0]; InternetAddress address = (InternetAddress) addresses[0];
@ -155,6 +160,7 @@ public class ContactInfo {
info.displayName = cursor.getString(colDisplayName); info.displayName = cursor.getString(colDisplayName);
info.lookupUri = lookupUri; info.lookupUri = lookupUri;
info.known = true;
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -216,6 +222,13 @@ public class ContactInfo {
if (info.displayName == null) if (info.displayName == null)
info.displayName = address.getPersonal(); 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) { synchronized (emailContactInfo) {
emailContactInfo.put(key, info); emailContactInfo.put(key, info);
} }

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

Loading…
Cancel
Save