Cache one favicon file

pull/200/head
M66B 4 years ago
parent 6b8b539b79
commit 410cb5be28

@ -387,16 +387,17 @@ public class ContactInfo {
File dir = new File(context.getCacheDir(), "favicons"); File dir = new File(context.getCacheDir(), "favicons");
if (!dir.exists()) if (!dir.exists())
dir.mkdir(); dir.mkdir();
File file = new File(dir, domain);
try { try {
// check cache // check cache
if (file.exists()) File verified = new File(dir, domain + "_verified");
if (file.length() == 0) File input = (verified.exists() ? verified : new File(dir, domain));
if (input.exists())
if (input.length() == 0)
Log.i("Favicon blacklisted domain=" + domain); Log.i("Favicon blacklisted domain=" + domain);
else { else {
info.bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); info.bitmap = BitmapFactory.decodeFile(input.getAbsolutePath());
info.verified = new File(dir, domain + "-verified").exists(); info.verified = input.getName().endsWith("_verified");
} }
else { else {
final int scaleToPixels = Helper.dp2pixels(context, FAVICON_ICON_SIZE); final int scaleToPixels = Helper.dp2pixels(context, FAVICON_ICON_SIZE);
@ -622,11 +623,10 @@ public class ContactInfo {
throw ex; throw ex;
// Add to cache // Add to cache
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { File output = new File(dir, domain + (info.verified ? "_verified" : ""));
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) {
info.bitmap.compress(Bitmap.CompressFormat.PNG, 90, os); info.bitmap.compress(Bitmap.CompressFormat.PNG, 90, os);
} }
if (info.verified)
new File(dir, domain + "-verified").createNewFile();
} }
} catch (Throwable ex) { } catch (Throwable ex) {
if (isRecoverable(ex, context)) if (isRecoverable(ex, context))
@ -638,7 +638,7 @@ public class ContactInfo {
else else
Log.e(ex); Log.e(ex);
try { try {
file.createNewFile(); new File(dir, domain).createNewFile();
} catch (IOException ex1) { } catch (IOException ex1) {
Log.e(ex1); Log.e(ex1);
} }

Loading…
Cancel
Save