mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-27 11:25:13 +01:00
Unified executor model
This commit is contained in:
@@ -75,7 +75,6 @@ import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.mail.Address;
|
||||
@@ -101,12 +100,6 @@ public class ContactInfo {
|
||||
private static Map<String, Lookup> emailLookup = new ConcurrentHashMap<>();
|
||||
private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>();
|
||||
|
||||
private static final ExecutorService executorLookup =
|
||||
Helper.getBackgroundExecutor(1, "contact");
|
||||
|
||||
private static final ExecutorService executorFavicon =
|
||||
Helper.getBackgroundExecutor(0, "favicon");
|
||||
|
||||
private static final int GENERATED_ICON_SIZE = 48; // dp
|
||||
private static final int FAVICON_ICON_SIZE = 64; // dp
|
||||
private static final int FAVICON_CONNECT_TIMEOUT = 5 * 1000; // milliseconds
|
||||
@@ -207,7 +200,7 @@ public class ContactInfo {
|
||||
|
||||
for (String type : new String[]{"favicons", "generated"}) {
|
||||
final File dir = new File(context.getFilesDir(), type);
|
||||
executorFavicon.submit(new Runnable() {
|
||||
Helper.getParallelExecutor().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -381,7 +374,7 @@ public class ContactInfo {
|
||||
List<Future<Favicon>> futures = new ArrayList<>();
|
||||
|
||||
if (bimi)
|
||||
futures.add(executorFavicon.submit(new Callable<Favicon>() {
|
||||
futures.add(Helper.getParallelExecutor().submit(new Callable<Favicon>() {
|
||||
@Override
|
||||
public Favicon call() throws Exception {
|
||||
Pair<Bitmap, Boolean> bimi =
|
||||
@@ -391,9 +384,9 @@ public class ContactInfo {
|
||||
}));
|
||||
|
||||
if (gravatars)
|
||||
futures.add(executorFavicon.submit(Avatar.getGravatar(email, scaleToPixels, context)));
|
||||
futures.add(Helper.getParallelExecutor().submit(Avatar.getGravatar(email, scaleToPixels, context)));
|
||||
if (libravatars)
|
||||
futures.add(executorFavicon.submit(Avatar.getLibravatar(email, scaleToPixels, context)));
|
||||
futures.add(Helper.getParallelExecutor().submit(Avatar.getLibravatar(email, scaleToPixels, context)));
|
||||
|
||||
if (favicons) {
|
||||
String host = domain;
|
||||
@@ -402,7 +395,7 @@ public class ContactInfo {
|
||||
while (host.indexOf('.') > 0) {
|
||||
final URL base = new URL("https://" + host);
|
||||
|
||||
futures.add(executorFavicon.submit(new Callable<Favicon>() {
|
||||
futures.add(Helper.getParallelExecutor().submit(new Callable<Favicon>() {
|
||||
@Override
|
||||
public Favicon call() throws Exception {
|
||||
return parseFavicon(base, scaleToPixels, context);
|
||||
@@ -420,7 +413,7 @@ public class ContactInfo {
|
||||
final URL base = new URL("https://" + host);
|
||||
|
||||
for (String name : FIXED_FAVICONS)
|
||||
futures.add(executorFavicon.submit(new Callable<Favicon>() {
|
||||
futures.add(Helper.getParallelExecutor().submit(new Callable<Favicon>() {
|
||||
@Override
|
||||
public Favicon call() throws Exception {
|
||||
return getFavicon(new URL(base, name), null, scaleToPixels, context);
|
||||
@@ -752,7 +745,7 @@ public class ContactInfo {
|
||||
continue;
|
||||
|
||||
final URL url = new URL(base, favicon);
|
||||
futures.add(executorFavicon.submit(new Callable<Pair<Favicon, URL>>() {
|
||||
futures.add(Helper.getParallelExecutor().submit(new Callable<Pair<Favicon, URL>>() {
|
||||
@Override
|
||||
public Pair<Favicon, URL> call() throws Exception {
|
||||
return new Pair(getFavicon(url, img.attr("type"), scaleToPixels, context), url);
|
||||
@@ -901,7 +894,7 @@ public class ContactInfo {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
Log.i("Contact changed uri=" + uri);
|
||||
executorLookup.submit(new Runnable() {
|
||||
Helper.getSerialExecutor().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -914,7 +907,7 @@ public class ContactInfo {
|
||||
}
|
||||
};
|
||||
|
||||
executorLookup.submit(new Runnable() {
|
||||
Helper.getSerialExecutor().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user