From 37d8194d60d0b4dca3b4782b913d486a011edb41 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 17 Oct 2023 08:53:42 +0200 Subject: [PATCH] Added option to suggest contacts of the current account only --- .../eu/faircode/email/FragmentCompose.java | 9 +++++-- .../faircode/email/FragmentOptionsSend.java | 15 ++++++++++- .../main/res/layout/fragment_options_send.xml | 27 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 8ccb55b64f..d0033596ba 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -299,6 +299,7 @@ public class FragmentCompose extends FragmentBase { private boolean lt_sentence; private boolean lt_auto; + private Long account = null; private long working = -1; private State state = State.NONE; private boolean show_images = false; @@ -445,6 +446,7 @@ public class FragmentCompose extends FragmentBase { final boolean suggest_sent = prefs.getBoolean("suggest_sent", true); final boolean suggest_received = prefs.getBoolean("suggest_received", false); final boolean suggest_frequently = prefs.getBoolean("suggest_frequently", false); + final boolean suggest_account = prefs.getBoolean("suggest_account", false); final boolean cc_bcc = prefs.getBoolean("cc_bcc", false); final boolean circular = prefs.getBoolean("circular", true); @@ -1236,9 +1238,11 @@ public class FragmentCompose extends FragmentBase { List items = new ArrayList<>(); if (suggest_sent) - items.addAll(db.contact().searchContacts(null, EntityContact.TYPE_TO, wildcard)); + items.addAll(db.contact().searchContacts( + suggest_account ? FragmentCompose.this.account : null, EntityContact.TYPE_TO, wildcard)); if (suggest_received) - for (EntityContact item : db.contact().searchContacts(null, EntityContact.TYPE_FROM, wildcard)) + for (EntityContact item : db.contact().searchContacts( + suggest_account ? FragmentCompose.this.account : null, EntityContact.TYPE_FROM, wildcard)) if (!MessageHelper.isNoReply(item.email)) items.add(item); for (EntityContact item : items) { @@ -7868,6 +7872,7 @@ public class FragmentCompose extends FragmentBase { public void onItemSelected(AdapterView parent, View view, int position, long id) { final Context context = parent.getContext(); TupleIdentityEx identity = (TupleIdentityEx) parent.getAdapter().getItem(position); + FragmentCompose.this.account = (identity == null ? null : identity.account); int at = (identity == null ? -1 : identity.email.indexOf('@')); etExtra.setHint(at < 0 ? null : identity.email.substring(0, at)); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 27f4d3c8a9..45194b7d10 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -69,6 +69,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swSuggestSent; private SwitchCompat swSuggestReceived; private SwitchCompat swSuggestFrequently; + private SwitchCompat swSuggestAccount; private SwitchCompat swAutoIdentity; private Button btnLocalContacts; private SwitchCompat swSendChips; @@ -121,7 +122,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private final static String[] RESET_OPTIONS = new String[]{ "keyboard", "keyboard_no_fullscreen", - "suggest_names", "suggest_sent", "suggested_received", "suggest_frequently", "auto_identity", + "suggest_names", "suggest_sent", "suggested_received", "suggest_frequently", "suggest_account", "auto_identity", "send_reminders", "send_chips", "send_nav_color", "send_pending", "auto_save_paragraph", "auto_save_dot", "discard_delete", "send_delayed", @@ -156,6 +157,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swSuggestSent = view.findViewById(R.id.swSuggestSent); swSuggestReceived = view.findViewById(R.id.swSuggestReceived); swSuggestFrequently = view.findViewById(R.id.swSuggestFrequently); + swSuggestAccount = view.findViewById(R.id.swSuggestAccount); swAutoIdentity = view.findViewById(R.id.swAutoIdentity); btnLocalContacts = view.findViewById(R.id.btnLocalContacts); swSendChips = view.findViewById(R.id.swSendChips); @@ -261,6 +263,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("suggest_sent", checked).apply(); swSuggestFrequently.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); + swSuggestAccount.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); swAutoIdentity.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); } }); @@ -270,6 +273,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("suggest_received", checked).apply(); swSuggestFrequently.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); + swSuggestAccount.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); swAutoIdentity.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); } }); @@ -281,6 +285,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); + swSuggestAccount.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("suggest_account", checked).apply(); + } + }); + swAutoIdentity.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -762,6 +773,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swSuggestReceived.setChecked(prefs.getBoolean("suggest_received", false)); swSuggestFrequently.setChecked(prefs.getBoolean("suggest_frequently", false)); swSuggestFrequently.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); + swSuggestAccount.setChecked(prefs.getBoolean("suggest_account", false)); + swSuggestAccount.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); swAutoIdentity.setChecked(prefs.getBoolean("auto_identity", false)); swAutoIdentity.setEnabled(swSuggestSent.isChecked() || swSuggestReceived.isChecked()); swSendChips.setChecked(prefs.getBoolean("send_chips", true)); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index 80de192b3b..a5f8015206 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -182,6 +182,31 @@ app:layout_constraintTop_toBottomOf="@id/swSuggestReceived" app:switchPadding="12dp" /> + + + + Suggest addresses found in sent messages Suggest addresses found in received messages Sort suggested addresses on frequency of use + Limit suggestions to current account Alternative reply/forward prefix Show address bubbles Use the identity color for the bottom action bar @@ -967,6 +968,7 @@ If disabled, only email addresses will be used when selecting contacts In addition to contacts provided by Android. Contact data will be stored for newly sent or received messages only when enabled. + This only applies to local contacts because contacts in the Android address book are not linked to specific accounts This will select the last identity used when selecting a recipient for new messages Show a warning when the message text or the subject is empty or when an attachment might be missing The email server could still add the messages to the sent message folder