forked from upstream-mirrors/quik
Allow finding contact uri from email
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ import android.net.Uri
|
||||
import model.Recipient
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToRecipienImpl @Inject constructor(private val context: Context) : CursorToRecipient {
|
||||
class CursorToRecipientImpl @Inject constructor(private val context: Context) : CursorToRecipient {
|
||||
|
||||
companion object {
|
||||
val URI = Uri.parse("content://mms-sms/canonical-addresses")
|
||||
@@ -20,6 +20,7 @@ package repository
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.BaseColumns
|
||||
import android.provider.ContactsContract
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Single
|
||||
@@ -37,11 +38,16 @@ class ContactRepositoryImpl @Inject constructor(val context: Context) : ContactR
|
||||
|
||||
override fun findContactUri(address: String): Single<Uri> {
|
||||
return Flowable.just(address)
|
||||
.map { Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address)) }
|
||||
.mapNotNull { uri -> context.contentResolver.query(uri, arrayOf(ContactsContract.PhoneLookup._ID), null, null, null) }
|
||||
.map {
|
||||
when {
|
||||
address.contains('@') -> Uri.withAppendedPath(ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address))
|
||||
else -> Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address))
|
||||
}
|
||||
}
|
||||
.mapNotNull { uri -> context.contentResolver.query(uri, arrayOf(BaseColumns._ID), null, null, null) }
|
||||
.flatMap { cursor -> cursor.asFlowable() }
|
||||
.firstOrError()
|
||||
.map { cursor -> cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID)) }
|
||||
.map { cursor -> cursor.getString(cursor.getColumnIndexOrThrow(BaseColumns._ID)) }
|
||||
.map { id -> Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id) }
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ import mapper.CursorToMessage
|
||||
import mapper.CursorToMessageImpl
|
||||
import mapper.CursorToPart
|
||||
import mapper.CursorToPartImpl
|
||||
import mapper.CursorToRecipienImpl
|
||||
import mapper.CursorToRecipientImpl
|
||||
import mapper.CursorToRecipient
|
||||
import repository.ContactRepository
|
||||
import repository.ContactRepositoryImpl
|
||||
@@ -114,7 +114,7 @@ class AppModule(private var application: Application) {
|
||||
fun provideCursorToPart(mapper: CursorToPartImpl): CursorToPart = mapper
|
||||
|
||||
@Provides
|
||||
fun provideCursorToRecipient(mapper: CursorToRecipienImpl): CursorToRecipient = mapper
|
||||
fun provideCursorToRecipient(mapper: CursorToRecipientImpl): CursorToRecipient = mapper
|
||||
|
||||
|
||||
// Repository
|
||||
|
||||
Reference in New Issue
Block a user