From 2a6123dca664486d7ba4b32b1d07f98fa44b4399 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 28 Jun 2023 22:17:39 +0200 Subject: [PATCH] Fixed saving signature styles --- .../eu/faircode/email/ActivitySignature.java | 28 +++++++++++++++++++ .../java/eu/faircode/email/StyleHelper.java | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySignature.java b/app/src/main/java/eu/faircode/email/ActivitySignature.java index 99f38a11e9..7a30d5410a 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySignature.java +++ b/app/src/main/java/eu/faircode/email/ActivitySignature.java @@ -29,6 +29,8 @@ import android.net.Uri; import android.os.Bundle; import android.text.Editable; import android.text.Html; +import android.text.SpanWatcher; +import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; @@ -357,6 +359,32 @@ public class ActivitySignature extends ActivityBase { }, null); etText.setText(signature); } + + etText.getText().setSpan(new SpanWatcher() { + @Override + public void onSpanAdded(Spannable text, Object what, int start, int end) { + checkChanged(what); + } + + @Override + public void onSpanRemoved(Spannable text, Object what, int start, int end) { + checkChanged(what); + } + + @Override + public void onSpanChanged(Spannable text, Object what, int ostart, int oend, int nstart, int nend) { + checkChanged(what); + } + + private void checkChanged(Object what) { + for (Class cls : StyleHelper.CLEAR_STYLES) + if (cls.isAssignableFrom(what.getClass())) { + dirty = true; + saved = null; + } + } + }, 0, etText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + saved = html; loaded = true; } diff --git a/app/src/main/java/eu/faircode/email/StyleHelper.java b/app/src/main/java/eu/faircode/email/StyleHelper.java index 15b2aeeb65..1f8ec10d38 100644 --- a/app/src/main/java/eu/faircode/email/StyleHelper.java +++ b/app/src/main/java/eu/faircode/email/StyleHelper.java @@ -77,7 +77,7 @@ import java.util.List; import java.util.Locale; public class StyleHelper { - private static final List> CLEAR_STYLES = Collections.unmodifiableList(Arrays.asList( + static final List> CLEAR_STYLES = Collections.unmodifiableList(Arrays.asList( StyleSpan.class, UnderlineSpan.class, RelativeSizeSpan.class,