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

WebsiteHandler.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: 42255ab89d1ba157b8ca66bd618765e96036327b (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
package at.bitfire.vcard4android.contactrow

import android.content.ContentValues
import android.provider.ContactsContract.CommonDataKinds.Website
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.LabeledProperty
import at.bitfire.vcard4android.property.CustomType
import ezvcard.property.Url

object WebsiteHandler: DataRowHandler() {

    override fun forMimeType() = Website.CONTENT_ITEM_TYPE

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

        val url = Url(values.getAsString(Website.URL) ?: return)
        val labeledUrl = LabeledProperty(url)

        when (values.getAsInteger(Website.TYPE)) {
            Website.TYPE_HOMEPAGE ->
                url.type = CustomType.Url.TYPE_HOMEPAGE
            Website.TYPE_BLOG ->
                url.type = CustomType.Url.TYPE_BLOG
            Website.TYPE_PROFILE ->
                url.type = CustomType.Url.TYPE_PROFILE
            Website.TYPE_HOME ->
                url.type = CustomType.HOME
            Website.TYPE_WORK ->
                url.type = CustomType.WORK
            Website.TYPE_FTP ->
                url.type = CustomType.Url.TYPE_FTP
            Website.TYPE_CUSTOM ->
                values.getAsString(Website.LABEL)?.let {
                    labeledUrl.label = it
                }
        }
        contact.urls += labeledUrl
    }

}