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 324d9156..695fd967 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -30,6 +30,7 @@ const val BDAY = "BDAY:" const val ANNIVERSARY = "ANNIVERSARY:" const val PHOTO = "PHOTO" const val EMAIL = "EMAIL" +const val ADR = "ADR" const val ENCODING = "ENCODING" const val BASE64 = "BASE64" const val JPEG = "JPEG" 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 793a8ccc..21f784ad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt @@ -50,6 +50,12 @@ class VcfExporter { out.writeLn("$EMAIL$delimiterType:${it.value}") } + contact.addresses.forEach { + val type = getAddressTypeLabel(it.type) + val delimiterType = if (type.isEmpty()) "" else ";$type" + out.writeLn("$ADR$delimiterType:;;${it.value};;;;") + } + contact.events.forEach { if (it.type == CommonDataKinds.Event.TYPE_BIRTHDAY) { out.writeLn("$BDAY${it.value}") @@ -136,4 +142,10 @@ class VcfExporter { CommonDataKinds.Email.TYPE_MOBILE -> MOBILE else -> "" } + + private fun getAddressTypeLabel(type: Int) = when (type) { + CommonDataKinds.StructuredPostal.TYPE_HOME -> HOME + CommonDataKinds.StructuredPostal.TYPE_WORK -> WORK + else -> "" + } } 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 9dee4a43..15c8ca09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt @@ -67,6 +67,7 @@ class VcfImporter(val activity: SimpleActivity) { line.toUpperCase().startsWith(N) -> addNames(line.substring(N.length)) line.toUpperCase().startsWith(TEL) -> addPhoneNumber(line.substring(TEL.length)) line.toUpperCase().startsWith(EMAIL) -> addEmail(line.substring(EMAIL.length)) + line.toUpperCase().startsWith(ADR) -> addAddress(line.substring(ADR.length)) line.toUpperCase().startsWith(BDAY) -> addBirthday(line.substring(BDAY.length)) line.toUpperCase().startsWith(ANNIVERSARY) -> addAnniversary(line.substring(ANNIVERSARY.length)) line.toUpperCase().startsWith(PHOTO) -> addPhoto(line.substring(PHOTO.length)) @@ -154,6 +155,25 @@ class VcfImporter(val activity: SimpleActivity) { else -> CommonDataKinds.Email.TYPE_OTHER } + private fun addAddress(address: String) { + val addressParts = address.trimStart(';').split(":") + var rawType = addressParts[0] + if (rawType.contains('=')) { + rawType = rawType.split('=').last() + } + val type = getAddressTypeId(rawType.toUpperCase()) + val addresses = addressParts[1].split(";") + if (addresses.size == 7) { + curAddresses.add(Address(addresses[2], type)) + } + } + + private fun getAddressTypeId(type: String) = when (type) { + HOME -> CommonDataKinds.Email.TYPE_HOME + WORK -> CommonDataKinds.Email.TYPE_WORK + else -> CommonDataKinds.Email.TYPE_OTHER + } + private fun addBirthday(birthday: String) { curEvents.add(Event(birthday, CommonDataKinds.Event.TYPE_BIRTHDAY)) }