handle address field export/importing
This commit is contained in:
parent
9edcee7110
commit
51d2d5d22b
|
@ -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"
|
||||
|
|
|
@ -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 -> ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue