From f1aa4e96d7a525d7a4771116fdcfa5607838922b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 10 Jan 2021 12:11:35 +0100 Subject: [PATCH] do not update contact organization, if there is none --- .../contacts/pro/helpers/ContactsHelper.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index db1d3590..39abe003 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -154,7 +154,7 @@ class ContactsHelper(val context: Context) { val mimetype = cursor.getStringValue(Data.MIMETYPE) // ignore names at Organization type contacts - if (cursor.getStringValue(Data.MIMETYPE) == StructuredName.CONTENT_ITEM_TYPE) { + if (mimetype == StructuredName.CONTENT_ITEM_TYPE) { prefix = cursor.getStringValue(StructuredName.PREFIX) ?: "" firstName = cursor.getStringValue(StructuredName.GIVEN_NAME) ?: "" middleName = cursor.getStringValue(StructuredName.MIDDLE_NAME) ?: "" @@ -1012,14 +1012,16 @@ class ContactsHelper(val context: Context) { } // add organization - ContentProviderOperation.newInsert(Data.CONTENT_URI).apply { - withValue(Data.RAW_CONTACT_ID, contact.id) - withValue(Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE) - withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company) - withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE) - withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition) - withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE) - operations.add(build()) + if (contact.organization.isNotEmpty()) { + ContentProviderOperation.newInsert(Data.CONTENT_URI).apply { + withValue(Data.RAW_CONTACT_ID, contact.id) + withValue(Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE) + withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company) + withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE) + withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition) + withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE) + operations.add(build()) + } } // delete websites