Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SipAddressHandler.kt « datarow « vcard4android « bitfire « at « java « main « src - github.com/bitfireAT/vcard4android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0290c1354edd606cdfafc1a4bb84b1513a8711bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package at.bitfire.vcard4android.datarow

import android.content.ContentValues
import android.provider.ContactsContract.CommonDataKinds.SipAddress
import at.bitfire.vcard4android.Constants
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.LabeledProperty
import ezvcard.parameter.ImppType
import ezvcard.property.Impp

object SipAddressHandler: DataRowHandler() {

    override fun forMimeType() = SipAddress.CONTENT_ITEM_TYPE

    override fun handle(values: ContentValues, contact: Contact) {
        super.handle(values, contact)

        val sip = values.getAsString(SipAddress.SIP_ADDRESS) ?: return

        try {
            val impp = Impp("sip:$sip")
            val labeledImpp = LabeledProperty(impp)

            when (values.getAsInteger(SipAddress.TYPE)) {
                SipAddress.TYPE_HOME ->
                    impp.types += ImppType.HOME
                SipAddress.TYPE_WORK ->
                    impp.types += ImppType.WORK
                SipAddress.TYPE_CUSTOM ->
                    values.getAsString(SipAddress.LABEL)?.let {
                        labeledImpp.label = it
                    }
            }
            contact.impps.add(labeledImpp)
        } catch(e: IllegalArgumentException) {
            Constants.log.warning("Ignoring invalid locally stored SIP address")
        }
   }

}