From ea5f9d7e28d87d333eae259a6f4a3d8eec0993d0 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 10 Dec 2020 20:56:47 +0100 Subject: [PATCH] Get favicons for top domains --- .../java/eu/faircode/email/ContactInfo.java | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ContactInfo.java b/app/src/main/java/eu/faircode/email/ContactInfo.java index 07a4b310e2..15a84f5f48 100644 --- a/app/src/main/java/eu/faircode/email/ContactInfo.java +++ b/app/src/main/java/eu/faircode/email/ContactInfo.java @@ -344,38 +344,45 @@ public class ContactInfo { info.bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); else { final int scaleToPixels = Helper.dp2pixels(context, 64); - final URL base = new URL("https://" + domain); - final URL www = new URL("https://www." + domain); List> futures = new ArrayList<>(); - futures.add(executorFavicon.submit(new Callable() { - @Override - public Bitmap call() throws Exception { - return parseFavicon(base, scaleToPixels); - } - })); + String host = domain; + while (host.indexOf('.') > 0) { + final URL base = new URL("https://" + host); + final URL www = new URL("https://www." + host); - futures.add(executorFavicon.submit(new Callable() { - @Override - public Bitmap call() throws Exception { - return parseFavicon(www, scaleToPixels); - } - })); + futures.add(executorFavicon.submit(new Callable() { + @Override + public Bitmap call() throws Exception { + return parseFavicon(base, scaleToPixels); + } + })); - futures.add(executorFavicon.submit(new Callable() { - @Override - public Bitmap call() throws Exception { - return getFavicon(new URL(base, "favicon.ico"), scaleToPixels); - } - })); + futures.add(executorFavicon.submit(new Callable() { + @Override + public Bitmap call() throws Exception { + return parseFavicon(www, scaleToPixels); + } + })); - futures.add(executorFavicon.submit(new Callable() { - @Override - public Bitmap call() throws Exception { - return getFavicon(new URL(www, "favicon.ico"), scaleToPixels); - } - })); + futures.add(executorFavicon.submit(new Callable() { + @Override + public Bitmap call() throws Exception { + return getFavicon(new URL(base, "favicon.ico"), scaleToPixels); + } + })); + + futures.add(executorFavicon.submit(new Callable() { + @Override + public Bitmap call() throws Exception { + return getFavicon(new URL(www, "favicon.ico"), scaleToPixels); + } + })); + + int dot = host.indexOf('.'); + host = host.substring(dot + 1); + } Throwable ex = null; for (Future future : futures)