Refactoring

pull/172/head
M66B 6 years ago
parent ac595df4a6
commit 53976a426f

@ -57,7 +57,7 @@ public class ContactInfo {
private static Map<String, Uri> emailLookup = new ConcurrentHashMap<>(); private static Map<String, Uri> emailLookup = new ConcurrentHashMap<>();
private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>(); private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>();
private static final Map<String, Gravatar> emailGravatar = new HashMap<>(); private static final Map<String, Avatar> emailGravatar = new HashMap<>();
private static final ExecutorService executor = private static final ExecutorService executor =
Helper.getBackgroundExecutor(1, "contact"); Helper.getBackgroundExecutor(1, "contact");
@ -173,8 +173,8 @@ public class ContactInfo {
if (gravatars) { if (gravatars) {
boolean lookup; boolean lookup;
synchronized (emailGravatar) { synchronized (emailGravatar) {
Gravatar g = emailGravatar.get(address.getAddress()); Avatar avatar = emailGravatar.get(address.getAddress());
lookup = (g == null || g.isExpired() || g.isAvailable()); lookup = (avatar == null || avatar.isExpired() || avatar.isAvailable());
} }
if (lookup) { if (lookup) {
@ -194,12 +194,14 @@ public class ContactInfo {
int status = urlConnection.getResponseCode(); int status = urlConnection.getResponseCode();
if (status == HttpURLConnection.HTTP_OK) { if (status == HttpURLConnection.HTTP_OK) {
info.bitmap = BitmapFactory.decodeStream(urlConnection.getInputStream()); info.bitmap = BitmapFactory.decodeStream(urlConnection.getInputStream());
// Positive reply
synchronized (emailGravatar) { synchronized (emailGravatar) {
emailGravatar.put(address.getAddress(), new Gravatar(true)); emailGravatar.put(address.getAddress(), new Avatar(true));
} }
} else if (status == HttpURLConnection.HTTP_NOT_FOUND) { } else if (status == HttpURLConnection.HTTP_NOT_FOUND) {
// Negative reply
synchronized (emailGravatar) { synchronized (emailGravatar) {
emailGravatar.put(address.getAddress(), new Gravatar(false)); emailGravatar.put(address.getAddress(), new Avatar(false));
} }
} else } else
throw new IOException("HTTP status=" + status); throw new IOException("HTTP status=" + status);
@ -334,11 +336,11 @@ public class ContactInfo {
return all; return all;
} }
private static class Gravatar { private static class Avatar {
private boolean available; private boolean available;
private long time; private long time;
Gravatar(boolean available) { Avatar(boolean available) {
this.available = available; this.available = available;
this.time = new Date().getTime(); this.time = new Date().getTime();
} }

Loading…
Cancel
Save