From 375cb14e970f26db08914bcadfc372273ef511f1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 3 Sep 2018 12:12:47 +0200 Subject: [PATCH] properly export custom type values --- .../contacts/helpers/Constants.kt | 1 + .../contacts/helpers/VcfExporter.kt | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt index 0f56d22b..c6ec72be 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -56,6 +56,7 @@ const val PHOTO_UNCHANGED = 4 const val CELL = "CELL" const val WORK = "WORK" const val HOME = "HOME" +const val OTHER = "OTHER" const val PREF = "PREF" const val MAIN = "MAIN" const val FAX = "FAX" diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt index 30c5237b..b4651fb5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt @@ -15,10 +15,7 @@ import com.simplemobiletools.contacts.helpers.VcfExporter.ExportResult.EXPORT_FA import com.simplemobiletools.contacts.models.Contact import ezvcard.Ezvcard import ezvcard.VCard -import ezvcard.parameter.AddressType -import ezvcard.parameter.EmailType import ezvcard.parameter.ImageType -import ezvcard.parameter.TelephoneType import ezvcard.property.* import ezvcard.util.PartialDate import java.io.File @@ -62,13 +59,13 @@ class VcfExporter { contact.phoneNumbers.forEach { val phoneNumber = Telephone(it.value) - phoneNumber.types.add(TelephoneType.find(getPhoneNumberLabel(it.type))) + phoneNumber.parameters.addType(getPhoneNumberTypeLabel(it.type, it.label)) card.addTelephoneNumber(phoneNumber) } contact.emails.forEach { val email = Email(it.value) - email.types.add(EmailType.find(getEmailTypeLabel(it.type))) + email.parameters.addType(getEmailTypeLabel(it.type, it.label)) card.addEmail(email) } @@ -101,7 +98,7 @@ class VcfExporter { contact.addresses.forEach { val address = Address() address.streetAddress = it.value - address.types.add(AddressType.find(getAddressTypeLabel(it.type))) + address.parameters.addType(getAddressTypeLabel(it.type, it.label)) card.addAddress(address) } @@ -143,24 +140,30 @@ class VcfExporter { } } - private fun getPhoneNumberLabel(type: Int) = when (type) { + private fun getPhoneNumberTypeLabel(type: Int, label: String) = when (type) { CommonDataKinds.Phone.TYPE_MOBILE -> CELL + CommonDataKinds.Phone.TYPE_HOME -> HOME CommonDataKinds.Phone.TYPE_WORK -> WORK CommonDataKinds.Phone.TYPE_MAIN -> PREF CommonDataKinds.Phone.TYPE_FAX_WORK -> WORK_FAX CommonDataKinds.Phone.TYPE_FAX_HOME -> HOME_FAX CommonDataKinds.Phone.TYPE_PAGER -> PAGER - else -> HOME + CommonDataKinds.Phone.TYPE_OTHER -> OTHER + else -> label } - private fun getEmailTypeLabel(type: Int) = when (type) { + private fun getEmailTypeLabel(type: Int, label: String) = when (type) { + CommonDataKinds.Email.TYPE_HOME -> HOME CommonDataKinds.Email.TYPE_WORK -> WORK CommonDataKinds.Email.TYPE_MOBILE -> MOBILE - else -> HOME + CommonDataKinds.Email.TYPE_OTHER -> OTHER + else -> label } - private fun getAddressTypeLabel(type: Int) = when (type) { + private fun getAddressTypeLabel(type: Int, label: String) = when (type) { + CommonDataKinds.StructuredPostal.TYPE_HOME -> HOME CommonDataKinds.StructuredPostal.TYPE_WORK -> WORK - else -> HOME + CommonDataKinds.StructuredPostal.TYPE_OTHER -> OTHER + else -> label } }