Improved image caching

pull/178/head
M66B 5 years ago
parent 304ed90fe0
commit aada937c74

@ -1882,7 +1882,7 @@ public class FragmentCompose extends FragmentBase {
new SimpleTask<Spanned>() { new SimpleTask<Spanned>() {
@Override @Override
protected Spanned onExecute(Context context, Bundle args) throws IOException { protected Spanned onExecute(Context context, Bundle args) throws IOException {
long id = args.getLong("id"); final long id = args.getLong("id");
List<Uri> uris = args.getParcelableArrayList("uris"); List<Uri> uris = args.getParcelableArrayList("uris");
boolean image = args.getBoolean("image"); boolean image = args.getBoolean("image");
int resize = args.getInt("resize"); int resize = args.getInt("resize");
@ -2637,7 +2637,7 @@ public class FragmentCompose extends FragmentBase {
Spanned spanned = HtmlHelper.fromHtml(text, new Html.ImageGetter() { Spanned spanned = HtmlHelper.fromHtml(text, new Html.ImageGetter() {
@Override @Override
public Drawable getDrawable(String source) { public Drawable getDrawable(String source) {
return ImageHelper.decodeImage(getContext(), -1, source, true, 0, etBody); return ImageHelper.decodeImage(getContext(), working, source, true, 0, etBody);
} }
}, null); }, null);
etBody.getText().insert(etBody.getSelectionStart(), spanned); etBody.getText().insert(etBody.getSelectionStart(), spanned);
@ -4572,7 +4572,7 @@ public class FragmentCompose extends FragmentBase {
signature = HtmlHelper.fromHtml(identity.signature, new Html.ImageGetter() { signature = HtmlHelper.fromHtml(identity.signature, new Html.ImageGetter() {
@Override @Override
public Drawable getDrawable(String source) { public Drawable getDrawable(String source) {
return ImageHelper.decodeImage(getContext(), -1, source, true, 0, tvSignature); return ImageHelper.decodeImage(getContext(), working, source, true, 0, tvSignature);
} }
}, null); }, null);
tvSignature.setText(signature); tvSignature.setText(signature);

@ -333,7 +333,7 @@ class ImageHelper {
return d; return d;
} }
if (!show || id < 0) { if (!show) {
// Show placeholder icon // Show placeholder icon
int resid = (embedded || data ? R.drawable.baseline_photo_library_24 : R.drawable.baseline_image_24); int resid = (embedded || data ? R.drawable.baseline_photo_library_24 : R.drawable.baseline_image_24);
Drawable d = res.getDrawable(resid, theme); Drawable d = res.getDrawable(resid, theme);
@ -513,6 +513,9 @@ class ImageHelper {
} }
private static Drawable getCachedImage(Context context, long id, String source) { private static Drawable getCachedImage(Context context, long id, String source) {
if (id < 0)
return null;
File file = getCacheFile(context, id, source); File file = getCacheFile(context, id, source);
if (file.exists()) { if (file.exists()) {
Log.i("Using cached " + file); Log.i("Using cached " + file);
@ -618,10 +621,12 @@ class ImageHelper {
Log.i("Downloaded image source=" + source); Log.i("Downloaded image source=" + source);
if (id >= 0) {
File file = getCacheFile(context, id, source); File file = getCacheFile(context, id, source);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
bm.compress(Bitmap.CompressFormat.PNG, 90, os); bm.compress(Bitmap.CompressFormat.PNG, 90, os);
} }
}
Drawable d = new BitmapDrawable(res, bm); Drawable d = new BitmapDrawable(res, bm);
d.setBounds(0, 0, Math.round(bm.getWidth() * dm.density), Math.round(bm.getHeight() * dm.density)); d.setBounds(0, 0, Math.round(bm.getWidth() * dm.density), Math.round(bm.getHeight() * dm.density));

Loading…
Cancel
Save