diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index 6c5cbfa0..1b25d07e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -119,12 +119,12 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val emails = SparseArray>() val uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI val projection = arrayOf( - ContactsContract.CommonDataKinds.Email.CONTACT_ID, + ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.CommonDataKinds.Email.DATA, ContactsContract.CommonDataKinds.Email.TYPE ) - val selection = if (contactId == null) null else "${ContactsContract.CommonDataKinds.Email.CONTACT_ID} = ?" + val selection = if (contactId == null) null else "${ContactsContract.Data.RAW_CONTACT_ID} = ?" val selectionArgs = if (contactId == null) null else arrayOf(contactId.toString()) var cursor: Cursor? = null @@ -132,7 +132,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) if (cursor?.moveToFirst() == true) { do { - val id = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.CONTACT_ID) + val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) val email = cursor.getStringValue(ContactsContract.CommonDataKinds.Email.DATA) val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.TYPE) @@ -154,12 +154,12 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val phoneNumbers = SparseArray>() val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI val projection = arrayOf( - ContactsContract.CommonDataKinds.Phone.CONTACT_ID, + ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.TYPE ) - val selection = if (contactId == null) null else "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?" + val selection = if (contactId == null) null else "${ContactsContract.Data.RAW_CONTACT_ID} = ?" val selectionArgs = if (contactId == null) null else arrayOf(contactId.toString()) var cursor: Cursor? = null @@ -167,7 +167,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) if (cursor?.moveToFirst() == true) { do { - val id = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.CONTACT_ID) + val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) val number = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.NUMBER) val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.TYPE) @@ -234,6 +234,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { if (sorting and SORT_DESCENDING != 0) { sort += " DESC" } + return sort } @@ -450,7 +451,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { fun deleteContacts(contacts: ArrayList) { try { val operations = ArrayList() - val selection = "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?" + val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ?" contacts.forEach { val selectionArgs = arrayOf(it.id.toString()) operations.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(selection, selectionArgs).build()) @@ -461,20 +462,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) { } } - fun doesSourceContainContacts(source: String): Boolean { - val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI - val projection = arrayOf(ContactsContract.CommonDataKinds.Email.CONTACT_ID) - val selection = "${ContactsContract.RawContacts.ACCOUNT_NAME} = ?" - val selectionArgs = arrayOf(source) - var cursor: Cursor? = null - try { - cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) - return (cursor?.moveToFirst() == true) - } finally { - cursor?.close() - } - } - private fun getThumbnailSize(): Int { val uri = ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI val projection = arrayOf(ContactsContract.DisplayPhoto.THUMBNAIL_MAX_DIM)