diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 77b7fa7c04..231f4a67a7 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -475,6 +475,7 @@ public class AdapterMessage extends RecyclerView.Adapter> drawableSize = new HashMap<>(); private SimpleTask taskContactInfo; @@ -757,31 +758,52 @@ public class AdapterMessage extends RecyclerView.Adapter p = drawableSize.get(d); + if (p == null || p.first == 0) + continue; + + float s = Math.min(bw / (float) p.first, scale); + properties.setScale(message.id, s); + + int w = Math.round(p.first * s); + int h = Math.round(p.second * s); + d.setBounds(0, 0, w, h); + } + + // Feedback + String perc = Math.round(scale) + " %"; if (toast != null) toast.cancel(); toast = ToastEx.makeText(context, perc, Toast.LENGTH_SHORT); toast.show(); } + return true; } }); } - if (accessibility) { view.setAccessibilityDelegate(accessibilityDelegateHeader); header.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); @@ -1948,6 +1970,8 @@ public class AdapterMessage extends RecyclerView.Adapter() { @Override protected void onPreExecute(Bundle args) { @@ -1966,6 +1990,7 @@ public class AdapterMessage extends RecyclerView.Adapter> map = new HashMap<>(); SpannableStringBuilder ssb = HtmlHelper.fromDocument(context, document, true, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { Drawable drawable = ImageHelper.decodeImage(context, message.id, source, show_images, zoom, tvBody); + Rect bounds = drawable.getBounds(); + map.put(drawable, new Pair<>(bounds.right, bounds.bottom)); + + bounds.right = Math.round(bounds.right * scale); + bounds.bottom = Math.round(bounds.bottom * scale); + drawable.setBounds(bounds); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (drawable instanceof AnimatedImageDrawable) @@ -2133,6 +2165,7 @@ public class AdapterMessage extends RecyclerView.Adapter kv = new HashMap<>(); final private Map> values = new HashMap<>(); + final private LongSparseArray scales = new LongSparseArray<>(); final private LongSparseArray sizes = new LongSparseArray<>(); final private LongSparseArray heights = new LongSparseArray<>(); final private LongSparseArray> positions = new LongSparseArray<>(); @@ -1645,6 +1646,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. handleExpand(message.id); } + @Override + public void setScale(long id, Float size) { + if (size == null) + scales.remove(id); + else + scales.put(id, size); + } + + @Override + public float getScale(long id, float defaultSize) { + return scales.get(id, defaultSize); + } + @Override public void setSize(long id, Float size) { if (size == null) @@ -3513,6 +3527,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. Log.i("Hidden id=" + id); for (String key : values.keySet()) values.get(key).remove(id); + scales.remove(id); sizes.remove(id); heights.remove(id); positions.remove(id);