Merge pull request #1421 from sdex/check_contact_exists
Check if the number exists in the contacts and the private contacts
This commit is contained in:
commit
10c8ac2f1e
1 changed files with 10 additions and 15 deletions
|
@ -380,22 +380,17 @@ class SimpleContactsHelper(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
fun exists(number: String): Boolean {
|
||||
if (!context.hasPermission(PERMISSION_READ_CONTACTS)) {
|
||||
return false
|
||||
}
|
||||
|
||||
val uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number))
|
||||
val projection = arrayOf(PhoneLookup._ID)
|
||||
|
||||
try {
|
||||
val cursor = context.contentResolver.query(uri, projection, null, null, null)
|
||||
cursor?.use {
|
||||
return it.moveToFirst()
|
||||
fun exists(number: String, callback: (Boolean) -> Unit) {
|
||||
val privateCursor = context.getMyContactsCursor(false, true)
|
||||
SimpleContactsHelper(context).getAvailableContacts(false) { contacts ->
|
||||
val contact = contacts.firstOrNull { it.doesHavePhoneNumber(number) }
|
||||
if (contact != null) {
|
||||
callback.invoke(true)
|
||||
} else {
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
|
||||
val privateContact = privateContacts.firstOrNull { it.doesHavePhoneNumber(number) }
|
||||
callback.invoke(privateContact != null)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue