mirror of https://github.com/M66B/FairEmail.git
Allow removing inline images
This commit is contained in:
parent
e6cf20a49a
commit
66eea4221a
|
@ -103,8 +103,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
||||||
private void bindTo(EntityAttachment attachment) {
|
private void bindTo(EntityAttachment attachment) {
|
||||||
view.setAlpha(!attachment.isAttachment() ? Helper.LOW_LIGHT : 1.0f);
|
view.setAlpha(!attachment.isAttachment() ? Helper.LOW_LIGHT : 1.0f);
|
||||||
|
|
||||||
ibDelete.setVisibility(readonly ? View.GONE :
|
ibDelete.setVisibility(readonly ? View.GONE : View.VISIBLE);
|
||||||
attachment.isInline() && attachment.error == null ? View.INVISIBLE : View.VISIBLE);
|
|
||||||
|
|
||||||
int resid = 0;
|
int resid = 0;
|
||||||
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(attachment.getMimeType());
|
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(attachment.getMimeType());
|
||||||
|
|
|
@ -215,7 +215,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
private ImageButton ibCcBcc;
|
private ImageButton ibCcBcc;
|
||||||
private RecyclerView rvAttachment;
|
private RecyclerView rvAttachment;
|
||||||
private TextView tvNoInternetAttachments;
|
private TextView tvNoInternetAttachments;
|
||||||
private ImageButton ibCloseUnusedImagesHint;
|
|
||||||
private EditTextCompose etBody;
|
private EditTextCompose etBody;
|
||||||
private TextView tvNoInternet;
|
private TextView tvNoInternet;
|
||||||
private TextView tvSignature;
|
private TextView tvSignature;
|
||||||
|
@ -233,7 +232,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
private Group grpExtra;
|
private Group grpExtra;
|
||||||
private Group grpAddresses;
|
private Group grpAddresses;
|
||||||
private Group grpAttachments;
|
private Group grpAttachments;
|
||||||
private Group grpUnusedImagesHint;
|
|
||||||
private Group grpBody;
|
private Group grpBody;
|
||||||
private Group grpSignature;
|
private Group grpSignature;
|
||||||
private Group grpReferenceHint;
|
private Group grpReferenceHint;
|
||||||
|
@ -317,7 +315,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
ibCcBcc = view.findViewById(R.id.ivCcBcc);
|
ibCcBcc = view.findViewById(R.id.ivCcBcc);
|
||||||
rvAttachment = view.findViewById(R.id.rvAttachment);
|
rvAttachment = view.findViewById(R.id.rvAttachment);
|
||||||
tvNoInternetAttachments = view.findViewById(R.id.tvNoInternetAttachments);
|
tvNoInternetAttachments = view.findViewById(R.id.tvNoInternetAttachments);
|
||||||
ibCloseUnusedImagesHint = view.findViewById(R.id.ibCloseUnusedImagesHint);
|
|
||||||
etBody = view.findViewById(R.id.etBody);
|
etBody = view.findViewById(R.id.etBody);
|
||||||
tvNoInternet = view.findViewById(R.id.tvNoInternet);
|
tvNoInternet = view.findViewById(R.id.tvNoInternet);
|
||||||
tvSignature = view.findViewById(R.id.tvSignature);
|
tvSignature = view.findViewById(R.id.tvSignature);
|
||||||
|
@ -337,7 +334,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
grpAddresses = view.findViewById(R.id.grpAddresses);
|
grpAddresses = view.findViewById(R.id.grpAddresses);
|
||||||
grpAttachments = view.findViewById(R.id.grpAttachments);
|
grpAttachments = view.findViewById(R.id.grpAttachments);
|
||||||
grpBody = view.findViewById(R.id.grpBody);
|
grpBody = view.findViewById(R.id.grpBody);
|
||||||
grpUnusedImagesHint = view.findViewById(R.id.grpUnusedImagesHint);
|
|
||||||
grpSignature = view.findViewById(R.id.grpSignature);
|
grpSignature = view.findViewById(R.id.grpSignature);
|
||||||
grpReferenceHint = view.findViewById(R.id.grpReferenceHint);
|
grpReferenceHint = view.findViewById(R.id.grpReferenceHint);
|
||||||
|
|
||||||
|
@ -455,15 +451,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
setZoom();
|
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() {
|
etBody.setInputContentListener(new EditTextCompose.IInputContentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onInputContent(Uri uri) {
|
public void onInputContent(Uri uri) {
|
||||||
|
@ -936,7 +923,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
rvAttachment.setAdapter(adapter);
|
rvAttachment.setAdapter(adapter);
|
||||||
|
|
||||||
tvNoInternetAttachments.setVisibility(View.GONE);
|
tvNoInternetAttachments.setVisibility(View.GONE);
|
||||||
grpUnusedImagesHint.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
final String pkg = Helper.getOpenKeychainPackage(getContext());
|
final String pkg = Helper.getOpenKeychainPackage(getContext());
|
||||||
Log.i("PGP binding to " + pkg);
|
Log.i("PGP binding to " + pkg);
|
||||||
|
@ -3775,6 +3761,8 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
db.attachment().liveAttachments(data.draft.id).observe(getViewLifecycleOwner(),
|
db.attachment().liveAttachments(data.draft.id).observe(getViewLifecycleOwner(),
|
||||||
new Observer<List<EntityAttachment>>() {
|
new Observer<List<EntityAttachment>>() {
|
||||||
|
private Integer count = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(@Nullable List<EntityAttachment> attachments) {
|
public void onChanged(@Nullable List<EntityAttachment> attachments) {
|
||||||
if (attachments == null)
|
if (attachments == null)
|
||||||
|
@ -3784,14 +3772,11 @@ public class FragmentCompose extends FragmentBase {
|
||||||
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
|
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
boolean downloading = false;
|
boolean downloading = false;
|
||||||
boolean inline_images = false;
|
|
||||||
for (EntityAttachment attachment : attachments) {
|
for (EntityAttachment attachment : attachments) {
|
||||||
if (attachment.isEncryption())
|
if (attachment.isEncryption())
|
||||||
continue;
|
continue;
|
||||||
if (attachment.progress != null)
|
if (attachment.progress != null)
|
||||||
downloading = true;
|
downloading = true;
|
||||||
if (attachment.isInline() && attachment.isImage())
|
|
||||||
inline_images = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("Attachments=" + attachments.size() + " downloading=" + downloading);
|
Log.i("Attachments=" + attachments.size() + " downloading=" + downloading);
|
||||||
|
@ -3799,9 +3784,38 @@ public class FragmentCompose extends FragmentBase {
|
||||||
rvAttachment.setTag(downloading);
|
rvAttachment.setTag(downloading);
|
||||||
checkInternet();
|
checkInternet();
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
if (count != null && count > attachments.size()) {
|
||||||
boolean inline_image_hint = prefs.getBoolean("inline_image_hint", true);
|
boolean updated = false;
|
||||||
grpUnusedImagesHint.setVisibility(inline_images && inline_image_hint ? View.VISIBLE : View.GONE);
|
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -235,31 +235,6 @@
|
||||||
app:layout_constraintStart_toStartOf="@id/rvAttachment"
|
app:layout_constraintStart_toStartOf="@id/rvAttachment"
|
||||||
app:layout_constraintTop_toBottomOf="@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
|
<View
|
||||||
android:id="@+id/vSeparator"
|
android:id="@+id/vSeparator"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
@ -268,7 +243,7 @@
|
||||||
android:background="?attr/colorSeparator"
|
android:background="?attr/colorSeparator"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/ibCloseUnusedImagesHint" />
|
app:layout_constraintTop_toBottomOf="@+id/tvNoInternetAttachments" />
|
||||||
|
|
||||||
<eu.faircode.email.EditTextCompose
|
<eu.faircode.email.EditTextCompose
|
||||||
android:id="@+id/etBody"
|
android:id="@+id/etBody"
|
||||||
|
@ -454,12 +429,6 @@
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:constraint_referenced_ids="vSeparatorAttachments,rvAttachment" />
|
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
|
<androidx.constraintlayout.widget.Group
|
||||||
android:id="@+id/grpBody"
|
android:id="@+id/grpBody"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
Loading…
Reference in New Issue