mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
do not try parsing names at Organization contacts
This commit is contained in:
@ -159,11 +159,21 @@ class ContactsHelper(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
||||||
val prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: ""
|
var prefix = ""
|
||||||
val firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
|
var firstName = ""
|
||||||
val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
var middleName = ""
|
||||||
val surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
|
var surname = ""
|
||||||
val suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: ""
|
var suffix = ""
|
||||||
|
|
||||||
|
// ignore names at Organization type contacts
|
||||||
|
if (cursor.getStringValue(ContactsContract.Data.MIMETYPE) == CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) {
|
||||||
|
prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: ""
|
||||||
|
firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
|
||||||
|
middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
||||||
|
surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
|
||||||
|
suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
val nickname = ""
|
val nickname = ""
|
||||||
val photoUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
|
val photoUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
|
||||||
val numbers = ArrayList<PhoneNumber>() // proper value is obtained below
|
val numbers = ArrayList<PhoneNumber>() // proper value is obtained below
|
||||||
@ -808,11 +818,22 @@ class ContactsHelper(val context: Context) {
|
|||||||
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
||||||
val prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: ""
|
|
||||||
val firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
|
var prefix = ""
|
||||||
val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
var firstName = ""
|
||||||
val surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
|
var middleName = ""
|
||||||
val suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: ""
|
var surname = ""
|
||||||
|
var suffix = ""
|
||||||
|
|
||||||
|
// ignore names at Organization type contacts
|
||||||
|
if (cursor.getStringValue(ContactsContract.Data.MIMETYPE) == CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) {
|
||||||
|
prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: ""
|
||||||
|
firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
|
||||||
|
middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
||||||
|
surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
|
||||||
|
suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
val nickname = getNicknames(id)[id] ?: ""
|
val nickname = getNicknames(id)[id] ?: ""
|
||||||
val photoUri = cursor.getStringValue(CommonDataKinds.Phone.PHOTO_URI) ?: ""
|
val photoUri = cursor.getStringValue(CommonDataKinds.Phone.PHOTO_URI) ?: ""
|
||||||
val number = getPhoneNumbers(id)[id] ?: ArrayList()
|
val number = getPhoneNumbers(id)[id] ?: ArrayList()
|
||||||
@ -879,6 +900,7 @@ class ContactsHelper(val context: Context) {
|
|||||||
private fun getContactSourceType(accountName: String) = getDeviceContactSources().firstOrNull { it.name == accountName }?.type ?: ""
|
private fun getContactSourceType(accountName: String) = getDeviceContactSources().firstOrNull { it.name == accountName }?.type ?: ""
|
||||||
|
|
||||||
private fun getContactProjection() = arrayOf(
|
private fun getContactProjection() = arrayOf(
|
||||||
|
ContactsContract.Data.MIMETYPE,
|
||||||
ContactsContract.Data.CONTACT_ID,
|
ContactsContract.Data.CONTACT_ID,
|
||||||
ContactsContract.Data.RAW_CONTACT_ID,
|
ContactsContract.Data.RAW_CONTACT_ID,
|
||||||
CommonDataKinds.StructuredName.PREFIX,
|
CommonDataKinds.StructuredName.PREFIX,
|
||||||
@ -936,8 +958,8 @@ class ContactsHelper(val context: Context) {
|
|||||||
try {
|
try {
|
||||||
val operations = ArrayList<ContentProviderOperation>()
|
val operations = ArrayList<ContentProviderOperation>()
|
||||||
ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).apply {
|
ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).apply {
|
||||||
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = ?"
|
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND (${ContactsContract.Data.MIMETYPE} = ? OR ${ContactsContract.Data.MIMETYPE} = ?)"
|
||||||
val selectionArgs = arrayOf(contact.id.toString(), CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
val selectionArgs = arrayOf(contact.id.toString(), CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
||||||
withSelection(selection, selectionArgs)
|
withSelection(selection, selectionArgs)
|
||||||
withValue(CommonDataKinds.StructuredName.PREFIX, contact.prefix)
|
withValue(CommonDataKinds.StructuredName.PREFIX, contact.prefix)
|
||||||
withValue(CommonDataKinds.StructuredName.GIVEN_NAME, contact.firstName)
|
withValue(CommonDataKinds.StructuredName.GIVEN_NAME, contact.firstName)
|
||||||
|
Reference in New Issue
Block a user