From 69b68de511b15fe908da8220a05df0d7d829f511 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 15 Jan 2018 00:06:53 +0100 Subject: [PATCH] properly parse phone numbers at Version 3 vcf files too --- .../contacts/helpers/Constants.kt | 2 ++ .../contacts/helpers/VcfImporter.kt | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 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 30708ee7..5559ff4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -38,6 +38,8 @@ val CELL = "CELL" val WORK = "WORK" val HOME = "HOME" val PREF = "PREF" +val MAIN = "MAIN" +val FAX = "FAX" val WORK_FAX = "WORK;FAX" val HOME_FAX = "HOME;FAX" val PAGER = "PAGER" diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt index d2384182..069cdc70 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt @@ -73,25 +73,40 @@ class VcfImporter(val activity: SimpleActivity) { private fun addPhoneNumber(phoneNumber: String) { val phoneParts = phoneNumber.trimStart(';').split(":") - val type = getPhoneNumberTypeId(phoneParts[0]) + var rawType = phoneParts[0] + var subType = "" + if (rawType.contains('=')) { + val types = rawType.split('=') + if (types.any { it.contains(';') }) { + subType = types[1].split(';').first() + } + rawType = types.last() + } + + val type = getPhoneNumberTypeId(rawType, subType) val value = phoneParts[1] curPhoneNumbers.add(PhoneNumber(value, type)) } - private fun getPhoneNumberTypeId(type: String) = when (type) { + private fun getPhoneNumberTypeId(type: String, subType: String) = when (type) { CELL -> CommonDataKinds.Phone.TYPE_MOBILE WORK -> CommonDataKinds.Phone.TYPE_WORK HOME -> CommonDataKinds.Phone.TYPE_HOME - PREF -> CommonDataKinds.Phone.TYPE_MAIN + PREF, MAIN -> CommonDataKinds.Phone.TYPE_MAIN WORK_FAX -> CommonDataKinds.Phone.TYPE_FAX_WORK HOME_FAX -> CommonDataKinds.Phone.TYPE_FAX_HOME + FAX -> if (subType == WORK) CommonDataKinds.Phone.TYPE_FAX_WORK else CommonDataKinds.Phone.TYPE_FAX_HOME PAGER -> CommonDataKinds.Phone.TYPE_PAGER else -> CommonDataKinds.Phone.TYPE_OTHER } private fun addEmail(email: String) { val emailParts = email.trimStart(';').split(":") - val type = getEmailTypeId(emailParts[0]) + var rawType = emailParts[0] + if (rawType.contains('=')) { + rawType = rawType.split('=').last() + } + val type = getEmailTypeId(rawType) val value = emailParts[1] curEmails.add(Email(value, type)) }