diff --git a/app/src/main/java/eu/faircode/email/AdapterAttachment.java b/app/src/main/java/eu/faircode/email/AdapterAttachment.java index cad639ccb4..8df8b7abb4 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAttachment.java +++ b/app/src/main/java/eu/faircode/email/AdapterAttachment.java @@ -103,8 +103,7 @@ public class AdapterAttachment extends RecyclerView.Adapter>() { + private Integer count = null; + @Override public void onChanged(@Nullable List attachments) { if (attachments == null) @@ -3784,14 +3772,11 @@ public class FragmentCompose extends FragmentBase { grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE); boolean downloading = false; - boolean inline_images = false; for (EntityAttachment attachment : attachments) { if (attachment.isEncryption()) continue; if (attachment.progress != null) downloading = true; - if (attachment.isInline() && attachment.isImage()) - inline_images = true; } Log.i("Attachments=" + attachments.size() + " downloading=" + downloading); @@ -3799,9 +3784,38 @@ public class FragmentCompose extends FragmentBase { rvAttachment.setTag(downloading); checkInternet(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean inline_image_hint = prefs.getBoolean("inline_image_hint", true); - grpUnusedImagesHint.setVisibility(inline_images && inline_image_hint ? View.VISIBLE : View.GONE); + if (count != null && count > attachments.size()) { + boolean updated = false; + Editable edit = etBody.getEditableText(); + + ImageSpan[] spans = edit.getSpans(0, edit.length(), ImageSpan.class); + for (int i = 0; i < spans.length && !updated; i++) { + ImageSpan span = spans[i]; + String source = span.getSource(); + if (source != null && source.startsWith("cid:")) { + String cid = "<" + source.substring(4) + ">"; + boolean found = false; + for (EntityAttachment attachment : attachments) + if (cid.equals(attachment.cid)) { + found = true; + break; + } + + if (!found) { + updated = true; + int start = edit.getSpanStart(span); + int end = edit.getSpanEnd(span); + edit.removeSpan(span); + edit.delete(start, end); + } + } + } + + if (updated) + etBody.setText(edit); + } + + count = attachments.size(); } }); diff --git a/app/src/main/res/layout/fragment_compose.xml b/app/src/main/res/layout/fragment_compose.xml index 43e7ab9e49..dba406b9ca 100644 --- a/app/src/main/res/layout/fragment_compose.xml +++ b/app/src/main/res/layout/fragment_compose.xml @@ -235,31 +235,6 @@ app:layout_constraintStart_toStartOf="@id/rvAttachment" app:layout_constraintTop_toBottomOf="@id/rvAttachment" /> - - - - + app:layout_constraintTop_toBottomOf="@+id/tvNoInternetAttachments" /> - -