Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 532ae580 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Handle (non-standard) TYPE=other for phone numbers and addresses, too (for better compatibility)

parent 39c990b8
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -732,6 +732,7 @@ open class AndroidContact(
                types.contains(Contact.PHONE_TYPE_MMS) ->
                    typeCode = Phone.TYPE_MMS

                types.contains(Contact.PHONE_TYPE_OTHER) ||
                types.contains(TelephoneType.VOICE) ||
                types.contains(TelephoneType.TEXT) -> {}

@@ -769,8 +770,9 @@ open class AndroidContact(
        val email = labeledEmail.property

        // drop TYPE=internet and TYPE=x400 because Android only knows Internet email addresses
        // drop TYPE=other for compatibility, too (non-standard type which is only used by some clients and not useful as an explicit value)
        val types = email.types
        types.removeAll(arrayOf(EmailType.INTERNET, EmailType.X400))
        types.removeAll(arrayOf(EmailType.INTERNET, EmailType.X400, Contact.EMAIL_TYPE_OTHER))

        // preferred email address?
        var pref: Int? = null
@@ -796,7 +798,6 @@ open class AndroidContact(
                    EmailType.HOME -> typeCode = Email.TYPE_HOME
                    EmailType.WORK -> typeCode = Email.TYPE_WORK
                    Contact.EMAIL_TYPE_MOBILE -> typeCode = Email.TYPE_MOBILE
                    Contact.EMAIL_TYPE_OTHER -> typeCode = Email.TYPE_OTHER
                }
            if (typeCode == 0) {    // we still didn't find a known type
                if (email.types.isEmpty())
@@ -872,7 +873,6 @@ open class AndroidContact(

        var typeCode: Int = Im.TYPE_OTHER
        var typeLabel: String? = null

        if (labeledImpp.label != null) {
            typeCode = Im.TYPE_CUSTOM
            typeLabel = labeledImpp.label
@@ -1044,22 +1044,23 @@ open class AndroidContact(
            formattedAddress = lines.joinToString("\n")
        }

        val types = address.types
        var typeCode = StructuredPostal.TYPE_OTHER
        var typeLabel: String? = null
        if (labeledAddress.label != null) {
            typeCode = StructuredPostal.TYPE_CUSTOM
            typeLabel = labeledAddress.label
        } else {
            for (type in address.types)
                when (type) {
                    AddressType.HOME -> typeCode = StructuredPostal.TYPE_HOME
                    AddressType.WORK -> typeCode = StructuredPostal.TYPE_WORK
                }
            if (typeCode == StructuredPostal.TYPE_OTHER && address.types.isNotEmpty()) {
            when {
                types.contains(AddressType.HOME) -> typeCode = StructuredPostal.TYPE_HOME
                types.contains(AddressType.WORK) -> typeCode = StructuredPostal.TYPE_WORK
                types.contains(Contact.ADDRESS_TYPE_OTHER) -> {}
                types.isNotEmpty() -> {
                    typeCode = StructuredPostal.TYPE_CUSTOM
                    typeLabel = xNameToLabel(address.types.first().value)
                }
            }
        }

        val op: BatchOperation.Operation
        val builder = ContentProviderOperation.newInsert(dataSyncURI())
+6 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ package at.bitfire.vcard4android
import ezvcard.Ezvcard
import ezvcard.VCard
import ezvcard.VCardVersion
import ezvcard.parameter.AddressType
import ezvcard.parameter.EmailType
import ezvcard.parameter.ImageType
import ezvcard.parameter.TelephoneType
@@ -90,12 +91,17 @@ class Contact {
        val PHONE_TYPE_RADIO = TelephoneType.get("x-radio")!!
        val PHONE_TYPE_ASSISTANT = TelephoneType.get("X-assistant")!!
        val PHONE_TYPE_MMS = TelephoneType.get("x-mms")!!
        /** Sometimes used to denote an "other" phone numbers. Only for compatibility – don't use it yourself! */
        val PHONE_TYPE_OTHER = TelephoneType.get("other")!!

        /** Custom email type to denote "mobile" email addresses. */
        val EMAIL_TYPE_MOBILE = EmailType.get("x-mobile")!!
        /** Sometimes used to denote an "other" email address. Only for compatibility – don't use it yourself! */
        val EMAIL_TYPE_OTHER = EmailType.get("other")!!

        /** Sometimes used to denote an "other" postal address. Only for compatibility – don't use it yourself! */
        val ADDRESS_TYPE_OTHER = AddressType.get("other")!!

        const val NICKNAME_TYPE_MAIDEN_NAME = "x-maiden-name"
        const val NICKNAME_TYPE_SHORT_NAME = "x-short-name"
        const val NICKNAME_TYPE_INITIALS = "x-initials"