|
|
|
@ -1356,7 +1356,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|
|
|
|
ibSearchContact.setVisibility(show_addresses && (hasFrom || hasTo) ? View.VISIBLE : View.GONE);
|
|
|
|
|
ibNotifyContact.setVisibility(show_addresses && hasChannel && hasFrom ? View.VISIBLE : View.GONE);
|
|
|
|
|
ibPinContact.setVisibility(show_addresses && pin && hasFrom ? View.VISIBLE : View.GONE);
|
|
|
|
|
ibAddContact.setVisibility(show_addresses && contacts && hasFrom ? View.VISIBLE : View.GONE);
|
|
|
|
|
ibAddContact.setVisibility(show_addresses && hasFrom ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
|
|
tvSubmitterTitle.setVisibility(show_addresses && !TextUtils.isEmpty(submitter) ? View.VISIBLE : View.GONE);
|
|
|
|
|
tvSubmitter.setVisibility(show_addresses && !TextUtils.isEmpty(submitter) ? View.VISIBLE : View.GONE);
|
|
|
|
@ -3036,26 +3036,22 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onAddContact(TupleMessageEx message) {
|
|
|
|
|
for (Address address : message.from) {
|
|
|
|
|
InternetAddress ia = (InternetAddress) address;
|
|
|
|
|
String name = ia.getPersonal();
|
|
|
|
|
String email = ia.getAddress();
|
|
|
|
|
|
|
|
|
|
// https://developer.android.com/training/contacts-provider/modify-data
|
|
|
|
|
Intent edit = new Intent();
|
|
|
|
|
if (!TextUtils.isEmpty(name))
|
|
|
|
|
edit.putExtra(ContactsContract.Intents.Insert.NAME, name);
|
|
|
|
|
if (!TextUtils.isEmpty(email))
|
|
|
|
|
edit.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
|
|
|
|
|
InternetAddress ia = (InternetAddress) message.from[0];
|
|
|
|
|
String name = ia.getPersonal();
|
|
|
|
|
String email = ia.getAddress();
|
|
|
|
|
|
|
|
|
|
Uri lookupUri = null;
|
|
|
|
|
if (contacts) {
|
|
|
|
|
String like = "%" + (name == null ? email : name) + "%";
|
|
|
|
|
ContentResolver resolver = context.getContentResolver();
|
|
|
|
|
try (Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
|
|
|
|
new String[]{
|
|
|
|
|
ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
|
|
|
|
|
ContactsContract.Contacts.LOOKUP_KEY
|
|
|
|
|
},
|
|
|
|
|
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
|
|
|
|
|
new String[]{email}, null)) {
|
|
|
|
|
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?" +
|
|
|
|
|
" OR " + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?",
|
|
|
|
|
new String[]{email, like}, null)) {
|
|
|
|
|
if (cursor != null && cursor.moveToNext()) {
|
|
|
|
|
int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
|
|
|
|
|
int colLookupKey = cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
|
|
|
|
@ -3063,23 +3059,30 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|
|
|
|
long contactId = cursor.getLong(colContactId);
|
|
|
|
|
String lookupKey = cursor.getString(colLookupKey);
|
|
|
|
|
|
|
|
|
|
Uri lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
|
|
|
|
|
|
|
|
|
|
edit.setAction(Intent.ACTION_EDIT);
|
|
|
|
|
edit.setDataAndTypeAndNormalize(lookupUri, ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
|
|
|
|
} else {
|
|
|
|
|
edit.setAction(Intent.ACTION_INSERT);
|
|
|
|
|
edit.setType(ContactsContract.Contacts.CONTENT_TYPE);
|
|
|
|
|
lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PackageManager pm = context.getPackageManager();
|
|
|
|
|
if (edit.resolveActivity(pm) == null)
|
|
|
|
|
Snackbar.make(parentFragment.getView(),
|
|
|
|
|
R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
|
|
|
|
|
else
|
|
|
|
|
context.startActivity(edit);
|
|
|
|
|
// https://developer.android.com/training/contacts-provider/modify-data
|
|
|
|
|
Intent edit = new Intent();
|
|
|
|
|
edit.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
|
|
|
|
|
if (!TextUtils.isEmpty(name))
|
|
|
|
|
edit.putExtra(ContactsContract.Intents.Insert.NAME, name);
|
|
|
|
|
if (lookupUri == null) {
|
|
|
|
|
edit.setAction(Intent.ACTION_INSERT);
|
|
|
|
|
edit.setType(ContactsContract.Contacts.CONTENT_TYPE);
|
|
|
|
|
} else {
|
|
|
|
|
edit.setAction(Intent.ACTION_EDIT);
|
|
|
|
|
edit.setDataAndTypeAndNormalize(lookupUri, ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PackageManager pm = context.getPackageManager();
|
|
|
|
|
if (edit.resolveActivity(pm) == null)
|
|
|
|
|
Snackbar.make(parentFragment.getView(),
|
|
|
|
|
R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
|
|
|
|
|
else
|
|
|
|
|
context.startActivity(edit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onToggleMessage(TupleMessageEx message) {
|
|
|
|
|