From e446dcedadfade96eee6290bde3242ef1f8b0a88 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 20 Nov 2020 14:35:07 +0100 Subject: [PATCH] Added bottom posting --- .../eu/faircode/email/FragmentCompose.java | 34 ++++++++++++++----- .../faircode/email/FragmentOptionsSend.java | 12 ++++++- .../main/res/layout/fragment_options_send.xml | 14 +++++++- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index efdbdd8046..20b0b4e009 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -3358,6 +3358,7 @@ public class FragmentCompose extends FragmentBase { boolean sign_default = prefs.getBoolean("sign_default", false); boolean encrypt_default = prefs.getBoolean("encrypt_default", false); boolean receipt_default = prefs.getBoolean("receipt_default", false); + boolean write_below = prefs.getBoolean("write_below", false); Log.i("Load draft action=" + action + " id=" + id + " reference=" + reference); @@ -3834,7 +3835,10 @@ public class FragmentCompose extends FragmentBase { e.tagName(quote ? "blockquote" : "p"); reply.appendChild(e); - document.body().appendChild(reply); + if (write_below) + document.body().prependChild(reply); + else + document.body().appendChild(reply); addSignature(context, document, data.draft, selected); } @@ -4003,7 +4007,10 @@ public class FragmentCompose extends FragmentBase { Document document = HtmlHelper.sanitizeCompose(context, doc.html(), true); for (Element e : ref) - document.body().appendChild(e); + if (write_below) + document.body().prependChild(e); + else + document.body().appendChild(e); EntityIdentity identity = null; if (data.draft.identity != null) @@ -4451,12 +4458,16 @@ public class FragmentCompose extends FragmentBase { // Get saved body Document d; + boolean write_below = prefs.getBoolean("write_below", false); if (extras != null && extras.containsKey("html")) { // Save current revision Document c = JsoupEx.parse(body); for (Element e : ref) - c.body().appendChild(e); + if (write_below) + c.body().prependChild(e); + else + c.body().appendChild(e); addSignature(context, c, draft, identity); @@ -4467,7 +4478,10 @@ public class FragmentCompose extends FragmentBase { d = HtmlHelper.sanitizeCompose(context, body, true); for (Element e : ref) - d.body().appendChild(e); + if (write_below) + d.body().prependChild(e); + else + d.body().appendChild(e); addSignature(context, d, draft, identity); } @@ -4977,6 +4991,7 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int signature_location = prefs.getInt("signature_location", 1); boolean usenet = prefs.getBoolean("usenet_signature", false); + boolean write_below = prefs.getBoolean("write_below", false); Element div = document.createElement("div"); div.attr("fairemail", "signature"); @@ -4992,12 +5007,15 @@ public class FragmentCompose extends FragmentBase { div.append(identity.signature); Elements ref = document.select("div[fairemail=reference]"); - if (signature_location == 0) + if (signature_location == 0) // top document.body().prependChild(div); - else if (ref.size() == 0 || signature_location == 2) + else if (ref.size() == 0 || signature_location == 2) // bottom document.body().appendChild(div); - else if (signature_location == 1) - ref.first().before(div); + else if (signature_location == 1) // between + if (write_below) + ref.last().after(div); + else + ref.first().before(div); } private void showDraft(final EntityMessage draft, final boolean scroll) { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 8e4f4696ee..a52c9b5597 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -54,6 +54,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swPrefixOnce; private SwitchCompat swSeparateReply; private SwitchCompat swExtendedReply; + private SwitchCompat swWriteBelow; private SwitchCompat swQuoteReply; private SwitchCompat swQuoteLimit; private SwitchCompat swResizeReply; @@ -73,7 +74,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private final static String[] RESET_OPTIONS = new String[]{ "keyboard", "suggest_sent", "suggested_received", "suggest_frequently", "send_reminders", "send_delayed", - "compose_font", "prefix_once", "separate_reply", "extended_reply", "quote_reply", "quote_limit", "resize_reply", + "compose_font", "prefix_once", "separate_reply", "extended_reply", "write_below", "quote_reply", "quote_limit", "resize_reply", "signature_location", "signature_reply", "signature_forward", "discard_delete", "plain_only", "format_flowed", "usenet_signature", "remove_signatures", @@ -102,6 +103,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swPrefixOnce = view.findViewById(R.id.swPrefixOnce); swSeparateReply = view.findViewById(R.id.swSeparateReply); swExtendedReply = view.findViewById(R.id.swExtendedReply); + swWriteBelow = view.findViewById(R.id.swWriteBelow); swQuoteReply = view.findViewById(R.id.swQuoteReply); swQuoteLimit = view.findViewById(R.id.swQuoteLimit); swResizeReply = view.findViewById(R.id.swResizeReply); @@ -228,6 +230,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); + swWriteBelow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("write_below", checked).apply(); + } + }); + swQuoteReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -409,6 +418,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", true)); swSeparateReply.setChecked(prefs.getBoolean("separate_reply", false)); swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false)); + swWriteBelow.setChecked(prefs.getBoolean("write_below", false)); swQuoteReply.setChecked(prefs.getBoolean("quote_reply", true)); swQuoteLimit.setChecked(prefs.getBoolean("quote_limit", true)); swResizeReply.setChecked(prefs.getBoolean("resize_reply", true)); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index c1e2b26b47..46073b13b2 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -225,6 +225,18 @@ app:layout_constraintTop_toBottomOf="@id/swSeparateReply" app:switchPadding="12dp" /> + +