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

SipAddressBuilder.kt « contactrow « vcard4android « bitfire « at « java « main « src - github.com/bitfireAT/vcard4android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f47c534ab7037cbe2db2c2c0a6f02ff20db5d38 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/***************************************************************************************************
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 **************************************************************************************************/

package at.bitfire.vcard4android.contactrow

import android.net.Uri
import android.provider.ContactsContract.CommonDataKinds.SipAddress
import at.bitfire.vcard4android.BatchOperation
import at.bitfire.vcard4android.Contact
import ezvcard.parameter.ImppType
import java.util.*

class SipAddressBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact)
    : DataRowBuilder(Factory.mimeType(), dataRowUri, rawContactId, contact) {

    override fun build(): List<BatchOperation.CpoBuilder> {
        val result = LinkedList<BatchOperation.CpoBuilder>()
        for (labeledIm in contact.impps) {
            val impp = labeledIm.property

            val protocol = impp.protocol
            if (!ImMapping.SCHEME_SIP.equals(protocol, true))
                // other protocols are handled by ImBuilder
                continue

            var typeCode: Int = SipAddress.TYPE_OTHER
            var typeLabel: String? = null
            if (labeledIm.label != null) {
                typeCode = SipAddress.TYPE_CUSTOM
                typeLabel = labeledIm.label
            } else {
                for (type in impp.types)
                    when (type) {
                        ImppType.HOME,
                        ImppType.PERSONAL -> typeCode = SipAddress.TYPE_HOME
                        ImppType.WORK,
                        ImppType.BUSINESS -> typeCode = SipAddress.TYPE_WORK
                    }
            }

            // save as IM address
            result += newDataRow()
                .withValue(SipAddress.SIP_ADDRESS, impp.handle)
                .withValue(SipAddress.TYPE, typeCode)
                .withValue(SipAddress.LABEL, typeLabel)
        }
        return result
    }


    object Factory: DataRowBuilder.Factory<SipAddressBuilder> {
        override fun mimeType() = SipAddress.CONTENT_ITEM_TYPE
        override fun newInstance(dataRowUri: Uri, rawContactId: Long?, contact: Contact) =
            SipAddressBuilder(dataRowUri, rawContactId, contact)
    }

}