diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index f865ada467..c8bde5f235 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -144,6 +144,12 @@ public class ApplicationEx extends Application { editor.putBoolean("ascending_list", prefs.getBoolean("ascending", false)); editor.remove("ascending"); } + + } else if (version < 701) { + if (prefs.getBoolean("suggest_local", false)) { + editor.putBoolean("suggest_sent", true); + editor.remove("suggest_local"); + } } if (BuildConfig.DEBUG && false) { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 8525c64fff..6fcd5d8e23 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -528,16 +528,18 @@ public class FragmentCompose extends FragmentBase { }); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean suggest_local = prefs.getBoolean("suggest_local", false); + boolean suggest_sent = prefs.getBoolean("suggest_sent", false); + boolean suggest_received = prefs.getBoolean("suggest_received", false); cadapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence typed) { - Log.i("Searching provided contact=" + typed); + Log.i("Suggest contact=" + typed); String wildcard = "%" + typed + "%"; - boolean contacts = Helper.hasPermission(getContext(), Manifest.permission.READ_CONTACTS); - MatrixCursor provided = new MatrixCursor(new String[]{"_id", "name", "email"}); + List cursors = new ArrayList<>(); + MatrixCursor provided = new MatrixCursor(new String[]{"_id", "name", "email"}); + boolean contacts = Helper.hasPermission(getContext(), Manifest.permission.READ_CONTACTS); if (contacts) { Cursor cursor = resolver.query( ContactsContract.CommonDataKinds.Email.CONTENT_URI, @@ -553,18 +555,25 @@ public class FragmentCompose extends FragmentBase { "CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME + " NOT LIKE '%@%' THEN 0 ELSE 1 END" + ", " + ContactsContract.Contacts.DISPLAY_NAME + " COLLATE NOCASE" + ", " + ContactsContract.CommonDataKinds.Email.DATA + " COLLATE NOCASE"); + while (cursor != null && cursor.moveToNext()) provided.newRow() .add(cursor.getLong(0)) .add(cursor.getString(1)) .add(cursor.getString(2)); - - if (!suggest_local) - return provided; } + cursors.add(provided); + + if (suggest_sent) + cursors.add(db.contact().searchContacts(null, EntityContact.TYPE_TO, wildcard)); - Cursor local = db.contact().searchContacts(null, null, wildcard); - return new MergeCursor(new Cursor[]{provided, local}); + if (suggest_received) + cursors.add(db.contact().searchContacts(null, EntityContact.TYPE_FROM, wildcard)); + + if (cursors.size() == 1) + return cursors.get(0); + else + return new MergeCursor(cursors.toArray(new Cursor[0])); } }); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 56af281981..caedc87d9a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -41,7 +41,8 @@ import androidx.preference.PreferenceManager; public class FragmentOptionsSend extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private SwitchCompat swKeyboard; - private SwitchCompat swSuggestLocal; + private SwitchCompat swSuggestSent; + private SwitchCompat swSuggestReceived; private SwitchCompat swPrefixOnce; private SwitchCompat swPlainOnly; private SwitchCompat swUsenetSignature; @@ -52,7 +53,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private Spinner spSendDelayed; private final static String[] RESET_OPTIONS = new String[]{ - "keyboard", "suggest_local", "prefix_once", "plain_only", "usenet_signature", "autoresize", "resize", "lookup_mx", "send_delayed" + "keyboard", "suggest_sent", "suggested_received", "prefix_once", "plain_only", "usenet_signature", + "autoresize", "resize", "lookup_mx", "send_delayed" }; @Override @@ -66,7 +68,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc // Get controls swKeyboard = view.findViewById(R.id.swKeyboard); - swSuggestLocal = view.findViewById(R.id.swSuggestLocal); + swSuggestSent = view.findViewById(R.id.swSuggestSent); + swSuggestReceived = view.findViewById(R.id.swSuggestReceived); swPrefixOnce = view.findViewById(R.id.swPrefixOnce); swPlainOnly = view.findViewById(R.id.swPlainOnly); swUsenetSignature = view.findViewById(R.id.swUsenetSignature); @@ -89,10 +92,17 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); - swSuggestLocal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + swSuggestSent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("suggest_local", checked).apply(); + prefs.edit().putBoolean("suggest_sent", checked).apply(); + } + }); + + swSuggestReceived.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("suggest_received", checked).apply(); } }); @@ -206,7 +216,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); swKeyboard.setChecked(prefs.getBoolean("keyboard", true)); - swSuggestLocal.setChecked(prefs.getBoolean("suggest_local", false)); + swSuggestSent.setChecked(prefs.getBoolean("suggest_sent", false)); + swSuggestReceived.setChecked(prefs.getBoolean("suggest_received", false)); swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", true)); swPlainOnly.setChecked(prefs.getBoolean("plain_only", false)); swUsenetSignature.setChecked(prefs.getBoolean("usenet_signature", false)); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index b856c97bdf..20554732b0 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -31,16 +31,16 @@ app:layout_constraintTop_toTopOf="parent" app:switchPadding="12dp" /> - + app:layout_constraintTop_toBottomOf="@id/swKeyboard" /> + app:layout_constraintTop_toBottomOf="@id/tvSuggestLocal" /> + + + + Show keyboard by default Suggest locally stored contacts + Suggest addresses found in sent messages + Suggest addresses found in received messages Prefix subject only once on replying or forwarding Send plain text only by default Usenet signature convention