mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-29 11:15:51 +00:00
Use cached anonymous contact info
This commit is contained in:
parent
a1679e9ac4
commit
1e6d41ce10
1 changed files with 49 additions and 4 deletions
|
@ -29,6 +29,7 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
|
@ -97,6 +98,8 @@ public class ContactInfo {
|
|||
|
||||
static final int FAVICON_READ_BYTES = 50 * 1024;
|
||||
|
||||
private static final Object lock = new Object();
|
||||
private static ContactInfo anonymous = null;
|
||||
private static Map<String, Lookup> emailLookup = new ConcurrentHashMap<>();
|
||||
private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>();
|
||||
|
||||
|
@ -226,14 +229,27 @@ public class ContactInfo {
|
|||
}
|
||||
|
||||
private static ContactInfo[] get(Context context, long account, String folderType, String selector, Address[] addresses, boolean cacheOnly) {
|
||||
if (addresses == null || addresses.length == 0)
|
||||
return new ContactInfo[]{new ContactInfo()};
|
||||
if (addresses == null || addresses.length == 0) {
|
||||
ContactInfo anonymous = getAnonymous(context);
|
||||
return new ContactInfo[]{anonymous == null ? new ContactInfo() : anonymous};
|
||||
}
|
||||
|
||||
ContactInfo[] result = new ContactInfo[addresses.length];
|
||||
for (int i = 0; i < addresses.length; i++) {
|
||||
result[i] = _get(context, account, folderType, selector, (InternetAddress) addresses[i], cacheOnly);
|
||||
if (result[i] == null)
|
||||
if (result[i] == null) {
|
||||
if (cacheOnly)
|
||||
return null;
|
||||
ContactInfo anonymous = getAnonymous(context);
|
||||
if (anonymous == null)
|
||||
return null;
|
||||
result[i] = anonymous;
|
||||
} else if (result[i].bitmap == null) {
|
||||
if (!cacheOnly) {
|
||||
ContactInfo anonymous = getAnonymous(context);
|
||||
result[i].bitmap = (anonymous == null ? null : anonymous.bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -577,6 +593,35 @@ public class ContactInfo {
|
|||
return info;
|
||||
}
|
||||
|
||||
private static ContactInfo getAnonymous(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean avatars = prefs.getBoolean("avatars", true);
|
||||
boolean bimi = (prefs.getBoolean("bimi", false) && !BuildConfig.PLAY_STORE_RELEASE);
|
||||
boolean gravatars = (prefs.getBoolean("gravatars", false) && !BuildConfig.PLAY_STORE_RELEASE);
|
||||
boolean libravatars = (prefs.getBoolean("libravatars", false) && !BuildConfig.PLAY_STORE_RELEASE);
|
||||
boolean favicons = prefs.getBoolean("favicons", false);
|
||||
boolean generated = prefs.getBoolean("generated_icons", true);
|
||||
boolean identicons = prefs.getBoolean("identicons", false);
|
||||
if (avatars || bimi || gravatars || libravatars || favicons || generated || identicons) {
|
||||
synchronized (lock) {
|
||||
if (anonymous == null) {
|
||||
Drawable d = context.getDrawable(R.drawable.twotone_person_24);
|
||||
Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
d.setTint(Helper.resolveColor(context, R.attr.colorSeparator));
|
||||
d.draw(canvas);
|
||||
|
||||
anonymous = new ContactInfo();
|
||||
anonymous.bitmap = bitmap;
|
||||
}
|
||||
return anonymous;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Favicon parseFavicon(URL base, int scaleToPixels, Context context) throws IOException {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean favicons_partial = prefs.getBoolean("favicons_partial", true);
|
||||
|
|
Loading…
Reference in a new issue