From a327809c6c6667eb18f94d4dfca47b773d74f582 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 23 Feb 2020 16:39:43 +0100 Subject: [PATCH] Keep changes on switching from/to signature HTML --- .../eu/faircode/email/ActivitySignature.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySignature.java b/app/src/main/java/eu/faircode/email/ActivitySignature.java index bb7179097d..43c7a316a0 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySignature.java +++ b/app/src/main/java/eu/faircode/email/ActivitySignature.java @@ -26,9 +26,11 @@ import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; +import android.text.Editable; import android.text.Html; import android.text.SpannableStringBuilder; import android.text.Spanned; +import android.text.TextWatcher; import android.text.style.ImageSpan; import android.view.LayoutInflater; import android.view.Menu; @@ -53,6 +55,7 @@ public class ActivitySignature extends ActivityBase { private BottomNavigationView bottom_navigation; private boolean raw = false; + private boolean dirty = false; private static final int REQUEST_IMAGE = 1; @@ -77,6 +80,23 @@ public class ActivitySignature extends ActivityBase { } }); + etText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // Do nothing + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + dirty = true; + } + + @Override + public void afterTextChanged(Editable s) { + // Do nothing + } + }); + style_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { @@ -136,8 +156,7 @@ public class ActivitySignature extends ActivityBase { switch (item.getItemId()) { case R.id.menu_edit_html: item.setChecked(!item.isChecked()); - raw = item.isChecked(); - load(); + html(item.isChecked()); return true; default: return super.onOptionsItemSelected(item); @@ -173,6 +192,7 @@ public class ActivitySignature extends ActivityBase { return getDrawableByUri(ActivitySignature.this, Uri.parse(source)); } }, null)); + dirty = false; } private void delete() { @@ -191,6 +211,17 @@ public class ActivitySignature extends ActivityBase { finish(); } + private void html(boolean raw) { + this.raw = raw; + + if (!raw || dirty) { + String html = (raw ? HtmlHelper.toHtml(etText.getText()) : etText.getText().toString()); + getIntent().putExtra("html", html); + } + + load(); + } + private void insertImage() { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE);