mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 05:35:39 +03:00
Use displayName
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
2d1a06b034
commit
69b477063f
1 changed files with 7 additions and 12 deletions
|
@ -21,10 +21,10 @@ import com.owncloud.android.utils.PermissionUtil.checkSelfPermission
|
||||||
class ContactManager(private val context: Context) {
|
class ContactManager(private val context: Context) {
|
||||||
|
|
||||||
fun openContact(searchResult: SearchResultEntry, listInterface: UnifiedSearchListInterface) {
|
fun openContact(searchResult: SearchResultEntry, listInterface: UnifiedSearchListInterface) {
|
||||||
val contactId = searchResult.attributes["uid"]
|
val displayName = searchResult.attributes["displayName"]
|
||||||
val haveReadContactsPermission = checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
|
val haveReadContactsPermission = checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
|
||||||
val contactIds = if (haveReadContactsPermission) {
|
val contactIds = if (haveReadContactsPermission && displayName != null) {
|
||||||
getContactId(contactId!!)
|
getContactId(displayName)
|
||||||
} else {
|
} else {
|
||||||
listOf()
|
listOf()
|
||||||
}
|
}
|
||||||
|
@ -46,15 +46,11 @@ class ContactManager(private val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getContactId(contactName: String): List<Long> {
|
private fun getContactId(displayName: String): List<Long> {
|
||||||
val result = arrayListOf<Long>()
|
val result = arrayListOf<Long>()
|
||||||
|
val projection = arrayOf(ContactsContract.Contacts._ID)
|
||||||
val projection = arrayOf(
|
val selection = "${ContactsContract.Contacts.DISPLAY_NAME} = ?"
|
||||||
ContactsContract.Contacts._ID,
|
val selectionArgs = arrayOf(displayName)
|
||||||
)
|
|
||||||
|
|
||||||
val selection = "${ContactsContract.Contacts._ID} = ?"
|
|
||||||
val selectionArgs = arrayOf(contactName)
|
|
||||||
|
|
||||||
val cursor = context.contentResolver.query(
|
val cursor = context.contentResolver.query(
|
||||||
ContactsContract.Contacts.CONTENT_URI,
|
ContactsContract.Contacts.CONTENT_URI,
|
||||||
|
@ -66,7 +62,6 @@ class ContactManager(private val context: Context) {
|
||||||
|
|
||||||
cursor?.use {
|
cursor?.use {
|
||||||
val idIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID)
|
val idIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID)
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val id = cursor.getLong(idIndex)
|
val id = cursor.getLong(idIndex)
|
||||||
result.add(id)
|
result.add(id)
|
||||||
|
|
Loading…
Reference in a new issue