From 0cb92c12a728829f40e89147ecfcceae73a02400 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 24 Nov 2022 21:25:08 +0100 Subject: [PATCH] Signature editor: restore unchanged HTML --- .../eu/faircode/email/ActivitySignature.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySignature.java b/app/src/main/java/eu/faircode/email/ActivitySignature.java index 4323ab0036..e7be45c611 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySignature.java +++ b/app/src/main/java/eu/faircode/email/ActivitySignature.java @@ -70,6 +70,7 @@ public class ActivitySignature extends ActivityBase { private boolean loaded = false; private boolean dirty = false; + private String saved = null; private static final int REQUEST_IMAGE = 1; private static final int REQUEST_FILE = 2; @@ -111,8 +112,10 @@ public class ActivitySignature extends ActivityBase { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - if (loaded) + if (loaded) { dirty = true; + saved = null; + } } @Override @@ -207,8 +210,10 @@ public class ActivitySignature extends ActivityBase { if (savedInstanceState == null) { load(getIntent().getStringExtra("html")); dirty = false; - } else + } else { dirty = savedInstanceState.getBoolean("fair:dirty"); + saved = savedInstanceState.getString("fair:saved"); + } } @Override @@ -223,6 +228,7 @@ public class ActivitySignature extends ActivityBase { @Override protected void onSaveInstanceState(Bundle outState) { outState.putBoolean("fair:dirty", dirty); + outState.putString("fair:saved", saved); super.onSaveInstanceState(outState); } @@ -328,6 +334,7 @@ public class ActivitySignature extends ActivityBase { String html = (dirty ? getHtml() : getIntent().getStringExtra("html")); + tvHtmlRemark.setVisibility(raw ? View.VISIBLE : View.GONE); etText.setRaw(raw); etText.setTypeface(raw ? Typeface.MONOSPACE : Typeface.DEFAULT); @@ -340,9 +347,12 @@ public class ActivitySignature extends ActivityBase { private String getHtml() { etText.clearComposingText(); - if (etText.isRaw()) - return etText.getText().toString(); - else { + if (etText.isRaw()) { + saved = etText.getText().toString(); + return saved; + } else { + if (saved != null) + return saved; String html = HtmlHelper.toHtml(etText.getText(), this); Document d = JsoupEx.parse(html); return d.body().html();