From 0838a10ef3c6210a640f51b6a80a90d280ab35da Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 21 Jun 2024 07:40:55 +0200 Subject: [PATCH] Simplified editing signatures inline --- .../eu/faircode/email/FragmentCompose.java | 31 +++++++++++++------ app/src/main/res/layout/fragment_compose.xml | 6 ++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 4d2e11cd3f..eba93bda69 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -824,6 +824,7 @@ public class FragmentCompose extends FragmentBase { Object tag = cbSignature.getTag(); if (tag == null || !tag.equals(checked)) { cbSignature.setTag(checked); + ibSignature.setEnabled(checked); tvSignature.setAlpha(checked ? 1.0f : Helper.LOW_LIGHT); if (tag != null) { Bundle extras = new Bundle(); @@ -841,18 +842,27 @@ public class FragmentCompose extends FragmentBase { if (identity == null || TextUtils.isEmpty(identity.signature)) return; - ClipboardManager clipboard = Helper.getSystemService(v.getContext(), ClipboardManager.class); - if (clipboard == null) - return; + Document d = HtmlHelper.sanitizeCompose(v.getContext(), identity.signature, true); + SpannableStringBuilder spanned = HtmlHelper.fromDocument(v.getContext(), d, new HtmlHelper.ImageGetterEx() { + @Override + public Drawable getDrawable(Element element) { + return ImageHelper.decodeImage(v.getContext(), + working, element, true, zoom, 1.0f, etBody); + } + }, null); + if (spanned.length() > 0 && spanned.charAt(spanned.length() - 1) != '\n') + spanned.append('\n'); - ClipData clip = ClipData.newHtmlText( - v.getContext().getString(R.string.title_edit_signature_text), - HtmlHelper.getText(v.getContext(), identity.signature), - identity.signature); - clipboard.setPrimaryClip(clip); + Editable edit = etBody.getText(); + if (edit.length() > 0 && edit.charAt(edit.length() - 1) != '\n') + edit.append('\n'); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) - ToastEx.makeText(v.getContext(), R.string.title_clipboard_copied, Toast.LENGTH_LONG).show(); + int start = edit.length(); + edit.append(spanned); + etBody.setSelection(start); + + cbSignature.setChecked(false); + ibSignature.setEnabled(false); } }); @@ -7960,6 +7970,7 @@ public class FragmentCompose extends FragmentBase { ivMarkdown.setVisibility(markdown ? View.VISIBLE : View.GONE); cbSignature.setChecked(draft.signature); + ibSignature.setEnabled(draft.signature); tvSignature.setAlpha(draft.signature ? 1.0f : Helper.LOW_LIGHT); boolean ref_has_images = args.getBoolean("ref_has_images"); diff --git a/app/src/main/res/layout/fragment_compose.xml b/app/src/main/res/layout/fragment_compose.xml index 089a0c1838..2cd0bb09ed 100644 --- a/app/src/main/res/layout/fragment_compose.xml +++ b/app/src/main/res/layout/fragment_compose.xml @@ -413,12 +413,12 @@ android:layout_marginTop="12dp" android:layout_marginEnd="6dp" android:background="?android:attr/selectableItemBackgroundBorderless" - android:contentDescription="@string/title_clipboard_copy" + android:contentDescription="@string/title_edit_signature" android:padding="3dp" - android:tooltipText="@string/title_clipboard_copy" + android:tooltipText="@string/title_edit_signature" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/cbSignature" - app:srcCompat="@drawable/twotone_file_copy_24" /> + app:srcCompat="@drawable/twotone_edit_24" />