fix importing contacts with custom field types

This commit is contained in:
tibbi 2018-09-03 13:24:26 +02:00
parent 375cb14e97
commit 349f3a1fc3
1 changed files with 32 additions and 11 deletions

View File

@ -48,24 +48,42 @@ class VcfImporter(val activity: SimpleActivity) {
val phoneNumbers = ArrayList<PhoneNumber>() val phoneNumbers = ArrayList<PhoneNumber>()
ezContact.telephoneNumbers.forEach { ezContact.telephoneNumbers.forEach {
val type = getPhoneNumberTypeId(it.types.firstOrNull()?.value ?: MOBILE)
val number = it.text val number = it.text
phoneNumbers.add(PhoneNumber(number, type, "")) val type = getPhoneNumberTypeId(it.types.firstOrNull()?.value ?: MOBILE)
val label = if (type == CommonDataKinds.Phone.TYPE_CUSTOM) {
it.types.firstOrNull()?.value ?: ""
} else {
""
}
phoneNumbers.add(PhoneNumber(number, type, label))
} }
val emails = ArrayList<Email>() val emails = ArrayList<Email>()
ezContact.emails.forEach { ezContact.emails.forEach {
val type = getEmailTypeId(it.types.firstOrNull()?.value ?: HOME)
val email = it.value val email = it.value
emails.add(Email(email, type, "")) val type = getEmailTypeId(it.types.firstOrNull()?.value ?: HOME)
val label = if (type == CommonDataKinds.Email.TYPE_CUSTOM) {
it.types.firstOrNull()?.value ?: ""
} else {
""
}
emails.add(Email(email, type, label))
} }
val addresses = ArrayList<Address>() val addresses = ArrayList<Address>()
ezContact.addresses.forEach { ezContact.addresses.forEach {
val type = getAddressTypeId(it.types.firstOrNull()?.value ?: HOME)
val address = it.streetAddress val address = it.streetAddress
val type = getAddressTypeId(it.types.firstOrNull()?.value ?: HOME)
val label = if (type == CommonDataKinds.StructuredPostal.TYPE_CUSTOM) {
it.types.firstOrNull()?.value ?: ""
} else {
""
}
if (address?.isNotEmpty() == true) { if (address?.isNotEmpty() == true) {
addresses.add(Address(address, type, "")) addresses.add(Address(address, type, label))
} }
} }
@ -126,20 +144,23 @@ class VcfImporter(val activity: SimpleActivity) {
HOME_FAX -> CommonDataKinds.Phone.TYPE_FAX_HOME HOME_FAX -> CommonDataKinds.Phone.TYPE_FAX_HOME
FAX -> CommonDataKinds.Phone.TYPE_FAX_WORK FAX -> CommonDataKinds.Phone.TYPE_FAX_WORK
PAGER -> CommonDataKinds.Phone.TYPE_PAGER PAGER -> CommonDataKinds.Phone.TYPE_PAGER
else -> CommonDataKinds.Phone.TYPE_OTHER OTHER -> CommonDataKinds.Phone.TYPE_OTHER
else -> CommonDataKinds.Phone.TYPE_CUSTOM
} }
private fun getEmailTypeId(type: String) = when (type.toUpperCase()) { private fun getEmailTypeId(type: String) = when (type.toUpperCase()) {
HOME -> CommonDataKinds.Email.TYPE_HOME HOME -> CommonDataKinds.Email.TYPE_HOME
WORK -> CommonDataKinds.Email.TYPE_WORK WORK -> CommonDataKinds.Email.TYPE_WORK
MOBILE -> CommonDataKinds.Email.TYPE_MOBILE MOBILE -> CommonDataKinds.Email.TYPE_MOBILE
else -> CommonDataKinds.Email.TYPE_OTHER OTHER -> CommonDataKinds.Email.TYPE_OTHER
else -> CommonDataKinds.Email.TYPE_CUSTOM
} }
private fun getAddressTypeId(type: String) = when (type.toUpperCase()) { private fun getAddressTypeId(type: String) = when (type.toUpperCase()) {
HOME -> CommonDataKinds.Email.TYPE_HOME HOME -> CommonDataKinds.StructuredPostal.TYPE_HOME
WORK -> CommonDataKinds.Email.TYPE_WORK WORK -> CommonDataKinds.StructuredPostal.TYPE_WORK
else -> CommonDataKinds.Email.TYPE_OTHER OTHER -> CommonDataKinds.StructuredPostal.TYPE_OTHER
else -> CommonDataKinds.StructuredPostal.TYPE_CUSTOM
} }
private fun savePhoto(byteArray: ByteArray?): String { private fun savePhoto(byteArray: ByteArray?): String {