Allow removing inline images

This commit is contained in:
M66B 2020-06-22 13:12:20 +02:00
parent e6cf20a49a
commit 66eea4221a
3 changed files with 36 additions and 54 deletions

View File

@ -103,8 +103,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private void bindTo(EntityAttachment attachment) {
view.setAlpha(!attachment.isAttachment() ? Helper.LOW_LIGHT : 1.0f);
ibDelete.setVisibility(readonly ? View.GONE :
attachment.isInline() && attachment.error == null ? View.INVISIBLE : View.VISIBLE);
ibDelete.setVisibility(readonly ? View.GONE : View.VISIBLE);
int resid = 0;
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(attachment.getMimeType());

View File

@ -215,7 +215,6 @@ public class FragmentCompose extends FragmentBase {
private ImageButton ibCcBcc;
private RecyclerView rvAttachment;
private TextView tvNoInternetAttachments;
private ImageButton ibCloseUnusedImagesHint;
private EditTextCompose etBody;
private TextView tvNoInternet;
private TextView tvSignature;
@ -233,7 +232,6 @@ public class FragmentCompose extends FragmentBase {
private Group grpExtra;
private Group grpAddresses;
private Group grpAttachments;
private Group grpUnusedImagesHint;
private Group grpBody;
private Group grpSignature;
private Group grpReferenceHint;
@ -317,7 +315,6 @@ public class FragmentCompose extends FragmentBase {
ibCcBcc = view.findViewById(R.id.ivCcBcc);
rvAttachment = view.findViewById(R.id.rvAttachment);
tvNoInternetAttachments = view.findViewById(R.id.tvNoInternetAttachments);
ibCloseUnusedImagesHint = view.findViewById(R.id.ibCloseUnusedImagesHint);
etBody = view.findViewById(R.id.etBody);
tvNoInternet = view.findViewById(R.id.tvNoInternet);
tvSignature = view.findViewById(R.id.tvSignature);
@ -337,7 +334,6 @@ public class FragmentCompose extends FragmentBase {
grpAddresses = view.findViewById(R.id.grpAddresses);
grpAttachments = view.findViewById(R.id.grpAttachments);
grpBody = view.findViewById(R.id.grpBody);
grpUnusedImagesHint = view.findViewById(R.id.grpUnusedImagesHint);
grpSignature = view.findViewById(R.id.grpSignature);
grpReferenceHint = view.findViewById(R.id.grpReferenceHint);
@ -455,15 +451,6 @@ public class FragmentCompose extends FragmentBase {
setZoom();
ibCloseUnusedImagesHint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("inline_image_hint", false).apply();
grpUnusedImagesHint.setVisibility(View.GONE);
}
});
etBody.setInputContentListener(new EditTextCompose.IInputContentListener() {
@Override
public void onInputContent(Uri uri) {
@ -936,7 +923,6 @@ public class FragmentCompose extends FragmentBase {
rvAttachment.setAdapter(adapter);
tvNoInternetAttachments.setVisibility(View.GONE);
grpUnusedImagesHint.setVisibility(View.GONE);
final String pkg = Helper.getOpenKeychainPackage(getContext());
Log.i("PGP binding to " + pkg);
@ -3775,6 +3761,8 @@ public class FragmentCompose extends FragmentBase {
db.attachment().liveAttachments(data.draft.id).observe(getViewLifecycleOwner(),
new Observer<List<EntityAttachment>>() {
private Integer count = null;
@Override
public void onChanged(@Nullable List<EntityAttachment> 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();
}
});

View File

@ -235,31 +235,6 @@
app:layout_constraintStart_toStartOf="@id/rvAttachment"
app:layout_constraintTop_toBottomOf="@id/rvAttachment" />
<ImageButton
android:id="@+id/ibCloseUnusedImagesHint"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_no_format"
app:layout_constraintBottom_toBottomOf="@+id/tvUnusedImagesHint"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/tvUnusedImagesHint"
app:srcCompat="@drawable/baseline_close_24" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvUnusedImagesHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:text="@string/title_unused_inline"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ibCloseUnusedImagesHint"
app:layout_constraintTop_toBottomOf="@id/tvNoInternetAttachments" />
<View
android:id="@+id/vSeparator"
android:layout_width="0dp"
@ -268,7 +243,7 @@
android:background="?attr/colorSeparator"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ibCloseUnusedImagesHint" />
app:layout_constraintTop_toBottomOf="@+id/tvNoInternetAttachments" />
<eu.faircode.email.EditTextCompose
android:id="@+id/etBody"
@ -454,12 +429,6 @@
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAttachments,rvAttachment" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpUnusedImagesHint"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="ibCloseUnusedImagesHint,tvUnusedImagesHint" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpBody"
android:layout_width="0dp"