@@ -14,10 +14,13 @@ import com.simplemobiletools.contacts.R
1414import com.simplemobiletools.contacts.adapters.SelectContactsAdapter
1515import com.simplemobiletools.contacts.extensions.config
1616import com.simplemobiletools.contacts.helpers.ContactsHelper
17+ import com.simplemobiletools.contacts.helpers.SMT_PRIVATE
1718import com.simplemobiletools.contacts.models.Contact
1819import kotlinx.android.synthetic.main.layout_select_contact.*
1920
2021class SelectContactActivity : SimpleActivity () {
22+ private var isGetEmailIntent = false
23+
2124 override fun onCreate (savedInstanceState : Bundle ? ) {
2225 super .onCreate(savedInstanceState)
2326 setContentView(R .layout.layout_select_contact)
@@ -41,12 +44,20 @@ class SelectContactActivity : SimpleActivity() {
4144 }
4245
4346 private fun initContacts () {
44- ContactsHelper ( this ).getContacts {
45- var contacts = it
47+ isGetEmailIntent = intent.data == ContactsContract . CommonDataKinds . Email . CONTENT_URI
48+ ContactsHelper ( this ).getContacts( true ) {
4649 if (isActivityDestroyed()) {
4750 return @getContacts
4851 }
4952
53+ var contacts = it.filter {
54+ if (isGetEmailIntent) {
55+ (it.source != SMT_PRIVATE && it.emails.isNotEmpty())
56+ } else {
57+ true
58+ }
59+ } as ArrayList <Contact >
60+
5061 val contactSources = config.displayContactSources
5162 if (! config.showAllContacts()) {
5263 contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList <Contact >
@@ -68,14 +79,21 @@ class SelectContactActivity : SimpleActivity() {
6879 }
6980
7081 private fun confirmSelection (contact : Contact ) {
71- val lookupKey = ContactsHelper (this ).getContactLookupKey(contact.id.toString())
72- val lookupUri = Uri .withAppendedPath(ContactsContract .Contacts .CONTENT_LOOKUP_URI , lookupKey)
73-
7482 Intent ().apply {
75- data = lookupUri
83+ data = getResultUri(contact)
7684 addFlags(Intent .FLAG_GRANT_READ_URI_PERMISSION )
7785 setResult(RESULT_OK , this )
7886 }
7987 finish()
8088 }
89+
90+ private fun getResultUri (contact : Contact ): Uri {
91+ return if (isGetEmailIntent) {
92+ val emailID = ContactsHelper (this ).getContactDataId(contact.id.toString())
93+ Uri .withAppendedPath(ContactsContract .Data .CONTENT_URI , emailID)
94+ } else {
95+ val lookupKey = ContactsHelper (this ).getContactLookupKey(contact.id.toString())
96+ Uri .withAppendedPath(ContactsContract .Contacts .CONTENT_LOOKUP_URI , lookupKey)
97+ }
98+ }
8199}
0 commit comments