From 206c84bfb018b2d6c76a100d2a633e48a1309838 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 24 Mar 2020 20:55:59 +0100 Subject: [PATCH] Select add/edit contact --- .../eu/faircode/email/AdapterMessage.java | 108 +++++++++++++----- .../eu/faircode/email/FragmentMessages.java | 30 +++++ app/src/main/res/values/strings.xml | 2 + 3 files changed, 112 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 7fa3481fd3..2e4fbdbf42 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -1356,7 +1356,7 @@ public class AdapterMessage extends RecyclerView.Adapter kv = new HashMap<>(); private Map> values = new HashMap<>(); private LongSparseArray sizes = new LongSparseArray<>(); private LongSparseArray heights = new LongSparseArray<>(); @@ -317,6 +320,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private static final int REQUEST_ACCOUNT = 19; private static final int REQUEST_EMPTY_FOLDER = 20; private static final int REQUEST_BOUNDARY_RETRY = 21; + static final int REQUEST_PICK_CONTACT = 22; static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW"; static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT"; @@ -1388,6 +1392,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private AdapterMessage.IProperties iProperties = new AdapterMessage.IProperties() { + @Override + public void setValue(String key, String value) { + kv.put(key, value); + } + @Override public void setValue(String name, long id, boolean enabled) { if (!values.containsKey(name)) @@ -4867,6 +4876,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. if (resultCode == RESULT_OK) onBoundaryRetry(); break; + case REQUEST_PICK_CONTACT: + if (resultCode == RESULT_OK && data != null) + onPickContact(data.getData()); + break; } } catch (Throwable ex) { Log.e(ex); @@ -6365,6 +6378,23 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. model.retry(viewType); } + private void onPickContact(Uri contactUri) { + String name = kv.get("name"); + String email = kv.get("email"); + + // This requires contacts permission + ContentResolver resolver = getContext().getContentResolver(); + Uri lookupUri = ContactsContract.Contacts.getLookupUri(resolver, contactUri); + + Intent edit = new Intent(); + edit.putExtra(ContactsContract.Intents.Insert.EMAIL, email); + if (!TextUtils.isEmpty(name)) + edit.putExtra(ContactsContract.Intents.Insert.NAME, name); + edit.setAction(Intent.ACTION_EDIT); + edit.setDataAndTypeAndNormalize(lookupUri, ContactsContract.Contacts.CONTENT_ITEM_TYPE); + startActivity(edit); + } + static void search( final Context context, final LifecycleOwner owner, final FragmentManager manager, long account, long folder, boolean server, String query) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a85d9fbff0..3ec8b19209 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -620,6 +620,8 @@ Create notification channel Edit notification channel Delete notification channel + Add contact + Edit contact Create sub folder Delete all local trashed messages permanently?