From 78c0ec320a1e4d955c11509cf71478afac362dc2 Mon Sep 17 00:00:00 2001 From: Alex Styl <1665273+alexstyl@users.noreply.github.com> Date: Sun, 24 Oct 2021 21:15:39 +0100 Subject: [PATCH] Add documentation on ContactColumn --- .../java/com/alexstyl/contactstore/Contact.kt | 6 +- .../alexstyl/contactstore/ContactColumn.kt | 55 ++++++++++++++++++- .../alexstyl/contactstore/ContactQueries.kt | 12 ++-- .../contactstore/LinkedAccountValue.kt | 2 +- .../contactstore/RequiredReadColumn.kt | 4 +- 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/library/src/main/java/com/alexstyl/contactstore/Contact.kt b/library/src/main/java/com/alexstyl/contactstore/Contact.kt index a48d46b0..12a6e6c2 100644 --- a/library/src/main/java/com/alexstyl/contactstore/Contact.kt +++ b/library/src/main/java/com/alexstyl/contactstore/Contact.kt @@ -12,7 +12,7 @@ import android.provider.ContactsContract.PhoneticNameStyle import com.alexstyl.contactstore.ContactColumn.Events import com.alexstyl.contactstore.ContactColumn.GroupMemberships import com.alexstyl.contactstore.ContactColumn.Image -import com.alexstyl.contactstore.ContactColumn.LinkedAccountColumn +import com.alexstyl.contactstore.ContactColumn.LinkedAccountValues import com.alexstyl.contactstore.ContactColumn.Mails import com.alexstyl.contactstore.ContactColumn.Names import com.alexstyl.contactstore.ContactColumn.Nickname @@ -124,7 +124,7 @@ interface Contact { val webAddresses: List> /** - * Requires : [ContactColumn.LinkedAccountColumn] + * Requires : [ContactColumn.LinkedAccountValues] */ val linkedAccountValues: List @@ -151,7 +151,7 @@ fun Contact.containsColumn(column: ContactColumn): Boolean { } fun Contact.containsLinkedAccountColumns(): Boolean { - return columns.any { it is LinkedAccountColumn } + return columns.any { it is LinkedAccountValues } } /** diff --git a/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt b/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt index c993c160..9ed78102 100644 --- a/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt +++ b/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt @@ -1,18 +1,71 @@ package com.alexstyl.contactstore sealed class ContactColumn { + /** + * A column that will populate the [Contact.phones] field of all queried contacts when requested. + */ object Phones : ContactColumn() + + /** + * A column that will populate the [Contact.mails] field of all queried contacts when requested. + */ object Mails : ContactColumn() + + /** + * A column that will populate the [Contact.note] field of all queried contacts when requested. + */ object Note : ContactColumn() + + /** + * A column that will populate the [Contact.events] field of all queried contacts when requested. + * + */ object Events : ContactColumn() + + /** + * A column that will populate the [Contact.postalAddresses] field of all queried contacts when requested. + */ object PostalAddresses : ContactColumn() + + /** + * A column that will populate the [Contact.imageData] field of all queried contacts when requested. + * + * @see Contact.imageData + */ object Image : ContactColumn() + + /** + * A column that will populate the [Contact.prefix], [Contact.firstName],[Contact.middleName],[Contact.lastName], [Contact.suffix] fields of all queried contacts when requested. + */ object Names : ContactColumn() + + /** + * A column that will populate the [Contact.nickname] field of all queried contacts when requested. + */ object Nickname : ContactColumn() + + /** + * A column that will populate the [Contact.webAddresses] field of all queried contacts when requested. + */ object WebAddresses : ContactColumn() + + /** + * A column that will populate the [Contact.organization] and [Contact.jobTitle] fields of all queried contacts when requested. + */ object Organization : ContactColumn() + + /** + * A column that will populate the [Contact.groups] field of all queried contacts when requested. + */ object GroupMemberships : ContactColumn() - data class LinkedAccountColumn(val packageName: String) : ContactColumn() + + /** + * A column that will populate the [Contact.linkedAccountValues] field of all queried contacts when requested. + * + * Each 3rd party app specifies a unique account type when syncing web contacts into the device. + * See [SyncColumns.ACCOUNT_TYPE][android.provider.ContactsContract.SyncColumns.ACCOUNT_TYPE] for more details. + */ + data class LinkedAccountValues(val accountType: String) : ContactColumn() } fun standardColumns(): List { diff --git a/library/src/main/java/com/alexstyl/contactstore/ContactQueries.kt b/library/src/main/java/com/alexstyl/contactstore/ContactQueries.kt index b8f1ed00..9307636b 100644 --- a/library/src/main/java/com/alexstyl/contactstore/ContactQueries.kt +++ b/library/src/main/java/com/alexstyl/contactstore/ContactQueries.kt @@ -409,7 +409,7 @@ internal class ContactQueries( } private fun buildSelectionArgs(columnsToFetch: List): Array { - val linkedAccountColumns = columnsToFetch.filterIsInstance() + val linkedAccountColumns = columnsToFetch.filterIsInstance() val standardColumns = columnsToFetch - linkedAccountColumns return standardColumns.map { column -> when (column) { @@ -424,12 +424,10 @@ internal class ContactQueries( Organization -> OrganizationColumns.CONTENT_ITEM_TYPE Nickname -> NicknameColumns.CONTENT_ITEM_TYPE GroupMemberships -> GroupColumns.CONTENT_ITEM_TYPE - is LinkedAccountColumn -> + is LinkedAccountValues -> error("Tried to map a LinkedAccountColumn as standard column") } - }.toTypedArray() + linkedAccountColumns.map { - it.packageName - }.toTypedArray() + }.toTypedArray() + linkedAccountColumns.map { it.accountType }.toTypedArray() } private fun buildColumnsToFetchSelection( @@ -437,7 +435,7 @@ internal class ContactQueries( columnsToFetch: List ): String { val columnsQuery = buildString { - val linkedAccountColumns = columnsToFetch.filterIsInstance() + val linkedAccountColumns = columnsToFetch.filterIsInstance() val standardColumns = columnsToFetch - linkedAccountColumns if (standardColumns.isNotEmpty()) { @@ -445,7 +443,7 @@ internal class ContactQueries( " ${Data.MIMETYPE} IN ${ valueIn(standardColumns.map { column -> when (column) { - is LinkedAccountColumn -> + is LinkedAccountValues -> error("Tried to map a LinkedAccountColumn as standard column") else -> "?" } diff --git a/library/src/main/java/com/alexstyl/contactstore/LinkedAccountValue.kt b/library/src/main/java/com/alexstyl/contactstore/LinkedAccountValue.kt index f0547be5..e123352f 100644 --- a/library/src/main/java/com/alexstyl/contactstore/LinkedAccountValue.kt +++ b/library/src/main/java/com/alexstyl/contactstore/LinkedAccountValue.kt @@ -2,6 +2,7 @@ package com.alexstyl.contactstore data class LinkedAccountValue( val id: Long, + val accountType: String, val mimetype: String, val data1: String, val data2: String, @@ -18,5 +19,4 @@ data class LinkedAccountValue( val data13: String, val data14: String, val data15: String, - val accountType: String, ) diff --git a/library/src/main/java/com/alexstyl/contactstore/RequiredReadColumn.kt b/library/src/main/java/com/alexstyl/contactstore/RequiredReadColumn.kt index 2c641e0b..1987be14 100644 --- a/library/src/main/java/com/alexstyl/contactstore/RequiredReadColumn.kt +++ b/library/src/main/java/com/alexstyl/contactstore/RequiredReadColumn.kt @@ -1,6 +1,6 @@ package com.alexstyl.contactstore -import com.alexstyl.contactstore.ContactColumn.LinkedAccountColumn +import com.alexstyl.contactstore.ContactColumn.LinkedAccountValues import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty @@ -31,7 +31,7 @@ internal class RequiredReadColumnA( private val value: T ) { operator fun getValue(contact: Contact, property: KProperty<*>): T { - return if (contact.columns.any { it is LinkedAccountColumn }) { + return if (contact.columns.any { it is LinkedAccountValues }) { value } else { error(