Prefer rel=icon, refactoring

pull/190/head
M66B 5 years ago
parent 9d88abbe74
commit ab04b41c10

@ -40,6 +40,7 @@ import androidx.preference.PreferenceManager;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
@ -485,7 +486,7 @@ public class ContactInfo {
Document doc = JsoupEx.parse(response); Document doc = JsoupEx.parse(response);
// <link rel="canonical" href="" /> // Use canonical address
Element canonical = doc.head().select("link[rel=canonical]").first(); Element canonical = doc.head().select("link[rel=canonical]").first();
if (canonical != null) { if (canonical != null) {
String href = canonical.attr("href"); String href = canonical.attr("href");
@ -493,24 +494,27 @@ public class ContactInfo {
base = new URL(href); base = new URL(href);
} }
List<Future<Bitmap>> futures = new ArrayList<>(); // https://en.wikipedia.org/wiki/Favicon
Elements imgs = new Elements();
for (Element link : doc.head().select("link[href~=.*\\.(ico|png|gif|svg)]")) { for (Element link : doc.head().select("link[rel=icon]"))
String favicon = link.attr("href"); if (link.hasAttr("href"))
if (TextUtils.isEmpty(favicon)) imgs.add(link);
continue;
final URL url = new URL(base, favicon); for (Element link : doc.head().select("link[href~=.*\\.(ico|png|gif|svg)]"))
futures.add(executorFavicon.submit(new Callable<Bitmap>() { if (link.hasAttr("href") &&
@Override !"icon".equals(link.attr("rel")))
public Bitmap call() throws Exception { imgs.add(link);
return getFavicon(url, scaleToPixels);
} for (Element meta : doc.head().select("meta[itemprop=image]"))
})); if (meta.hasAttr("content"))
} imgs.add(meta);
for (Element meta : doc.head().select("meta[itemprop=image]")) { List<Future<Bitmap>> futures = new ArrayList<>();
String favicon = meta.attr("content"); for (Element img : imgs) {
String favicon = ("link".equals(img.tagName())
? img.attr("href")
: img.attr("content"));
if (TextUtils.isEmpty(favicon)) if (TextUtils.isEmpty(favicon))
continue; continue;
@ -527,7 +531,7 @@ public class ContactInfo {
try { try {
return future.get(); return future.get();
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.w(ex);
} }
return null; return null;

Loading…
Cancel
Save