From 0afb68a0805c7db88f4ee7d82e18565a7e46b625 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 18 Apr 2022 10:43:35 +0200 Subject: [PATCH] Added option for signature on first reply only --- .../eu/faircode/email/FragmentCompose.java | 20 +++++++++++++++++++ .../faircode/email/FragmentOptionsSend.java | 14 ++++++++++++- .../main/res/layout/fragment_options_send.xml | 14 ++++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index b724d5138c..0dc4a98cbd 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -4926,6 +4926,26 @@ public class FragmentCompose extends FragmentBase { if (drafts == null) throw new IllegalArgumentException(context.getString(R.string.title_no_drafts)); + boolean signature_once = prefs.getBoolean("signature_reply_once", false); + if (signature_once && data.draft.signature && + ref != null && ref.thread != null && + ("reply".equals(action) || "reply_all".equals(action))) { + List outbound = new ArrayList<>(); + + EntityFolder sent = db.folder().getFolderByType(drafts.account, EntityFolder.SENT); + if (sent != null) + outbound.addAll(db.message().getMessagesByThread(drafts.account, ref.thread, null, sent.id)); + + EntityFolder outbox = db.folder().getOutbox(); + if (outbox != null) + outbound.addAll(db.message().getMessagesByThread(drafts.account, ref.thread, null, outbox.id)); + + if (outbound.size() > 0) { + Log.i("Signature suppressed"); + data.draft.signature = false; + } + } + data.draft.account = drafts.account; data.draft.folder = drafts.id; data.draft.identity = selected.id; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 95c47269e7..80f1877205 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -84,6 +84,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private Spinner spSignatureLocation; private SwitchCompat swSignatureNew; private SwitchCompat swSignatureReply; + private SwitchCompat swSignatureReplyOnce; private SwitchCompat swSignatureForward; private Button btnEditSignature; private SwitchCompat swDiscardDelete; @@ -106,7 +107,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "send_reminders", "send_chips", "send_delayed", "attach_new", "answer_action", "send_pending", "sound_sent", "compose_font", "prefix_once", "prefix_count", "separate_reply", "extended_reply", "write_below", "quote_reply", "quote_limit", "resize_reply", - "signature_location", "signature_new", "signature_reply", "signature_forward", + "signature_location", "signature_new", "signature_reply", "signature_reply_once", "signature_forward", "discard_delete", "reply_move", "auto_link", "plain_only", "format_flowed", "usenet_signature", "remove_signatures", "receipt_default", "receipt_type", "receipt_legacy", "lookup_mx" @@ -152,6 +153,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc spSignatureLocation = view.findViewById(R.id.spSignatureLocation); swSignatureNew = view.findViewById(R.id.swSignatureNew); swSignatureReply = view.findViewById(R.id.swSignatureReply); + swSignatureReplyOnce = view.findViewById(R.id.swSignatureReplyOnce); swSignatureForward = view.findViewById(R.id.swSignatureForward); btnEditSignature = view.findViewById(R.id.btnEditSignature); swDiscardDelete = view.findViewById(R.id.swDiscardDelete); @@ -434,6 +436,14 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("signature_reply", checked).apply(); + swSignatureReplyOnce.setEnabled(checked); + } + }); + + swSignatureReplyOnce.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("signature_reply_once", checked).apply(); } }); @@ -650,6 +660,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swSignatureNew.setChecked(prefs.getBoolean("signature_new", true)); swSignatureReply.setChecked(prefs.getBoolean("signature_reply", true)); + swSignatureReplyOnce.setChecked(prefs.getBoolean("signature_reply_once", false)); + swSignatureReplyOnce.setEnabled(swSignatureReply.isChecked()); swSignatureForward.setChecked(prefs.getBoolean("signature_forward", true)); swDiscardDelete.setChecked(prefs.getBoolean("discard_delete", true)); swReplyMove.setChecked(prefs.getBoolean("reply_move", false)); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index a6905f9271..964c69c244 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -574,6 +574,18 @@ app:layout_constraintTop_toBottomOf="@id/swSignatureNew" app:switchPadding="12dp" /> + +