Skip to content

Commit

Permalink
Returns no Raw Contacts when lookupKey is null
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed Jun 18, 2022
1 parent edc3006 commit c91dd6e
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ internal class RawContactQueries(
var currentRawContactId: Long = -1
val rawContacts = mutableListOf<RawContact>()

val contentUri = entityUri(contact) ?: return emptyList()

contentResolver.runQuery(
contentUri = entityUri(contact),
contentUri = contentUri,
projection = ContactQuery.COLUMNS,
sortOrder = ContactsContract.Contacts.Entity.RAW_CONTACT_ID
).iterate { cursor ->
Expand All @@ -37,11 +39,13 @@ internal class RawContactQueries(
return rawContacts.toList()
}

private fun entityUri(forContact: Contact): Uri {
private fun entityUri(forContact: Contact): Uri? {
val contactId = forContact.contactId
val lookupKey = forContact.lookupKey ?: return null

val contactUri = ensureIsContactUri(
contentResolver,
uri = ContactsContract.Contacts.getLookupUri(contactId, forContact.lookupKey?.value)
resolver = contentResolver,
uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey.value)
)
return Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Entity.CONTENT_DIRECTORY)
}
Expand Down Expand Up @@ -117,8 +121,7 @@ internal class RawContactQueries(
}
}

@Throws(IllegalArgumentException::class)
fun ensureIsContactUri(resolver: ContentResolver, uri: Uri): Uri? {
private fun ensureIsContactUri(resolver: ContentResolver, uri: Uri): Uri {
val authority = uri.authority

// Current Style Uri?
Expand Down

0 comments on commit c91dd6e

Please sign in to comment.