From b9e48a2a7bb8a6f08c4c685f50a5f7fdc7be2c17 Mon Sep 17 00:00:00 2001 From: Vandolf Estrellado Date: Sun, 28 Nov 2021 14:44:24 -1000 Subject: [PATCH] Closes #113 Fix hierarchy of CommonDataEntity --- DEV_NOTES.md | 4 +- README.md | 4 +- .../contacts/async/data/DataQueryAsync.kt | 14 +- .../contacts/async/util/DataContactAsync.kt | 10 +- .../async/util/DataRawContactAsync.kt | 10 +- .../contacts/async/util/DataRefreshAsync.kt | 11 +- .../async/util/DefaultContactDataAsync.kt | 18 +- core/src/main/java/contacts/core/Contacts.kt | 2 +- core/src/main/java/contacts/core/Fields.kt | 57 +++---- core/src/main/java/contacts/core/Insert.kt | 2 +- core/src/main/java/contacts/core/Where.kt | 6 +- core/src/main/java/contacts/core/data/Data.kt | 6 +- .../java/contacts/core/data/DataDelete.kt | 26 +-- .../main/java/contacts/core/data/DataQuery.kt | 140 +++++++-------- .../java/contacts/core/data/DataUpdate.kt | 34 ++-- .../java/contacts/core/entities/Address.kt | 6 +- .../{CommonDataEntity.kt => DataEntity.kt} | 24 ++- .../main/java/contacts/core/entities/Email.kt | 6 +- .../main/java/contacts/core/entities/Event.kt | 6 +- .../contacts/core/entities/GroupMembership.kt | 2 +- .../main/java/contacts/core/entities/Im.kt | 6 +- ...monDataFields.kt => MimeTypeDataFields.kt} | 12 +- .../main/java/contacts/core/entities/Name.kt | 4 +- .../java/contacts/core/entities/Nickname.kt | 4 +- .../main/java/contacts/core/entities/Note.kt | 4 +- .../contacts/core/entities/Organization.kt | 4 +- .../main/java/contacts/core/entities/Phone.kt | 6 +- .../main/java/contacts/core/entities/Photo.kt | 2 +- .../java/contacts/core/entities/Relation.kt | 6 +- .../java/contacts/core/entities/SipAddress.kt | 4 +- .../java/contacts/core/entities/Website.kt | 4 +- .../entities/cursor/AbstractEntityCursor.kt | 8 +- .../core/entities/cursor/MimeTypeCursor.kt | 4 +- .../custom/AbstractCustomDataOperation.kt | 12 +- .../custom/AbstractCustomEntityMapper.kt | 9 +- .../core/entities/custom/CustomData.kt | 32 ++++ .../core/entities/custom/CustomDataEntity.kt | 38 ----- .../entities/custom/CustomDataEntityHolder.kt | 2 +- .../entities/custom/CustomDataFieldMapper.kt | 2 +- .../entities/custom/CustomDataRegistry.kt | 24 +-- .../entities/mapper/EntityMapperFactory.kt | 3 +- ...aOperation.kt => AbstractDataOperation.kt} | 4 +- .../entities/operation/AddressOperation.kt | 2 +- .../operation/DataEntityOperationMapper.kt | 10 +- .../core/entities/operation/EmailOperation.kt | 2 +- .../core/entities/operation/EventOperation.kt | 2 +- .../operation/GroupMembershipOperation.kt | 2 +- .../core/entities/operation/ImOperation.kt | 2 +- .../core/entities/operation/NameOperation.kt | 2 +- .../entities/operation/NicknameOperation.kt | 2 +- .../core/entities/operation/NoteOperation.kt | 2 +- .../operation/OrganizationOperation.kt | 2 +- .../core/entities/operation/PhoneOperation.kt | 2 +- .../entities/operation/RelationOperation.kt | 2 +- .../entities/operation/SipAddressOperation.kt | 2 +- .../entities/operation/WebsiteOperation.kt | 2 +- .../contacts/core/profile/ProfileInsert.kt | 2 +- .../java/contacts/core/util/ContactData.kt | 4 +- .../java/contacts/core/util/DataContact.kt | 8 +- .../java/contacts/core/util/DataRawContact.kt | 8 +- .../java/contacts/core/util/DataRefresh.kt | 14 +- .../contacts/core/util/DefaultContactData.kt | 20 +-- .../contacts/entities/custom/gender/Gender.kt | 12 +- .../entities/custom/gender/GenderDataQuery.kt | 4 +- .../entities/custom/handlename/HandleName.kt | 8 +- .../custom/handlename/HandleNameDataQuery.kt | 4 +- howto/howto-learn-more-about-api-entities.md | 8 +- howto/howto-query-accounts.md | 2 +- howto/howto-query-contacts-advanced.md | 2 +- howto/howto-query-contacts.md | 2 +- howto/howto-query-data-sets.md | 51 +++--- howto/howto-query-groups.md | 2 +- howto/howto-query-raw-contacts.md | 2 +- howto/howto-update-data-sets.md | 5 +- .../data/DataPermissionsRequest.kt | 8 +- .../java/contacts/test/entities/TestData.kt | 4 +- .../contacts/test/entities/TestDataQuery.kt | 4 +- .../ui/entities/CommonDataEntityFactory.kt | 42 ----- .../entities/CommonDataEntityTypeFactory.kt | 161 ------------------ .../contacts/ui/entities/DataEntityFactory.kt | 42 +++++ ...monDataEntityType.kt => DataEntityType.kt} | 8 +- .../ui/entities/DataEntityTypeFactory.kt | 161 ++++++++++++++++++ .../java/contacts/ui/view/AddressesView.kt | 10 +- ...ntityListView.kt => DataEntityListView.kt} | 14 +- ...monDataEntityView.kt => DataEntityView.kt} | 11 +- ...tView.kt => DataEntityWithTypeListView.kt} | 19 +-- ...hTypeView.kt => DataEntityWithTypeView.kt} | 29 ++-- .../main/java/contacts/ui/view/EmailsView.kt | 10 +- .../main/java/contacts/ui/view/EventsView.kt | 10 +- ui/src/main/java/contacts/ui/view/ImsView.kt | 10 +- .../java/contacts/ui/view/NicknameView.kt | 4 +- .../java/contacts/ui/view/OrganizationView.kt | 4 +- .../main/java/contacts/ui/view/PhonesView.kt | 10 +- .../java/contacts/ui/view/RelationsView.kt | 10 +- .../java/contacts/ui/view/SipAddressView.kt | 4 +- .../java/contacts/ui/view/WebsitesView.kt | 10 +- ...n_data_entity.xml => view_data_entity.xml} | 0 ...ype.xml => view_data_entity_with_type.xml} | 0 98 files changed, 683 insertions(+), 678 deletions(-) rename core/src/main/java/contacts/core/entities/{CommonDataEntity.kt => DataEntity.kt} (85%) rename core/src/main/java/contacts/core/entities/{CommonDataFields.kt => MimeTypeDataFields.kt} (74%) create mode 100644 core/src/main/java/contacts/core/entities/custom/CustomData.kt delete mode 100644 core/src/main/java/contacts/core/entities/custom/CustomDataEntity.kt rename core/src/main/java/contacts/core/entities/operation/{AbstractCommonDataOperation.kt => AbstractDataOperation.kt} (99%) delete mode 100644 ui/src/main/java/contacts/ui/entities/CommonDataEntityFactory.kt delete mode 100644 ui/src/main/java/contacts/ui/entities/CommonDataEntityTypeFactory.kt create mode 100644 ui/src/main/java/contacts/ui/entities/DataEntityFactory.kt rename ui/src/main/java/contacts/ui/entities/{CommonDataEntityType.kt => DataEntityType.kt} (75%) create mode 100644 ui/src/main/java/contacts/ui/entities/DataEntityTypeFactory.kt rename ui/src/main/java/contacts/ui/view/{CommonDataEntityListView.kt => DataEntityListView.kt} (88%) rename ui/src/main/java/contacts/ui/view/{CommonDataEntityView.kt => DataEntityView.kt} (91%) rename ui/src/main/java/contacts/ui/view/{CommonDataEntityWithTypeListView.kt => DataEntityWithTypeListView.kt} (78%) rename ui/src/main/java/contacts/ui/view/{CommonDataEntityWithTypeView.kt => DataEntityWithTypeView.kt} (86%) rename ui/src/main/res/layout/{view_common_data_entity.xml => view_data_entity.xml} (100%) rename ui/src/main/res/layout/{view_common_data_entity_with_type.xml => view_data_entity_with_type.xml} (100%) diff --git a/DEV_NOTES.md b/DEV_NOTES.md index affdf3ea..319b2b01 100644 --- a/DEV_NOTES.md +++ b/DEV_NOTES.md @@ -313,7 +313,7 @@ The Contacts Provider may consolidate multiple contacts belonging to different a them into a single entry in the Contacts table whilst maintaining the separate entries in the RawContacts table. -A more common scenario that causes multiple RawContacts per Contact is when two or more Contacts are +A more likely scenario that causes multiple RawContacts per Contact is when two or more Contacts are "linked" (or "merged" for API 23 and below, or "joined" for API 22 and below). ### Behavior of linking/merging/joining contacts (AggregationExceptions) @@ -1149,7 +1149,7 @@ last! I left comments all over the code on when an androidx dependency may be useful. The most glaring example of this is @WorkerThread. Even with that, I'll hold off on adding the androidx annotation -lib. I think we can all be consenting adults and apply some common sense. +lib. I think we can all be consenting adults =) If the community strongly desires the addition of these support libs, then the community will win =) diff --git a/README.md b/README.md index e41365a7..bd5579b9 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ val emails = Contacts(context) .find() ``` -It's not just for emails. It's for all common data kinds (including custom data). +It's not just for emails. It's for all data kinds (including custom data). > For more info, read [How do I get a list of specific data kinds?](/howto/howto-query-data-sets.md) @@ -416,7 +416,7 @@ The find function optionally takes in a function that, if it returns true, will processing as soon as possible. The function is called numerous times during query processing to check if processing should stop or continue. This gives you the option to cancel the query. -This is useful when used in multi-threaded environments. One scenario where this would be commonly +This is useful when used in multi-threaded environments. One scenario where this would be frequently used is when performing queries as the user types a search text. You are able to cancel the current query when the user enters new text. diff --git a/async/src/main/java/contacts/async/data/DataQueryAsync.kt b/async/src/main/java/contacts/async/data/DataQueryAsync.kt index c77aa300..eb54a04b 100644 --- a/async/src/main/java/contacts/async/data/DataQueryAsync.kt +++ b/async/src/main/java/contacts/async/data/DataQueryAsync.kt @@ -1,9 +1,9 @@ package contacts.async.data import contacts.async.ASYNC_DISPATCHER -import contacts.core.CommonDataField -import contacts.core.data.CommonDataQuery -import contacts.core.entities.CommonDataEntity +import contacts.core.DataField +import contacts.core.data.DataQuery +import contacts.core.entities.ImmutableData import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext @@ -13,9 +13,9 @@ import kotlin.coroutines.CoroutineContext * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataQuery.find]. + * See [DataQuery.find]. */ -suspend fun CommonDataQuery.findWithContext( +suspend fun DataQuery.findWithContext( context: CoroutineContext = ASYNC_DISPATCHER ): List = withContext(context) { find { !isActive } } @@ -26,8 +26,8 @@ suspend fun CommonDataQuery.fi * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataQuery.find]. + * See [DataQuery.find]. */ -fun CommonDataQuery.findAsync( +fun DataQuery.findAsync( context: CoroutineContext = ASYNC_DISPATCHER ): Deferred> = CoroutineScope(context).async { find { !isActive } } \ No newline at end of file diff --git a/async/src/main/java/contacts/async/util/DataContactAsync.kt b/async/src/main/java/contacts/async/util/DataContactAsync.kt index 177e9bbb..217dfe09 100644 --- a/async/src/main/java/contacts/async/util/DataContactAsync.kt +++ b/async/src/main/java/contacts/async/util/DataContactAsync.kt @@ -2,7 +2,7 @@ package contacts.async.util import contacts.async.ASYNC_DISPATCHER import contacts.core.Contacts -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.Contact import contacts.core.util.contact import kotlinx.coroutines.* @@ -14,9 +14,9 @@ import kotlin.coroutines.CoroutineContext * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataEntity.contact]. + * See [DataEntity.contact]. */ -suspend fun CommonDataEntity.contactWithContext( +suspend fun DataEntity.contactWithContext( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Contact? = withContext(coroutineContext) { contact(contacts) { !isActive } } @@ -27,9 +27,9 @@ suspend fun CommonDataEntity.contactWithContext( * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataEntity.contact]. + * See [DataEntity.contact]. */ -fun CommonDataEntity.contactAsync( +fun DataEntity.contactAsync( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Deferred = CoroutineScope(coroutineContext).async { contact(contacts) { !isActive } } \ No newline at end of file diff --git a/async/src/main/java/contacts/async/util/DataRawContactAsync.kt b/async/src/main/java/contacts/async/util/DataRawContactAsync.kt index ee4cc27c..a3d9df46 100644 --- a/async/src/main/java/contacts/async/util/DataRawContactAsync.kt +++ b/async/src/main/java/contacts/async/util/DataRawContactAsync.kt @@ -2,7 +2,7 @@ package contacts.async.util import contacts.async.ASYNC_DISPATCHER import contacts.core.Contacts -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.RawContact import contacts.core.util.rawContact import kotlinx.coroutines.* @@ -14,9 +14,9 @@ import kotlin.coroutines.CoroutineContext * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataEntity.rawContact]. + * See [DataEntity.rawContact]. */ -suspend fun CommonDataEntity.rawContactWithContext( +suspend fun DataEntity.rawContactWithContext( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): RawContact? = withContext(coroutineContext) { @@ -29,9 +29,9 @@ suspend fun CommonDataEntity.rawContactWithContext( * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataEntity.rawContact]. + * See [DataEntity.rawContact]. */ -fun CommonDataEntity.rawContactAsync( +fun DataEntity.rawContactAsync( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Deferred = CoroutineScope(coroutineContext).async { diff --git a/async/src/main/java/contacts/async/util/DataRefreshAsync.kt b/async/src/main/java/contacts/async/util/DataRefreshAsync.kt index b62343ed..81b607e8 100644 --- a/async/src/main/java/contacts/async/util/DataRefreshAsync.kt +++ b/async/src/main/java/contacts/async/util/DataRefreshAsync.kt @@ -2,7 +2,8 @@ package contacts.async.util import contacts.async.ASYNC_DISPATCHER import contacts.core.Contacts -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity +import contacts.core.entities.ImmutableData import contacts.core.util.refresh import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext @@ -13,9 +14,9 @@ import kotlin.coroutines.CoroutineContext * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataEntity.refresh]. + * See [ImmutableData.refresh]. */ -suspend fun T.refreshWithContext( +suspend fun T.refreshWithContext( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): T? = withContext(coroutineContext) { @@ -28,9 +29,9 @@ suspend fun T.refreshWithContext( * * Computations automatically stops if the parent coroutine scope / job is cancelled. * - * See [CommonDataEntity.refresh]. + * See [ImmutableData.refresh]. */ -fun T.refreshAsync( +fun T.refreshAsync( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Deferred = CoroutineScope(coroutineContext).async { diff --git a/async/src/main/java/contacts/async/util/DefaultContactDataAsync.kt b/async/src/main/java/contacts/async/util/DefaultContactDataAsync.kt index 7345fa09..da92098b 100644 --- a/async/src/main/java/contacts/async/util/DefaultContactDataAsync.kt +++ b/async/src/main/java/contacts/async/util/DefaultContactDataAsync.kt @@ -2,7 +2,7 @@ package contacts.async.util import contacts.async.ASYNC_DISPATCHER import contacts.core.Contacts -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.util.clearDefault import contacts.core.util.setAsDefault import kotlinx.coroutines.CoroutineScope @@ -15,9 +15,9 @@ import kotlin.coroutines.CoroutineContext * Suspends the current coroutine, performs the operation in the given [coroutineContext], then * returns the result. * - * See [CommonDataEntity.setAsDefault]. + * See [DataEntity.setAsDefault]. */ -suspend fun CommonDataEntity.setAsDefaultWithContext( +suspend fun DataEntity.setAsDefaultWithContext( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Boolean = withContext(coroutineContext) { setAsDefault(contacts) } @@ -26,9 +26,9 @@ suspend fun CommonDataEntity.setAsDefaultWithContext( * Suspends the current coroutine, performs the operation in the given [coroutineContext], then * returns the result. * - * See [CommonDataEntity.clearDefault]. + * See [DataEntity.clearDefault]. */ -suspend fun CommonDataEntity.clearDefaultWithContext( +suspend fun DataEntity.clearDefaultWithContext( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Boolean = withContext(coroutineContext) { clearDefault(contacts) } @@ -37,9 +37,9 @@ suspend fun CommonDataEntity.clearDefaultWithContext( * Creates a [CoroutineScope] with the given [coroutineContext], performs the operation in that * scope, then returns the [Deferred] result. * - * See [CommonDataEntity.setAsDefault]. + * See [DataEntity.setAsDefault]. */ -fun CommonDataEntity.setAsDefaultAsync( +fun DataEntity.setAsDefaultAsync( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Deferred = CoroutineScope(coroutineContext).async { setAsDefault(contacts) } @@ -48,9 +48,9 @@ fun CommonDataEntity.setAsDefaultAsync( * Creates a [CoroutineScope] with the given [coroutineContext], performs the operation in that * scope, then returns the [Deferred] result. * - * See [CommonDataEntity.clearDefault]. + * See [DataEntity.clearDefault]. */ -fun CommonDataEntity.clearDefaultAsync( +fun DataEntity.clearDefaultAsync( contacts: Contacts, coroutineContext: CoroutineContext = ASYNC_DISPATCHER ): Deferred = CoroutineScope(coroutineContext).async { clearDefault(contacts) } \ No newline at end of file diff --git a/core/src/main/java/contacts/core/Contacts.kt b/core/src/main/java/contacts/core/Contacts.kt index 1db05bf6..429e3713 100644 --- a/core/src/main/java/contacts/core/Contacts.kt +++ b/core/src/main/java/contacts/core/Contacts.kt @@ -120,7 +120,7 @@ interface Contacts { val applicationContext: Context /** - * Provides functions required to support custom common data, which have [MimeType.Custom]. + * Provides functions required to support custom data, which have [MimeType.Custom]. */ val customDataRegistry: CustomDataRegistry } diff --git a/core/src/main/java/contacts/core/Fields.kt b/core/src/main/java/contacts/core/Fields.kt index 0b98323b..743ce76e 100644 --- a/core/src/main/java/contacts/core/Fields.kt +++ b/core/src/main/java/contacts/core/Fields.kt @@ -110,7 +110,7 @@ sealed class AbstractDataFieldSet : FieldSet() { abstract val forMatching: Set } -data class DataField internal constructor( +data class GenericDataField internal constructor( override val columnName: String, override val required: Boolean = false, ) : AbstractDataField() @@ -122,7 +122,7 @@ data class DataField internal constructor( * For a shorter name, use [F] (useful for Kotlin-ers). * * The real (more technically correct) name of this object is [DataFields]. The name "Fields" is - * used here so that Java consumers may be able to access these most commonly used fields using a + * used here so that Java consumers may be able to access these most frequently used fields using a * shorter name than "DataFields". * * ## Developer Notes @@ -141,7 +141,7 @@ object Fields : AbstractDataFieldSet() { val Contact = DataContactsFields() @JvmField - val DataId = DataField(Data._ID, required = true) + val DataId = GenericDataField(Data._ID, required = true) @JvmField val Email = EmailFields() @@ -156,12 +156,12 @@ object Fields : AbstractDataFieldSet() { val Im = ImFields() @JvmField - val IsPrimary = DataField(Data.IS_PRIMARY, required = true) + val IsPrimary = GenericDataField(Data.IS_PRIMARY, required = true) @JvmField - val IsSuperPrimary = DataField(Data.IS_SUPER_PRIMARY, required = true) + val IsSuperPrimary = GenericDataField(Data.IS_SUPER_PRIMARY, required = true) - internal val MimeType = DataField(Data.MIMETYPE, required = true) + internal val MimeType = GenericDataField(Data.MIMETYPE, required = true) @JvmField val Name = NameFields() @@ -420,20 +420,20 @@ class DataRawContactsFields internal constructor() : AbstractDataFieldSet() { +internal object EmptyDataFields : AbstractDataFieldSet() { - override val all = emptySet() + override val all = emptySet() - override val forMatching = emptySet() + override val forMatching = emptySet() } -data class AddressField internal constructor(override val columnName: String) : CommonDataField() { +data class AddressField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Address } @@ -483,7 +483,7 @@ class AddressFields internal constructor() : AbstractDataFieldSet( } } -data class EmailField internal constructor(override val columnName: String) : CommonDataField() { +data class EmailField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Email } @@ -508,7 +508,7 @@ class EmailFields internal constructor() : AbstractDataFieldSet() { } } -data class EventField internal constructor(override val columnName: String) : CommonDataField() { +data class EventField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Event } @@ -532,7 +532,7 @@ class EventFields internal constructor() : AbstractDataFieldSet() { } data class GroupMembershipField internal constructor(override val columnName: String) : - CommonDataField() { + DataField() { override val mimeType: MimeType = MimeType.GroupMembership } @@ -549,7 +549,7 @@ class GroupMembershipFields internal constructor() : AbstractDataFieldSet() } -data class ImField internal constructor(override val columnName: String) : CommonDataField() { +data class ImField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Im } @@ -582,7 +582,7 @@ class ImFields internal constructor() : AbstractDataFieldSet() { } } -data class NameField internal constructor(override val columnName: String) : CommonDataField() { +data class NameField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Name } @@ -630,7 +630,7 @@ class NameFields internal constructor() : AbstractDataFieldSet() { } } -data class NicknameField internal constructor(override val columnName: String) : CommonDataField() { +data class NicknameField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Nickname } @@ -649,7 +649,7 @@ class NicknameFields internal constructor() : AbstractDataFieldSet() { } data class OrganizationField internal constructor(override val columnName: String) : - CommonDataField() { + DataField() { override val mimeType: MimeType = MimeType.Organization } @@ -710,7 +710,7 @@ class OrganizationFields internal constructor() : AbstractDataFieldSet() { } internal data class PhotoField internal constructor(override val columnName: String) : - CommonDataField() { + DataField() { override val mimeType: MimeType = MimeType.Photo } @@ -757,7 +757,7 @@ internal class PhotoFields internal constructor() : AbstractDataFieldSet() } -data class RelationField internal constructor(override val columnName: String) : CommonDataField() { +data class RelationField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Relation } @@ -782,8 +782,7 @@ class RelationFields internal constructor() : AbstractDataFieldSet() } -data class SipAddressField internal constructor(override val columnName: String) : - CommonDataField() { +data class SipAddressField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.SipAddress } @@ -802,7 +801,7 @@ class SipAddressFields internal constructor() : AbstractDataFieldSet() } -data class WebsiteField internal constructor(override val columnName: String) : CommonDataField() { +data class WebsiteField internal constructor(override val columnName: String) : DataField() { override val mimeType: MimeType = MimeType.Website } @@ -824,19 +823,19 @@ class WebsiteFields internal constructor() : AbstractDataFieldSet( // region Custom Data Fields /** - * An abstract class that is used as a base of all custom common data fields. + * An abstract class that is used as a base of all custom data fields. * * ## Developer notes * * This had to be declared here instead of in the [contacts.core.entities.custom] package because - * [CommonDataField] is sealed. + * [DataField] is sealed. */ abstract class AbstractCustomDataField( /** * The name of this column. Must be one of [ColumnName]. */ columnName: ColumnName -) : CommonDataField() { +) : DataField() { protected abstract val customMimeType: MimeType.Custom diff --git a/core/src/main/java/contacts/core/Insert.kt b/core/src/main/java/contacts/core/Insert.kt index df2af792..4b6fb6bd 100644 --- a/core/src/main/java/contacts/core/Insert.kt +++ b/core/src/main/java/contacts/core/Insert.kt @@ -121,7 +121,7 @@ interface Insert { * * ## Note * - * The use case for this function is probably not common. You can simply not set a particular + * The use case for this function is probably rare. You can simply not set a particular * data instead of using this function. For example, if you want to create a new RawContact * with only name and email data, just set only name and email... * diff --git a/core/src/main/java/contacts/core/Where.kt b/core/src/main/java/contacts/core/Where.kt index 1c7bc1d5..5b78ad1c 100644 --- a/core/src/main/java/contacts/core/Where.kt +++ b/core/src/main/java/contacts/core/Where.kt @@ -1,7 +1,7 @@ package contacts.core import android.database.DatabaseUtils -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.EventDate import contacts.core.entities.MimeType import contacts.core.entities.toWhereString @@ -438,7 +438,7 @@ private fun where(field: Field, operator: String, value: Any?, options: String? where += " $options" } - if (field is CommonDataField && field.mimeType.value.isNotBlank()) { + if (field is DataField && field.mimeType.value.isNotBlank()) { where += " AND ${Fields.MimeType.columnName} = '${field.mimeType.value}'" } return where @@ -537,7 +537,7 @@ private fun Any?.toSqlString(): String = when (this) { is Collection<*> -> this.asSequence().toSqlString() is Sequence<*> -> this.map { it?.toSqlString() } .joinToString(separator = ", ", prefix = "(", postfix = ")") - is CommonDataEntity.Type -> value.toSqlString() + is DataEntity.Type -> value.toSqlString() is Date -> time.toString() // we will not assume that all dates are for EventDate comparisons. is EventDate -> toWhereString() is MimeType -> value.toSqlString() diff --git a/core/src/main/java/contacts/core/data/Data.kt b/core/src/main/java/contacts/core/data/Data.kt index 84fcddf3..45025503 100644 --- a/core/src/main/java/contacts/core/data/Data.kt +++ b/core/src/main/java/contacts/core/data/Data.kt @@ -5,7 +5,7 @@ import contacts.core.Contacts import contacts.core.ContactsPermissions /** - * Provides new [DataQuery], [DataUpdate], and [DataDelete] for Profile OR non-Profile (depending on + * Provides new [DataQueryFactory], [DataUpdate], and [DataDelete] for Profile OR non-Profile (depending on * instance) operations. * * Note that there is no DataInsert as data is required to be associated with a RawContact. @@ -22,10 +22,10 @@ import contacts.core.ContactsPermissions interface Data { /** - * Returns a new [DataQuery] instance for Profile OR non-Profile (depending on instance) data + * Returns a new [DataQueryFactory] instance for Profile OR non-Profile (depending on instance) data * queries. */ - fun query(): DataQuery + fun query(): DataQueryFactory /** * Returns a new [DataUpdate] instance for Profile OR non-Profile (depending on instance) data diff --git a/core/src/main/java/contacts/core/data/DataDelete.kt b/core/src/main/java/contacts/core/data/DataDelete.kt index ac122454..201a0737 100644 --- a/core/src/main/java/contacts/core/data/DataDelete.kt +++ b/core/src/main/java/contacts/core/data/DataDelete.kt @@ -3,7 +3,7 @@ package contacts.core.data import android.content.ContentProviderOperation.newDelete import android.content.ContentResolver import contacts.core.* -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.operation.withSelection import contacts.core.entities.table.ProfileUris import contacts.core.entities.table.Table @@ -28,7 +28,7 @@ import contacts.core.util.unsafeLazy * * ## Usage * - * To delete a [CommonDataEntity]; + * To delete a [DataEntity]; * * ```kotlin * val result = dataDelete @@ -53,20 +53,20 @@ interface DataDelete { * Those that have been manually created via a constructor will be ignored and result in a * failed operation. */ - fun data(vararg data: CommonDataEntity): DataDelete + fun data(vararg data: DataEntity): DataDelete /** * See [DataDelete.data]. */ - fun data(data: Collection): DataDelete + fun data(data: Collection): DataDelete /** * See [DataDelete.data]. */ - fun data(data: Sequence): DataDelete + fun data(data: Sequence): DataDelete /** - * Deletes the [CommonDataEntity]s in the queue (added via [data]) and returns the [Result]. + * Deletes the [DataEntity]s in the queue (added via [data]) and returns the [Result]. * * ## Permissions * @@ -80,7 +80,7 @@ interface DataDelete { fun commit(): Result /** - * Deletes the [CommonDataEntity]s in the queue (added via [data]) in one transaction. Either ALL + * Deletes the [DataEntity]s in the queue (added via [data]) in one transaction. Either ALL * deletes succeed or ALL fail. * * ## Permissions @@ -104,7 +104,7 @@ interface DataDelete { /** * True if the [data] has been successfully deleted. False otherwise. */ - fun isSuccessful(data: CommonDataEntity): Boolean + fun isSuccessful(data: DataEntity): Boolean } } @@ -130,11 +130,11 @@ private class DataDeleteImpl( } """.trimIndent() - override fun data(vararg data: CommonDataEntity) = data(data.asSequence()) + override fun data(vararg data: DataEntity) = data(data.asSequence()) - override fun data(data: Collection) = data(data.asSequence()) + override fun data(data: Collection) = data(data.asSequence()) - override fun data(data: Sequence): DataDelete = apply { + override fun data(data: Sequence): DataDelete = apply { dataIds.addAll(data.map { it.id ?: INVALID_ID }) } @@ -201,7 +201,7 @@ private class DataDeleteResult( override val isSuccessful: Boolean by unsafeLazy { dataIdsResultMap.all { it.value } } - override fun isSuccessful(data: CommonDataEntity): Boolean = + override fun isSuccessful(data: DataEntity): Boolean = data.id?.let { dataId -> dataIdsResultMap.getOrElse(dataId) { false } } ?: false @@ -211,5 +211,5 @@ private class DataDeleteFailed : DataDelete.Result { override val isSuccessful: Boolean = false - override fun isSuccessful(data: CommonDataEntity): Boolean = false + override fun isSuccessful(data: DataEntity): Boolean = false } \ No newline at end of file diff --git a/core/src/main/java/contacts/core/data/DataQuery.kt b/core/src/main/java/contacts/core/data/DataQuery.kt index 9ab9c941..28f5f4b9 100644 --- a/core/src/main/java/contacts/core/data/DataQuery.kt +++ b/core/src/main/java/contacts/core/data/DataQuery.kt @@ -5,7 +5,7 @@ import android.content.ContentResolver import contacts.core.* import contacts.core.entities.* import contacts.core.entities.cursor.rawContactsCursor -import contacts.core.entities.custom.CustomDataEntity +import contacts.core.entities.custom.ImmutableCustomData import contacts.core.entities.mapper.entityMapperFor import contacts.core.entities.table.ProfileUris import contacts.core.entities.table.Table @@ -18,149 +18,150 @@ import contacts.core.util.unsafeLazy * Provides new query instances for specific types of Profile OR non-Profile (depending on instance) * data. */ -interface DataQuery { +interface DataQueryFactory { /** * Queries for [Address]es. */ - fun addresses(): CommonDataQuery + fun addresses(): DataQuery /** * Queries for [Email]s. */ - fun emails(): CommonDataQuery + fun emails(): DataQuery /** * Queries for [Event]s. */ - fun events(): CommonDataQuery + fun events(): DataQuery /** * Queries for [GroupMembership]s. */ - fun groupMemberships(): CommonDataQuery + fun groupMemberships(): DataQuery /** * Queries for [Im]s. */ - fun ims(): CommonDataQuery + fun ims(): DataQuery /** * Queries for [Name]s. */ - fun names(): CommonDataQuery + fun names(): DataQuery /** * Queries for [Nickname]s. */ - fun nicknames(): CommonDataQuery + fun nicknames(): DataQuery /** * Queries for [Note]s. */ - fun notes(): CommonDataQuery + fun notes(): DataQuery /** * Queries for [Organization]s. */ - fun organizations(): CommonDataQuery + fun organizations(): DataQuery /** * Queries for [Phone]s. */ - fun phones(): CommonDataQuery + fun phones(): DataQuery // Photos are intentionally left out as it is internal to the library. /** * Queries for [Relation]s. */ - fun relations(): CommonDataQuery + fun relations(): DataQuery /** * Queries for [SipAddress]es. */ - fun sipAddresses(): CommonDataQuery + fun sipAddresses(): DataQuery /** * Queries for [Website]s. */ - fun websites(): CommonDataQuery + fun websites(): DataQuery /** * Queries for custom data of type [E] with the given custom [mimeType]. */ - fun - customData(mimeType: MimeType.Custom): CommonDataQuery + fun + customData(mimeType: MimeType.Custom): DataQuery } @Suppress("FunctionName") -internal fun DataQuery(contacts: Contacts, isProfile: Boolean): DataQuery = DataQueryImpl( - contacts, isProfile -) +internal fun DataQuery(contacts: Contacts, isProfile: Boolean): DataQueryFactory = + DataQueryFactoryImpl( + contacts, isProfile + ) -private class DataQueryImpl( +private class DataQueryFactoryImpl( private val contacts: Contacts, private val isProfile: Boolean -) : DataQuery { +) : DataQueryFactory { - override fun addresses(): CommonDataQuery = CommonDataQueryImpl( + override fun addresses(): DataQuery = DataQueryImpl( contacts, Fields.Address, MimeType.Address, isProfile ) - override fun emails(): CommonDataQuery = CommonDataQueryImpl( + override fun emails(): DataQuery = DataQueryImpl( contacts, Fields.Email, MimeType.Email, isProfile ) - override fun events(): CommonDataQuery = CommonDataQueryImpl( + override fun events(): DataQuery = DataQueryImpl( contacts, Fields.Event, MimeType.Event, isProfile ) - override fun groupMemberships(): CommonDataQuery = - CommonDataQueryImpl( + override fun groupMemberships(): DataQuery = + DataQueryImpl( contacts, Fields.GroupMembership, MimeType.GroupMembership, isProfile ) - override fun ims(): CommonDataQuery = CommonDataQueryImpl( + override fun ims(): DataQuery = DataQueryImpl( contacts, Fields.Im, MimeType.Im, isProfile ) - override fun names(): CommonDataQuery = CommonDataQueryImpl( + override fun names(): DataQuery = DataQueryImpl( contacts, Fields.Name, MimeType.Name, isProfile ) - override fun nicknames(): CommonDataQuery = CommonDataQueryImpl( + override fun nicknames(): DataQuery = DataQueryImpl( contacts, Fields.Nickname, MimeType.Nickname, isProfile ) - override fun notes(): CommonDataQuery = CommonDataQueryImpl( + override fun notes(): DataQuery = DataQueryImpl( contacts, Fields.Note, MimeType.Note, isProfile ) - override fun organizations(): CommonDataQuery = - CommonDataQueryImpl( + override fun organizations(): DataQuery = + DataQueryImpl( contacts, Fields.Organization, MimeType.Organization, isProfile ) - override fun phones(): CommonDataQuery = CommonDataQueryImpl( + override fun phones(): DataQuery = DataQueryImpl( contacts, Fields.Phone, MimeType.Phone, isProfile ) - override fun relations(): CommonDataQuery = CommonDataQueryImpl( + override fun relations(): DataQuery = DataQueryImpl( contacts, Fields.Relation, MimeType.Relation, isProfile ) - override fun sipAddresses(): CommonDataQuery = CommonDataQueryImpl( + override fun sipAddresses(): DataQuery = DataQueryImpl( contacts, Fields.SipAddress, MimeType.SipAddress, isProfile ) - override fun websites(): CommonDataQuery = CommonDataQueryImpl( + override fun websites(): DataQuery = DataQueryImpl( contacts, Fields.Website, MimeType.Website, isProfile ) @Suppress("UNCHECKED_CAST") - override fun - customData(mimeType: MimeType.Custom): CommonDataQuery = CommonDataQueryImpl( + override fun + customData(mimeType: MimeType.Custom): DataQuery = DataQueryImpl( contacts, contacts.customDataRegistry.entryOf(mimeType).fieldSet as AbstractCustomDataFieldSet, mimeType, isProfile @@ -212,7 +213,7 @@ private class DataQueryImpl( * .find(); * ``` */ -interface CommonDataQuery { +interface DataQuery { /** * Limits this query to only search for data associated with one of the given [accounts]. @@ -224,17 +225,17 @@ interface CommonDataQuery { * associated Account to be included in the search. RawContacts without an associated account * are considered local or device-only contacts, which are not synced. */ - fun accounts(vararg accounts: Account?): CommonDataQuery + fun accounts(vararg accounts: Account?): DataQuery /** - * See [CommonDataQuery.accounts] + * See [DataQuery.accounts] */ - fun accounts(accounts: Collection): CommonDataQuery + fun accounts(accounts: Collection): DataQuery /** - * See [CommonDataQuery.accounts] + * See [DataQuery.accounts] */ - fun accounts(accounts: Sequence): CommonDataQuery + fun accounts(accounts: Sequence): DataQuery /** * Includes the given set of [fields] of type [F] in the resulting data objects of type [E]. @@ -277,17 +278,17 @@ interface CommonDataQuery { * include/exclude in queries, inserts, and update, which will allow you to do things beyond * your wildest imagination! */ - fun include(vararg fields: F): CommonDataQuery + fun include(vararg fields: F): DataQuery /** - * See [CommonDataQuery.include]. + * See [DataQuery.include]. */ - fun include(fields: Collection): CommonDataQuery + fun include(fields: Collection): DataQuery /** - * See [CommonDataQuery.include]. + * See [DataQuery.include]. */ - fun include(fields: Sequence): CommonDataQuery + fun include(fields: Sequence): DataQuery /** * Filters the returned data matching the criteria defined by the [where]. @@ -304,10 +305,9 @@ interface CommonDataQuery { * [Fields.RawContact], [Fields.IsSuperPrimary], etc... * * This allows consumers to make a mistake about trying to match addresses using phone fields. - * At this point, I'll say we are consenting adults (Python motto if you don't know) and we need - * to apply some common sense =) + * At this point, I'll say we are consenting adults (Python motto if you don't know). */ - fun where(where: Where?): CommonDataQuery + fun where(where: Where?): DataQuery /** * Orders the returned data using one or more [orderBy]s. If not specified, then data is ordered @@ -317,31 +317,31 @@ interface CommonDataQuery { * optional parameter. */ @SafeVarargs - fun orderBy(vararg orderBy: OrderBy): CommonDataQuery + fun orderBy(vararg orderBy: OrderBy): DataQuery /** - * See [CommonDataQuery.orderBy]. + * See [DataQuery.orderBy]. */ - fun orderBy(orderBy: Collection>): CommonDataQuery + fun orderBy(orderBy: Collection>): DataQuery /** - * See [CommonDataQuery.orderBy]. + * See [DataQuery.orderBy]. */ - fun orderBy(orderBy: Sequence>): CommonDataQuery + fun orderBy(orderBy: Sequence>): DataQuery /** * Limits the maximum number of returned data to the given [limit]. * * If not specified, limit value of [Int.MAX_VALUE] is used. */ - fun limit(limit: Int): CommonDataQuery + fun limit(limit: Int): DataQuery /** * Skips results 0 to [offset] (excluding the offset). * * If not specified, offset value of 0 is used. */ - fun offset(offset: Int): CommonDataQuery + fun offset(offset: Int): DataQuery /** * The list of [E]s. @@ -382,7 +382,7 @@ interface CommonDataQuery { fun find(cancel: () -> Boolean): List } -private class CommonDataQueryImpl( +private class DataQueryImpl( private val contacts: Contacts, private val defaultIncludeFields: FieldSet, @@ -399,7 +399,7 @@ private class CommonDataQueryImpl( private var orderBy: CompoundOrderBy = DEFAULT_ORDER_BY, private var limit: Int = DEFAULT_LIMIT, private var offset: Int = DEFAULT_OFFSET -) : CommonDataQuery { +) : DataQuery { override fun toString(): String = """ @@ -419,7 +419,7 @@ private class CommonDataQueryImpl( override fun accounts(accounts: Collection) = accounts(accounts.asSequence()) - override fun accounts(accounts: Sequence): CommonDataQuery = apply { + override fun accounts(accounts: Sequence): DataQuery = apply { rawContactsWhere = accounts.toRawContactsWhere() } @@ -427,7 +427,7 @@ private class CommonDataQueryImpl( override fun include(fields: Collection) = include(fields.asSequence()) - override fun include(fields: Sequence): CommonDataQuery = apply { + override fun include(fields: Sequence): DataQuery = apply { val includeFields = if (fields.isEmpty()) { defaultIncludeFields.all.asSequence() } else { @@ -437,7 +437,7 @@ private class CommonDataQueryImpl( include = Include(includeFields + REQUIRED_INCLUDE_FIELDS) } - override fun where(where: Where?): CommonDataQuery = apply { + override fun where(where: Where?): DataQuery = apply { // Yes, I know DEFAULT_WHERE is null. This reads better though. this.where = where ?: DEFAULT_WHERE } @@ -446,7 +446,7 @@ private class CommonDataQueryImpl( override fun orderBy(orderBy: Collection>) = orderBy(orderBy.asSequence()) - override fun orderBy(orderBy: Sequence>): CommonDataQuery = apply { + override fun orderBy(orderBy: Sequence>): DataQuery = apply { this.orderBy = if (orderBy.isEmpty()) { DEFAULT_ORDER_BY } else { @@ -454,7 +454,7 @@ private class CommonDataQueryImpl( } } - override fun limit(limit: Int): CommonDataQuery = apply { + override fun limit(limit: Int): DataQuery = apply { this.limit = if (limit > 0) { limit } else { @@ -462,7 +462,7 @@ private class CommonDataQueryImpl( } } - override fun offset(offset: Int): CommonDataQuery = apply { + override fun offset(offset: Int): DataQuery = apply { this.offset = if (offset >= 0) { offset } else { @@ -492,7 +492,7 @@ private class CommonDataQueryImpl( } } -internal fun Contacts.resolveDataEntity( +internal fun Contacts.resolveDataEntity( isProfile: Boolean, mimeType: MimeType, rawContactsWhere: Where?, @@ -566,7 +566,7 @@ private fun ContentResolver.findRawContactIdsInRawContactsTable( /* Phones, Emails, and Addresses have a CONTENT_URI that contains all rows consisting of only those data kinds. Other data kinds do not have this content uri. These probably exists as an index / -for optimization since phones, emails, and addresses are the most commonly used data kinds. Using +for optimization since phones, emails, and addresses are the most frequently used data kinds. Using these CONTENT_URIs probably results in shorter search times since it only has to look through a subset of data instead of the entire data table. diff --git a/core/src/main/java/contacts/core/data/DataUpdate.kt b/core/src/main/java/contacts/core/data/DataUpdate.kt index 3ca41feb..52c1fa49 100644 --- a/core/src/main/java/contacts/core/data/DataUpdate.kt +++ b/core/src/main/java/contacts/core/data/DataUpdate.kt @@ -2,7 +2,7 @@ package contacts.core.data import android.content.ContentResolver import contacts.core.* -import contacts.core.entities.MutableCommonDataEntity +import contacts.core.entities.MutableData import contacts.core.entities.custom.CustomDataRegistry import contacts.core.entities.operation.updateOperation import contacts.core.util.applyBatch @@ -12,7 +12,7 @@ import contacts.core.util.unsafeLazy /** * Updates one or more Profile OR non-Profile (depending on instance) data rows in the data table. * - * Blank data ([MutableCommonDataEntity.isBlank]) will be deleted. For example, if all properties + * Blank data ([MutableData.isBlank]) will be deleted. For example, if all properties * of an email are all null or blank, then the email is deleted. This is the same behavior as the * native Contacts app. This behavior cannot be modified. * @@ -31,7 +31,7 @@ import contacts.core.util.unsafeLazy * * ## Usage * - * To update a set of [MutableCommonDataEntity]; + * To update a set of [MutableData]; * * ```kotlin * val result = dataUpdate @@ -96,26 +96,26 @@ interface DataUpdate { /** * Adds the given [data] to the update queue, which will be updated on [commit]. * - * Blank data ([MutableCommonDataEntity.isBlank] will be deleted instead. + * Blank data ([MutableData.isBlank] will be deleted instead. * * Only existing [data] that have been retrieved via a query will be added to the update queue. * Those that have been manually created via a constructor will be ignored and result in a * failed operation. */ - fun data(vararg data: MutableCommonDataEntity): DataUpdate + fun data(vararg data: MutableData): DataUpdate /** * See [DataUpdate.data]. */ - fun data(data: Collection): DataUpdate + fun data(data: Collection): DataUpdate /** * See [DataUpdate.data]. */ - fun data(data: Sequence): DataUpdate + fun data(data: Sequence): DataUpdate /** - * Updates the [MutableCommonDataEntity]s in the queue (added via [data]) and returns the [Result]. + * Updates the [MutableData]s in the queue (added via [data]) and returns the [Result]. * * ## Permissions * @@ -129,7 +129,7 @@ interface DataUpdate { fun commit(): Result /** - * Updates the [MutableCommonDataEntity]s in the queue (added via [data]) and returns the [Result]. + * Updates the [MutableData]s in the queue (added via [data]) and returns the [Result]. * * ## Permissions * @@ -162,7 +162,7 @@ interface DataUpdate { /** * True if the [data] has been successfully updated. False otherwise. */ - fun isSuccessful(data: MutableCommonDataEntity): Boolean + fun isSuccessful(data: MutableData): Boolean } } @@ -180,7 +180,7 @@ private class DataUpdateImpl( private val customDataRegistry: CustomDataRegistry, private val isProfile: Boolean, private var include: Include = allDataFields(customDataRegistry), - private val data: MutableSet = mutableSetOf() + private val data: MutableSet = mutableSetOf() ) : DataUpdate { override fun toString(): String = @@ -204,11 +204,11 @@ private class DataUpdateImpl( } } - override fun data(vararg data: MutableCommonDataEntity) = data(data.asSequence()) + override fun data(vararg data: MutableData) = data(data.asSequence()) - override fun data(data: Collection) = data(data.asSequence()) + override fun data(data: Collection) = data(data.asSequence()) - override fun data(data: Sequence): DataUpdate = apply { + override fun data(data: Sequence): DataUpdate = apply { this.data.addAll(data) } @@ -250,7 +250,7 @@ private class DataUpdateImpl( private fun ContentResolver.updateData( includeFields: Set, - data: MutableCommonDataEntity, + data: MutableData, customDataRegistry: CustomDataRegistry ): Boolean = data.updateOperation(includeFields, customDataRegistry)?.let { applyBatch(it) } != null @@ -259,7 +259,7 @@ private class DataUpdateResult(private val dataIdsResultMap: Map) override val isSuccessful: Boolean by unsafeLazy { dataIdsResultMap.all { it.value } } - override fun isSuccessful(data: MutableCommonDataEntity): Boolean { + override fun isSuccessful(data: MutableData): Boolean { val dataId = data.id return dataId != null && dataIdsResultMap.getOrElse(dataId) { false } } @@ -269,5 +269,5 @@ private class DataUpdateFailed : DataUpdate.Result { override val isSuccessful: Boolean = false - override fun isSuccessful(data: MutableCommonDataEntity): Boolean = false + override fun isSuccessful(data: MutableData): Boolean = false } diff --git a/core/src/main/java/contacts/core/entities/Address.kt b/core/src/main/java/contacts/core/entities/Address.kt index 83f9a5d0..2ed7bce2 100644 --- a/core/src/main/java/contacts/core/entities/Address.kt +++ b/core/src/main/java/contacts/core/entities/Address.kt @@ -101,7 +101,7 @@ data class Address internal constructor( */ val country: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Address @@ -134,7 +134,7 @@ data class Address internal constructor( country = country ) - enum class Type(override val value: Int) : CommonDataEntity.Type { + enum class Type(override val value: Int) : DataEntity.Type { // Order of declaration is the same as seen in the native contacts app HOME(CommonDataKinds.StructuredPostal.TYPE_HOME), // Default @@ -223,7 +223,7 @@ data class MutableAddress internal constructor( */ var country: String? -) : MutableCommonDataEntityWithType { +) : MutableDataWithType { constructor() : this( null, null, null, false, false, null, null, null, diff --git a/core/src/main/java/contacts/core/entities/CommonDataEntity.kt b/core/src/main/java/contacts/core/entities/DataEntity.kt similarity index 85% rename from core/src/main/java/contacts/core/entities/CommonDataEntity.kt rename to core/src/main/java/contacts/core/entities/DataEntity.kt index cc5d5144..dc4f3e46 100644 --- a/core/src/main/java/contacts/core/entities/CommonDataEntity.kt +++ b/core/src/main/java/contacts/core/entities/DataEntity.kt @@ -5,14 +5,14 @@ import android.provider.ContactsContract import contacts.core.util.isProfileId /** - * [Entity] in the data table that belong to a [RawContact]. + * [Entity] in the Data table that belong to a [RawContact]. * * A RawContact may either have; * - only 0 or 1 * - 0, 1, or more * of this type of entity */ -interface CommonDataEntity : Entity { +interface DataEntity : Entity { /** * The id of the Data row this represents. @@ -124,9 +124,19 @@ interface CommonDataEntity : Entity { } /** - * A [CommonDataEntity] that is mutable, allowing the [primaryValue] to be mutated among others. + * A [DataEntity] that is immutable. + * + * ## Dev note + * + * We are explicitly prepending "Immutable" to the interface name to prevent naming conflicts with + * [contacts.core.data.Data]. + */ +interface ImmutableData : DataEntity + +/** + * A [DataEntity] that is mutable, allowing the [primaryValue] to be mutated among others. */ -interface MutableCommonDataEntity : CommonDataEntity { +interface MutableData : DataEntity { /** * The main value encapsulated by this entity as a string for consumer usage. @@ -135,12 +145,12 @@ interface MutableCommonDataEntity : CommonDataEntity { } /** - * A [MutableCommonDataEntity], with a mutable [type] and [label]. + * A [MutableData], with a mutable [type] and [label]. */ -interface MutableCommonDataEntityWithType : MutableCommonDataEntity { +interface MutableDataWithType : MutableData { /** - * The [CommonDataEntity.Type] of the [primaryValue]. + * The [DataEntity.Type] of the [primaryValue]. */ var type: T? diff --git a/core/src/main/java/contacts/core/entities/Email.kt b/core/src/main/java/contacts/core/entities/Email.kt index d5826794..097910c0 100644 --- a/core/src/main/java/contacts/core/entities/Email.kt +++ b/core/src/main/java/contacts/core/entities/Email.kt @@ -43,7 +43,7 @@ data class Email internal constructor( */ val address: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Email @@ -66,7 +66,7 @@ data class Email internal constructor( address = address ) - enum class Type(override val value: Int) : CommonDataEntity.Type { + enum class Type(override val value: Int) : DataEntity.Type { // Order of declaration is the same as seen in the native contacts app HOME(CommonDataKinds.Email.TYPE_HOME), // Default @@ -123,7 +123,7 @@ data class MutableEmail internal constructor( */ var address: String? -) : MutableCommonDataEntityWithType { +) : MutableDataWithType { constructor() : this( null, null, null, false, false, diff --git a/core/src/main/java/contacts/core/entities/Event.kt b/core/src/main/java/contacts/core/entities/Event.kt index b5924256..a1bf032a 100644 --- a/core/src/main/java/contacts/core/entities/Event.kt +++ b/core/src/main/java/contacts/core/entities/Event.kt @@ -65,7 +65,7 @@ data class Event internal constructor( */ val date: EventDate? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Event @@ -88,7 +88,7 @@ data class Event internal constructor( date = date ) - enum class Type(override val value: Int) : CommonDataEntity.Type { + enum class Type(override val value: Int) : DataEntity.Type { // Order of declaration is the same as seen in the native contacts app BIRTHDAY(CommonDataKinds.Event.TYPE_BIRTHDAY), // Default @@ -151,7 +151,7 @@ data class MutableEvent internal constructor( */ var date: EventDate? -) : MutableCommonDataEntityWithType { +) : MutableDataWithType { constructor() : this( null, null, null, false, false, diff --git a/core/src/main/java/contacts/core/entities/GroupMembership.kt b/core/src/main/java/contacts/core/entities/GroupMembership.kt index bfe655a7..9de9f97a 100644 --- a/core/src/main/java/contacts/core/entities/GroupMembership.kt +++ b/core/src/main/java/contacts/core/entities/GroupMembership.kt @@ -47,7 +47,7 @@ data class GroupMembership internal constructor( */ val groupId: Long? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.GroupMembership diff --git a/core/src/main/java/contacts/core/entities/Im.kt b/core/src/main/java/contacts/core/entities/Im.kt index 5eab9283..46220229 100644 --- a/core/src/main/java/contacts/core/entities/Im.kt +++ b/core/src/main/java/contacts/core/entities/Im.kt @@ -46,7 +46,7 @@ data class Im internal constructor( */ val data: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Im @@ -69,7 +69,7 @@ data class Im internal constructor( data = data ) - enum class Protocol(override val value: Int) : CommonDataEntity.Type { + enum class Protocol(override val value: Int) : DataEntity.Type { // Type is also defined within CmmonDataKinds.Im... Ignore those. Type (and label) may have // been deprecated by protocol and protocol label. Or what probably happened was that there @@ -143,7 +143,7 @@ data class MutableIm internal constructor( */ var data: String? -) : MutableCommonDataEntityWithType { +) : MutableDataWithType { constructor() : this( null, null, null, false, false, diff --git a/core/src/main/java/contacts/core/entities/CommonDataFields.kt b/core/src/main/java/contacts/core/entities/MimeTypeDataFields.kt similarity index 74% rename from core/src/main/java/contacts/core/entities/CommonDataFields.kt rename to core/src/main/java/contacts/core/entities/MimeTypeDataFields.kt index f48bf8a4..a71254ee 100644 --- a/core/src/main/java/contacts/core/entities/CommonDataFields.kt +++ b/core/src/main/java/contacts/core/entities/MimeTypeDataFields.kt @@ -1,14 +1,14 @@ package contacts.core.entities -import contacts.core.CommonDataField -import contacts.core.EmptyCommonDataFields +import contacts.core.DataField +import contacts.core.EmptyDataFields import contacts.core.Fields import contacts.core.entities.custom.CustomDataRegistry -internal fun CommonDataEntity.fields(customDataRegistry: CustomDataRegistry): - Set = mimeType.fields(customDataRegistry) +internal fun DataEntity.fields(customDataRegistry: CustomDataRegistry): + Set = mimeType.fields(customDataRegistry) -internal fun MimeType.fields(customDataRegistry: CustomDataRegistry): Set = +internal fun MimeType.fields(customDataRegistry: CustomDataRegistry): Set = when (this) { MimeType.Address -> Fields.Address MimeType.Email -> Fields.Email @@ -25,5 +25,5 @@ internal fun MimeType.fields(customDataRegistry: CustomDataRegistry): Set Fields.SipAddress MimeType.Website -> Fields.Website is MimeType.Custom -> customDataRegistry.entryOf(this).fieldSet - MimeType.Unknown -> EmptyCommonDataFields + MimeType.Unknown -> EmptyDataFields }.all \ No newline at end of file diff --git a/core/src/main/java/contacts/core/entities/Name.kt b/core/src/main/java/contacts/core/entities/Name.kt index 5b2b3a37..3a3713ff 100644 --- a/core/src/main/java/contacts/core/entities/Name.kt +++ b/core/src/main/java/contacts/core/entities/Name.kt @@ -109,7 +109,7 @@ data class Name internal constructor( */ val phoneticFamilyName: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Name @@ -210,7 +210,7 @@ data class MutableName internal constructor( */ var phoneticFamilyName: String? -) : MutableCommonDataEntity { +) : MutableData { constructor() : this( null, null, null, false, false, null, null, diff --git a/core/src/main/java/contacts/core/entities/Nickname.kt b/core/src/main/java/contacts/core/entities/Nickname.kt index 10e018e3..4bff5fff 100644 --- a/core/src/main/java/contacts/core/entities/Nickname.kt +++ b/core/src/main/java/contacts/core/entities/Nickname.kt @@ -33,7 +33,7 @@ data class Nickname internal constructor( */ val name: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Nickname @@ -78,7 +78,7 @@ data class MutableNickname internal constructor( */ var name: String? -) : MutableCommonDataEntity { +) : MutableData { constructor() : this(null, null, null, false, false, null) diff --git a/core/src/main/java/contacts/core/entities/Note.kt b/core/src/main/java/contacts/core/entities/Note.kt index fb778000..6a8a90cc 100644 --- a/core/src/main/java/contacts/core/entities/Note.kt +++ b/core/src/main/java/contacts/core/entities/Note.kt @@ -30,7 +30,7 @@ data class Note internal constructor( */ val note: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Note @@ -75,7 +75,7 @@ data class MutableNote internal constructor( */ var note: String? -) : MutableCommonDataEntity { +) : MutableData { constructor() : this(null, null, null, false, false, null) diff --git a/core/src/main/java/contacts/core/entities/Organization.kt b/core/src/main/java/contacts/core/entities/Organization.kt index ac61ea0b..96bd9fe1 100644 --- a/core/src/main/java/contacts/core/entities/Organization.kt +++ b/core/src/main/java/contacts/core/entities/Organization.kt @@ -63,7 +63,7 @@ data class Organization internal constructor( */ val phoneticName: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Organization @@ -147,7 +147,7 @@ data class MutableOrganization internal constructor( */ var phoneticName: String? -) : MutableCommonDataEntity { +) : MutableData { constructor() : this( null, null, null, false, false, null, null, diff --git a/core/src/main/java/contacts/core/entities/Phone.kt b/core/src/main/java/contacts/core/entities/Phone.kt index 67a82ed4..a33787e4 100644 --- a/core/src/main/java/contacts/core/entities/Phone.kt +++ b/core/src/main/java/contacts/core/entities/Phone.kt @@ -61,7 +61,7 @@ data class Phone internal constructor( */ val normalizedNumber: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Phone @@ -85,7 +85,7 @@ data class Phone internal constructor( normalizedNumber = normalizedNumber ) - enum class Type(override val value: Int) : CommonDataEntity.Type { + enum class Type(override val value: Int) : DataEntity.Type { // Order of declaration is the same as seen in the native contacts app MOBILE(CommonDataKinds.Phone.TYPE_MOBILE), // Default @@ -167,7 +167,7 @@ data class MutablePhone internal constructor( */ var normalizedNumber: String? -) : MutableCommonDataEntityWithType { +) : MutableDataWithType { constructor() : this( null, null, null, false, false, diff --git a/core/src/main/java/contacts/core/entities/Photo.kt b/core/src/main/java/contacts/core/entities/Photo.kt index f00af7e3..874ac3ea 100644 --- a/core/src/main/java/contacts/core/entities/Photo.kt +++ b/core/src/main/java/contacts/core/entities/Photo.kt @@ -23,7 +23,7 @@ import kotlinx.parcelize.Parcelize * refactorings in case we need to add state. Also, Parcelize does not work on objects. */ @Parcelize -internal class Photo : CommonDataEntity { +internal class Photo : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Photo diff --git a/core/src/main/java/contacts/core/entities/Relation.kt b/core/src/main/java/contacts/core/entities/Relation.kt index e6991500..0a74addc 100644 --- a/core/src/main/java/contacts/core/entities/Relation.kt +++ b/core/src/main/java/contacts/core/entities/Relation.kt @@ -46,7 +46,7 @@ data class Relation internal constructor( */ val name: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Relation @@ -69,7 +69,7 @@ data class Relation internal constructor( name = name ) - enum class Type(override val value: Int) : CommonDataEntity.Type { + enum class Type(override val value: Int) : DataEntity.Type { // Order of declaration is the same as seen in the native contacts app ASSISTANT(CommonDataKinds.Relation.TYPE_ASSISTANT), // Default @@ -133,7 +133,7 @@ data class MutableRelation internal constructor( */ var name: String? -) : MutableCommonDataEntityWithType { +) : MutableDataWithType { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Relation diff --git a/core/src/main/java/contacts/core/entities/SipAddress.kt b/core/src/main/java/contacts/core/entities/SipAddress.kt index 0731d253..9a61c42d 100644 --- a/core/src/main/java/contacts/core/entities/SipAddress.kt +++ b/core/src/main/java/contacts/core/entities/SipAddress.kt @@ -33,7 +33,7 @@ data class SipAddress internal constructor( */ val sipAddress: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.SipAddress @@ -78,7 +78,7 @@ data class MutableSipAddress internal constructor( */ var sipAddress: String? -) : MutableCommonDataEntity { +) : MutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.SipAddress diff --git a/core/src/main/java/contacts/core/entities/Website.kt b/core/src/main/java/contacts/core/entities/Website.kt index 738fdfce..a83077b3 100644 --- a/core/src/main/java/contacts/core/entities/Website.kt +++ b/core/src/main/java/contacts/core/entities/Website.kt @@ -33,7 +33,7 @@ data class Website internal constructor( */ val url: String? -) : CommonDataEntity { +) : ImmutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Website @@ -78,7 +78,7 @@ data class MutableWebsite internal constructor( */ var url: String? -) : MutableCommonDataEntity { +) : MutableData { @IgnoredOnParcel override val mimeType: MimeType = MimeType.Website diff --git a/core/src/main/java/contacts/core/entities/cursor/AbstractEntityCursor.kt b/core/src/main/java/contacts/core/entities/cursor/AbstractEntityCursor.kt index 72b6e193..8670cc1f 100644 --- a/core/src/main/java/contacts/core/entities/cursor/AbstractEntityCursor.kt +++ b/core/src/main/java/contacts/core/entities/cursor/AbstractEntityCursor.kt @@ -3,7 +3,7 @@ package contacts.core.entities.cursor import android.database.Cursor import android.net.Uri import contacts.core.Field -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import java.util.* import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty @@ -156,7 +156,7 @@ abstract class AbstractEntityCursor( } @JvmOverloads - protected fun getType( + protected fun getType( field: F, default: T? = null, typeFromValue: (value: Int?) -> T? @@ -260,7 +260,7 @@ abstract class AbstractEntityCursor( default: Date? = null ): ReadOnlyProperty, Date?> = DateDelegate(field, default) - protected fun type( + protected fun type( field: F, default: T? = null, typeFromValue: (value: Int?) -> T? @@ -376,7 +376,7 @@ abstract class AbstractEntityCursor( getDate(field, default) } - private inner class TypeDelegate( + private inner class TypeDelegate( private val field: F, private val default: T? = null, private val typeFromValue: (value: Int?) -> T? diff --git a/core/src/main/java/contacts/core/entities/cursor/MimeTypeCursor.kt b/core/src/main/java/contacts/core/entities/cursor/MimeTypeCursor.kt index f65c454b..89b7fa4a 100644 --- a/core/src/main/java/contacts/core/entities/cursor/MimeTypeCursor.kt +++ b/core/src/main/java/contacts/core/entities/cursor/MimeTypeCursor.kt @@ -1,7 +1,7 @@ package contacts.core.entities.cursor import android.database.Cursor -import contacts.core.DataField +import contacts.core.GenericDataField import contacts.core.Fields import contacts.core.entities.MimeType import contacts.core.entities.custom.CustomDataRegistry @@ -13,7 +13,7 @@ import contacts.core.entities.custom.CustomDataRegistry * values. */ internal class MimeTypeCursor(cursor: Cursor, private val customDataRegistry: CustomDataRegistry) : - AbstractEntityCursor(cursor, setOf(Fields.MimeType)) { + AbstractEntityCursor(cursor, setOf(Fields.MimeType)) { val mimeType: MimeType get() = MimeType.fromValue(getString(Fields.MimeType), customDataRegistry) diff --git a/core/src/main/java/contacts/core/entities/custom/AbstractCustomDataOperation.kt b/core/src/main/java/contacts/core/entities/custom/AbstractCustomDataOperation.kt index 93251c9c..d334986a 100644 --- a/core/src/main/java/contacts/core/entities/custom/AbstractCustomDataOperation.kt +++ b/core/src/main/java/contacts/core/entities/custom/AbstractCustomDataOperation.kt @@ -2,15 +2,15 @@ package contacts.core.entities.custom import contacts.core.AbstractCustomDataField import contacts.core.entities.MimeType -import contacts.core.entities.operation.AbstractCommonDataOperation +import contacts.core.entities.operation.AbstractDataOperation /** - * An abstract class that is used as a base of all custom [AbstractCommonDataOperation]s. + * An abstract class that is used as a base of all custom [AbstractDataOperation]s. */ abstract class AbstractCustomDataOperation -( +( isProfile: Boolean, includeFields: Set -) : AbstractCommonDataOperation(isProfile, includeFields) { +) : AbstractDataOperation(isProfile, includeFields) { // Override this to cast type from MimeType to MimeType.Custom abstract override val mimeType: MimeType.Custom @@ -24,7 +24,7 @@ abstract class AbstractCustomDataOperation /* * Invokes the abstract setCustomData function, which uses the type of - * AbstractCustomDataField in the setValue function instead of CommonDataField. This + * AbstractCustomDataField in the setValue function instead of DataField. This * enforces consumers to use their custom data field instead of API fields. */ final override fun setData(data: E, setValue: (field: F, value: Any?) -> Unit) { @@ -34,7 +34,7 @@ abstract class AbstractCustomDataOperation /** * Creates instances of [AbstractCustomDataOperation]. */ - interface Factory { + interface Factory { /** * Creates instances of [AbstractCustomDataOperation] with the given [isProfile]. diff --git a/core/src/main/java/contacts/core/entities/custom/AbstractCustomEntityMapper.kt b/core/src/main/java/contacts/core/entities/custom/AbstractCustomEntityMapper.kt index 74fa9510..2d321a48 100644 --- a/core/src/main/java/contacts/core/entities/custom/AbstractCustomEntityMapper.kt +++ b/core/src/main/java/contacts/core/entities/custom/AbstractCustomEntityMapper.kt @@ -6,17 +6,18 @@ import contacts.core.entities.mapper.EntityMapper /** * An abstract class that is used as a base of all custom [EntityMapper]s. It uses a - * [AbstractCustomDataCursor] [C] (using fields of type [F]) and outputs a [CustomDataEntity] [E]. + * [AbstractCustomDataCursor] [C] (using fields of type [F]) and outputs a + * [MutableCustomData] [E]. */ abstract class AbstractCustomEntityMapper< F : AbstractCustomDataField, C : AbstractCustomDataCursor, - out E : MutableCustomDataEntity>( + out E : MutableCustomData>( private val cursor: C ) : EntityMapper { /** - * Returns the custom common data entity [E] created with values provided by the [cursor]. + * Returns the custom data entity [E] created with values provided by the [cursor]. */ protected abstract fun value(cursor: C): E @@ -34,7 +35,7 @@ abstract class AbstractCustomEntityMapper< interface Factory< F : AbstractCustomDataField, C : AbstractCustomDataCursor, - out E : MutableCustomDataEntity> { + out E : MutableCustomData> { /** * Creates instances of [AbstractCustomEntityMapper] with the given [cursor]. diff --git a/core/src/main/java/contacts/core/entities/custom/CustomData.kt b/core/src/main/java/contacts/core/entities/custom/CustomData.kt new file mode 100644 index 00000000..2d61285b --- /dev/null +++ b/core/src/main/java/contacts/core/entities/custom/CustomData.kt @@ -0,0 +1,32 @@ +package contacts.core.entities.custom + +import contacts.core.entities.* + +/** + * A custom [DataEntity]. + * + * Implementations are required to be parcelable. Kotlin users are recommended to use data class + * combined with [kotlinx.parcelize.Parcelize]. + */ +interface CustomDataEntity : DataEntity { + + // Override this to cast type from MimeType to MimeType.Custom + override val mimeType: MimeType.Custom +} + +/** + * An immutable [CustomDataEntity]. + * + * Implementors should define a toMutableX() function to allow for changes in their custom entities. + */ +interface ImmutableCustomData : CustomDataEntity, ImmutableData + +/** + * A mutable [CustomDataEntity]. + */ +interface MutableCustomData : CustomDataEntity, MutableData + +/** + * A custom [MutableDataWithType]. + */ +interface MutableCustomDataWithType : MutableCustomData, MutableDataWithType \ No newline at end of file diff --git a/core/src/main/java/contacts/core/entities/custom/CustomDataEntity.kt b/core/src/main/java/contacts/core/entities/custom/CustomDataEntity.kt deleted file mode 100644 index 4132c846..00000000 --- a/core/src/main/java/contacts/core/entities/custom/CustomDataEntity.kt +++ /dev/null @@ -1,38 +0,0 @@ -package contacts.core.entities.custom - -import contacts.core.entities.CommonDataEntity -import contacts.core.entities.MimeType -import contacts.core.entities.MutableCommonDataEntity -import contacts.core.entities.MutableCommonDataEntityWithType - -/** - * A custom [CommonDataEntity]. - * - * Implementations are required to be parcelable. Kotlin users are recommended to use data class - * combined with [kotlinx.parcelize.Parcelize]. - * - * Implementors should define a toMutableX() function to allow for changes in their custom entities. - * - * ## Developer notes - * - * Technically, this can be optional. We could have implemented this part of the API to be able to - * handle [CommonDataEntity] directly instead of this [CustomDataEntity]. However, we are able to - * streamline all custom entities this way, which makes our internal code easier to follow / trace. - * It also gives us more control and flexibility. - */ -interface CustomDataEntity : CommonDataEntity { - - // Override this to cast type from MimeType to MimeType.Custom - override val mimeType: MimeType.Custom -} - -/** - * A custom [MutableCommonDataEntity]. - */ -interface MutableCustomDataEntity : CustomDataEntity, MutableCommonDataEntity - -/** - * A custom [MutableCommonDataEntityWithType]. - */ -interface MutableCustomDataEntityWithType : - MutableCustomDataEntity, MutableCommonDataEntityWithType \ No newline at end of file diff --git a/core/src/main/java/contacts/core/entities/custom/CustomDataEntityHolder.kt b/core/src/main/java/contacts/core/entities/custom/CustomDataEntityHolder.kt index 78644519..b9d3c9a5 100644 --- a/core/src/main/java/contacts/core/entities/custom/CustomDataEntityHolder.kt +++ b/core/src/main/java/contacts/core/entities/custom/CustomDataEntityHolder.kt @@ -7,7 +7,7 @@ import kotlinx.parcelize.Parcelize internal data class CustomDataEntityHolder( // This is not exposed to consumers so we do not need a generic type since we have no visibility // of consumer types anyways. - val entities: MutableList, + val entities: MutableList, val countRestriction: CustomDataCountRestriction ) : Parcelable diff --git a/core/src/main/java/contacts/core/entities/custom/CustomDataFieldMapper.kt b/core/src/main/java/contacts/core/entities/custom/CustomDataFieldMapper.kt index 9e24a788..56017363 100644 --- a/core/src/main/java/contacts/core/entities/custom/CustomDataFieldMapper.kt +++ b/core/src/main/java/contacts/core/entities/custom/CustomDataFieldMapper.kt @@ -6,7 +6,7 @@ import contacts.core.AbstractCustomDataField * Provides a piece of data as a nullable String from the custom entity [E] corresponding to the * field [F]. */ -interface CustomDataFieldMapper { +interface CustomDataFieldMapper { /** * Return a piece of data as a nullable String from the [customEntity] corresponding to the diff --git a/core/src/main/java/contacts/core/entities/custom/CustomDataRegistry.kt b/core/src/main/java/contacts/core/entities/custom/CustomDataRegistry.kt index 9a87fec4..0b8613c7 100644 --- a/core/src/main/java/contacts/core/entities/custom/CustomDataRegistry.kt +++ b/core/src/main/java/contacts/core/entities/custom/CustomDataRegistry.kt @@ -19,7 +19,7 @@ class CustomDataRegistry { private val entryMap = mutableMapOf, - MutableCustomDataEntity>>() + MutableCustomData>>() /** * Register custom data [entries]. @@ -31,7 +31,7 @@ class CustomDataRegistry { entryMap[entry.mimeType.value] = entry as Entry< AbstractCustomDataField, AbstractCustomDataCursor, - MutableCustomDataEntity> + MutableCustomData> } } @@ -54,7 +54,7 @@ class CustomDataRegistry { * [customDataEntity] will be added and existing custom entities will remain. */ fun putCustomDataEntityInto( - rawContact: MutableRawContact, customDataEntity: MutableCustomDataEntity + rawContact: MutableRawContact, customDataEntity: MutableCustomData ) { val entry = entryOf(customDataEntity.mimeType) val entityHolder = rawContact.customDataEntities.getOrPut(entry.mimeType.value) { @@ -80,14 +80,14 @@ class CustomDataRegistry { fun removeCustomDataEntityFrom( rawContact: MutableRawContact, byReference: Boolean, - entity: MutableCustomDataEntity + entity: MutableCustomData ) { val entityHolder = rawContact.customDataEntities[entity.mimeType.value] entityHolder?.entities?.removeAll(entity, byReference) } /** - * Removes any [MutableCustomDataEntity]s associated with the [MimeType.Custom] contained in the + * Removes any [MutableCustomData]s associated with the [MimeType.Custom] contained in the * given [rawContact], if any. */ fun removeAllCustomDataEntityFrom(rawContact: MutableRawContact, mimeType: MimeType.Custom) { @@ -96,7 +96,7 @@ class CustomDataRegistry { } /** - * Returns the list of [MutableCustomDataEntity]s of type [T] associated with the + * Returns the list of [MutableCustomData]s of type [T] associated with the * [MimeType.Custom] contained in the given [rawContact], if any. * * If the [Entry.countRestriction] is [CustomDataCountRestriction.AT_MOST_ONE], then expect @@ -105,18 +105,18 @@ class CustomDataRegistry { * If the [Entry.countRestriction] is [CustomDataCountRestriction.NO_LIMIT], then expect * 0, 1, or more custom entities in the list. */ - fun customDataEntitiesFor( + fun customDataEntitiesFor( rawContact: RawContact, mimeType: MimeType.Custom ): List = customDataEntitiesFor(rawContact.customDataEntities, mimeType) /** * See [customDataEntitiesFor]. */ - fun customDataEntitiesFor( + fun customDataEntitiesFor( rawContact: MutableRawContact, mimeType: MimeType.Custom ): List = customDataEntitiesFor(rawContact.customDataEntities, mimeType) - private fun customDataEntitiesFor( + private fun customDataEntitiesFor( customDataEntities: Map, mimeType: MimeType.Custom ): List { val entityHolder = customDataEntities[mimeType.value] @@ -129,7 +129,7 @@ class CustomDataRegistry { internal fun entryOf(mimeTypeValue: String): Entry, - MutableCustomDataEntity> = entryMap[mimeTypeValue] + MutableCustomData> = entryMap[mimeTypeValue] ?: throw CustomDataException("Missing custom data entry for $mimeTypeValue") internal fun mimeTypeOf( @@ -153,11 +153,11 @@ class CustomDataRegistry { .toSet() /** - * A custom common data entry provides all the required implementations to support queries, + * A custom data entry provides all the required implementations to support queries, * inserts, updates, and deletes. */ interface Entry, - E : MutableCustomDataEntity> { + E : MutableCustomData> { val mimeType: MimeType.Custom val fieldSet: AbstractCustomDataFieldSet val fieldMapper: CustomDataFieldMapper diff --git a/core/src/main/java/contacts/core/entities/mapper/EntityMapperFactory.kt b/core/src/main/java/contacts/core/entities/mapper/EntityMapperFactory.kt index fb38d5fd..0e1b8bf5 100644 --- a/core/src/main/java/contacts/core/entities/mapper/EntityMapperFactory.kt +++ b/core/src/main/java/contacts/core/entities/mapper/EntityMapperFactory.kt @@ -59,7 +59,7 @@ internal fun CursorHolder.websiteMapper(): EntityMapper CursorHolder.entityMapperFor( +internal fun CursorHolder.entityMapperFor( mimeType: MimeType, customDataRegistry: CustomDataRegistry ): EntityMapper = when (mimeType) { @@ -93,7 +93,6 @@ internal fun CursorHolder.entityMapper // endregion - internal fun RawContactIdCursor.tempRawContactMapper(): EntityMapper = TempRawContactMapper(this) diff --git a/core/src/main/java/contacts/core/entities/operation/AbstractCommonDataOperation.kt b/core/src/main/java/contacts/core/entities/operation/AbstractDataOperation.kt similarity index 99% rename from core/src/main/java/contacts/core/entities/operation/AbstractCommonDataOperation.kt rename to core/src/main/java/contacts/core/entities/operation/AbstractDataOperation.kt index c846e162..59ab1038 100644 --- a/core/src/main/java/contacts/core/entities/operation/AbstractCommonDataOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/AbstractDataOperation.kt @@ -5,7 +5,7 @@ import android.content.ContentResolver import android.database.Cursor import android.net.Uri import contacts.core.* -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.MimeType import contacts.core.entities.cursor.CursorHolder import contacts.core.entities.cursor.dataCursor @@ -23,7 +23,7 @@ import contacts.core.util.query * Insert and update functions will do nothing for data that is not specified in [includeFields], * except for data that are required. */ -abstract class AbstractCommonDataOperation( +abstract class AbstractDataOperation( isProfile: Boolean, private val includeFields: Set ) { diff --git a/core/src/main/java/contacts/core/entities/operation/AddressOperation.kt b/core/src/main/java/contacts/core/entities/operation/AddressOperation.kt index 18736f0b..adf1e567 100644 --- a/core/src/main/java/contacts/core/entities/operation/AddressOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/AddressOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableAddress internal class AddressOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Address diff --git a/core/src/main/java/contacts/core/entities/operation/DataEntityOperationMapper.kt b/core/src/main/java/contacts/core/entities/operation/DataEntityOperationMapper.kt index 1be51586..b8057caa 100644 --- a/core/src/main/java/contacts/core/entities/operation/DataEntityOperationMapper.kt +++ b/core/src/main/java/contacts/core/entities/operation/DataEntityOperationMapper.kt @@ -5,7 +5,7 @@ import contacts.core.AbstractDataField import contacts.core.ContactsException import contacts.core.Fields import contacts.core.entities.MimeType -import contacts.core.entities.MutableCommonDataEntity +import contacts.core.entities.MutableData import contacts.core.entities.custom.CustomDataRegistry import contacts.core.intersect @@ -14,16 +14,16 @@ import contacts.core.intersect * * Only the fields specified in [includeFields] will be updated. */ -internal fun MutableCommonDataEntity.updateOperation( +internal fun MutableData.updateOperation( includeFields: Set, customDataRegistry: CustomDataRegistry ): ContentProviderOperation? = dataOperation(includeFields, customDataRegistry) .updateDataRowOrDeleteIfBlank(this) @Suppress("UNCHECKED_CAST") -private fun MutableCommonDataEntity.dataOperation( +private fun MutableData.dataOperation( includeFields: Set, customDataRegistry: CustomDataRegistry -): AbstractCommonDataOperation<*, MutableCommonDataEntity> = when (mimeType) { +): AbstractDataOperation<*, MutableData> = when (mimeType) { // We could instead do when (this) is MutableAddress -> AddressOperation() // However, using mimeType instead of the class allows for exhaustive compilation checks. // Not requiring an 'else' branch. @@ -60,4 +60,4 @@ private fun MutableCommonDataEntity.dataOperation( // functions. Manage photos via the (Raw)ContactPhoto extension functions. MimeType.GroupMembership, MimeType.Photo, MimeType.Unknown -> throw ContactsException("No data operation found for ${mimeType.value}") -} as AbstractCommonDataOperation<*, MutableCommonDataEntity> \ No newline at end of file +} as AbstractDataOperation<*, MutableData> \ No newline at end of file diff --git a/core/src/main/java/contacts/core/entities/operation/EmailOperation.kt b/core/src/main/java/contacts/core/entities/operation/EmailOperation.kt index 4004ceb0..43635e89 100644 --- a/core/src/main/java/contacts/core/entities/operation/EmailOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/EmailOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableEmail internal class EmailOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Email diff --git a/core/src/main/java/contacts/core/entities/operation/EventOperation.kt b/core/src/main/java/contacts/core/entities/operation/EventOperation.kt index 54a81fb6..68ad9f01 100644 --- a/core/src/main/java/contacts/core/entities/operation/EventOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/EventOperation.kt @@ -7,7 +7,7 @@ import contacts.core.entities.MutableEvent import contacts.core.entities.toDbString internal class EventOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Event diff --git a/core/src/main/java/contacts/core/entities/operation/GroupMembershipOperation.kt b/core/src/main/java/contacts/core/entities/operation/GroupMembershipOperation.kt index 08786a18..0dc15ce9 100644 --- a/core/src/main/java/contacts/core/entities/operation/GroupMembershipOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/GroupMembershipOperation.kt @@ -18,7 +18,7 @@ internal class GroupMembershipOperation( isProfile: Boolean, includeFields: Set, private val groups: Groups -) : AbstractCommonDataOperation(isProfile, includeFields) { +) : AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.GroupMembership diff --git a/core/src/main/java/contacts/core/entities/operation/ImOperation.kt b/core/src/main/java/contacts/core/entities/operation/ImOperation.kt index 1cc7621e..65ae8560 100644 --- a/core/src/main/java/contacts/core/entities/operation/ImOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/ImOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableIm internal class ImOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Im diff --git a/core/src/main/java/contacts/core/entities/operation/NameOperation.kt b/core/src/main/java/contacts/core/entities/operation/NameOperation.kt index ddbf7931..4b0dd9ce 100644 --- a/core/src/main/java/contacts/core/entities/operation/NameOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/NameOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableName internal class NameOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Name diff --git a/core/src/main/java/contacts/core/entities/operation/NicknameOperation.kt b/core/src/main/java/contacts/core/entities/operation/NicknameOperation.kt index a1a9832d..cdf4aceb 100644 --- a/core/src/main/java/contacts/core/entities/operation/NicknameOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/NicknameOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableNickname internal class NicknameOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Nickname diff --git a/core/src/main/java/contacts/core/entities/operation/NoteOperation.kt b/core/src/main/java/contacts/core/entities/operation/NoteOperation.kt index 873e85d4..cadcb6ae 100644 --- a/core/src/main/java/contacts/core/entities/operation/NoteOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/NoteOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableNote internal class NoteOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Note diff --git a/core/src/main/java/contacts/core/entities/operation/OrganizationOperation.kt b/core/src/main/java/contacts/core/entities/operation/OrganizationOperation.kt index a213b958..b5b4d40e 100644 --- a/core/src/main/java/contacts/core/entities/operation/OrganizationOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/OrganizationOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableOrganization internal class OrganizationOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Organization diff --git a/core/src/main/java/contacts/core/entities/operation/PhoneOperation.kt b/core/src/main/java/contacts/core/entities/operation/PhoneOperation.kt index f91944d1..bdebc920 100644 --- a/core/src/main/java/contacts/core/entities/operation/PhoneOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/PhoneOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutablePhone internal class PhoneOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Phone diff --git a/core/src/main/java/contacts/core/entities/operation/RelationOperation.kt b/core/src/main/java/contacts/core/entities/operation/RelationOperation.kt index 8df76377..b4d9763f 100644 --- a/core/src/main/java/contacts/core/entities/operation/RelationOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/RelationOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableRelation internal class RelationOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Relation diff --git a/core/src/main/java/contacts/core/entities/operation/SipAddressOperation.kt b/core/src/main/java/contacts/core/entities/operation/SipAddressOperation.kt index 277a404a..7a798e2f 100644 --- a/core/src/main/java/contacts/core/entities/operation/SipAddressOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/SipAddressOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableSipAddress internal class SipAddressOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.SipAddress diff --git a/core/src/main/java/contacts/core/entities/operation/WebsiteOperation.kt b/core/src/main/java/contacts/core/entities/operation/WebsiteOperation.kt index dac49244..95ce5343 100644 --- a/core/src/main/java/contacts/core/entities/operation/WebsiteOperation.kt +++ b/core/src/main/java/contacts/core/entities/operation/WebsiteOperation.kt @@ -6,7 +6,7 @@ import contacts.core.entities.MimeType import contacts.core.entities.MutableWebsite internal class WebsiteOperation(isProfile: Boolean, includeFields: Set) : - AbstractCommonDataOperation(isProfile, includeFields) { + AbstractDataOperation(isProfile, includeFields) { override val mimeType = MimeType.Website diff --git a/core/src/main/java/contacts/core/profile/ProfileInsert.kt b/core/src/main/java/contacts/core/profile/ProfileInsert.kt index 3c6c1fe8..ab3d86c1 100644 --- a/core/src/main/java/contacts/core/profile/ProfileInsert.kt +++ b/core/src/main/java/contacts/core/profile/ProfileInsert.kt @@ -149,7 +149,7 @@ interface ProfileInsert { * * ## Note * - * The use case for this function is probably not common. You can simply not set a particular + * The use case for this function is probably rare. You can simply not set a particular * data instead of using this function. For example, if you want to create a new RawContact * with only name and email data, just set only name and email... * diff --git a/core/src/main/java/contacts/core/util/ContactData.kt b/core/src/main/java/contacts/core/util/ContactData.kt index bdddb8c7..270dd9c4 100644 --- a/core/src/main/java/contacts/core/util/ContactData.kt +++ b/core/src/main/java/contacts/core/util/ContactData.kt @@ -1,7 +1,7 @@ package contacts.core.util import contacts.core.entities.* -import contacts.core.entities.custom.MutableCustomDataEntity +import contacts.core.entities.custom.MutableCustomData // Dev note: The functions that return a List instead of a Sequence are useful for Java consumers // as they will not have to convert Sequences to List. Also, all are functions instead of vals @@ -248,7 +248,7 @@ fun Contact.websiteList(): List = websites().toList() */ internal fun Contact.customDataSequenceOf( mimeType: MimeType.Custom -): Sequence = rawContacts +): Sequence = rawContacts .asSequence() .mapNotNull { it.customDataEntities[mimeType.value] } .flatMap { diff --git a/core/src/main/java/contacts/core/util/DataContact.kt b/core/src/main/java/contacts/core/util/DataContact.kt index 6bcd5a7d..80a4c7c4 100644 --- a/core/src/main/java/contacts/core/util/DataContact.kt +++ b/core/src/main/java/contacts/core/util/DataContact.kt @@ -1,13 +1,13 @@ package contacts.core.util import contacts.core.Contacts -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.Contact /** - * Returns the [Contact] with the [CommonDataEntity.contactId]. + * Returns the [Contact] with the [DataEntity.contactId]. * - * This may return null if the [Contact] no longer exists or if [CommonDataEntity.contactId] is null + * This may return null if the [Contact] no longer exists or if [DataEntity.contactId] is null * (which is the case for manually constructed entities). * * Supports profile/non-profile Contacts with native/custom data. @@ -23,7 +23,7 @@ import contacts.core.entities.Contact */ // [ANDROID X] @WorkerThread (not using annotation to avoid dependency on androidx.annotation) @JvmOverloads -fun CommonDataEntity.contact(contacts: Contacts, cancel: () -> Boolean = { false }): Contact? = +fun DataEntity.contact(contacts: Contacts, cancel: () -> Boolean = { false }): Contact? = contactId?.let { contactId -> contacts.findFirstContactWithId(contactId, cancel) } \ No newline at end of file diff --git a/core/src/main/java/contacts/core/util/DataRawContact.kt b/core/src/main/java/contacts/core/util/DataRawContact.kt index 4135ef9e..4017b4e4 100644 --- a/core/src/main/java/contacts/core/util/DataRawContact.kt +++ b/core/src/main/java/contacts/core/util/DataRawContact.kt @@ -1,13 +1,13 @@ package contacts.core.util import contacts.core.Contacts -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.RawContact /** - * Returns the [RawContact] with the [CommonDataEntity.rawContactId]. + * Returns the [RawContact] with the [DataEntity.rawContactId]. * - * This may return null if the [RawContact] no longer exists or if [CommonDataEntity.rawContactId] is null + * This may return null if the [RawContact] no longer exists or if [DataEntity.rawContactId] is null * (which is the case for manually constructed entities). * * Supports profile/non-profile RawContacts with native/custom data. @@ -23,7 +23,7 @@ import contacts.core.entities.RawContact */ // [ANDROID X] @WorkerThread (not using annotation to avoid dependency on androidx.annotation) @JvmOverloads -fun CommonDataEntity.rawContact( +fun DataEntity.rawContact( contacts: Contacts, cancel: () -> Boolean = { false } ): RawContact? = rawContactId?.let { rawContactId -> diff --git a/core/src/main/java/contacts/core/util/DataRefresh.kt b/core/src/main/java/contacts/core/util/DataRefresh.kt index dcc821c3..93672be2 100644 --- a/core/src/main/java/contacts/core/util/DataRefresh.kt +++ b/core/src/main/java/contacts/core/util/DataRefresh.kt @@ -2,16 +2,16 @@ package contacts.core.util import contacts.core.* import contacts.core.data.resolveDataEntity -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.ImmutableData import contacts.core.entities.fields /** - * Returns the [CommonDataEntity] with all of the latest data. + * Returns the [ImmutableData] [T] with all of the latest data. * * This is useful for getting the latest data after performing an update. This may return null if - * the [CommonDataEntity] no longer exists or if permission is not granted. + * the data entity no longer exists or if permission is not granted. * - * Returns itself if the [CommonDataEntity.id] is null, indicating that this DataEntity instance has + * Returns itself if the [ImmutableData.id] is null, indicating that this DataEntity instance has * not yet been inserted to the DB. * * Supports profile/non-profile native/custom data. @@ -27,7 +27,7 @@ import contacts.core.entities.fields */ // [ANDROID X] @WorkerThread (not using annotation to avoid dependency on androidx.annotation) @JvmOverloads -fun T.refresh(contacts: Contacts, cancel: () -> Boolean = { false }): T? = +fun T.refresh(contacts: Contacts, cancel: () -> Boolean = { false }): T? = if (id == null) { this } else if (!contacts.permissions.canQuery()) { @@ -38,4 +38,6 @@ fun T.refresh(contacts: Contacts, cancel: () -> Boolean = Include(fields(contacts.customDataRegistry) + Fields.Required.all), null, CompoundOrderBy(setOf(Fields.DataId.asc())), 1, 0, cancel ).firstOrNull() - } \ No newline at end of file + } + +// TODO MutableData extension + async \ No newline at end of file diff --git a/core/src/main/java/contacts/core/util/DefaultContactData.kt b/core/src/main/java/contacts/core/util/DefaultContactData.kt index e577f270..85c19757 100644 --- a/core/src/main/java/contacts/core/util/DefaultContactData.kt +++ b/core/src/main/java/contacts/core/util/DefaultContactData.kt @@ -3,7 +3,7 @@ package contacts.core.util import android.content.ContentProviderOperation import android.content.ContentProviderOperation.newUpdate import contacts.core.* -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.operation.withSelection import contacts.core.entities.operation.withValue import contacts.core.entities.table.ProfileUris @@ -12,12 +12,12 @@ import contacts.core.entities.table.Table /** * Returns the default data entity in the collection or null if not found. */ -fun Collection.default(): CommonDataEntity? = firstOrNull { it.isDefault } +fun Collection.default(): T? = firstOrNull { it.isDefault } /** * Returns the default data entity in the sequence or null if not found. */ -fun Sequence.default(): CommonDataEntity? = firstOrNull { it.isDefault } +fun Sequence.default(): T? = firstOrNull { it.isDefault } /** * Sets this data as the default for the set of data of the same type (e.g. email) for the aggregate @@ -34,7 +34,7 @@ fun Sequence.default(): CommonDataEntity? = firstOrNull { it.i * This should be called in a background thread to avoid blocking the UI thread. */ // [ANDROID X] @WorkerThread (not using annotation to avoid dependency on androidx.annotation) -fun CommonDataEntity.setAsDefault(contacts: Contacts): Boolean { +fun DataEntity.setAsDefault(contacts: Contacts): Boolean { val dataId = id val rawContactId = rawContactId val contactId = contactId @@ -83,7 +83,7 @@ fun CommonDataEntity.setAsDefault(contacts: Contacts): Boolean { * This should be called in a background thread to avoid blocking the UI thread. */ // [ANDROID X] @WorkerThread (not using annotation to avoid dependency on androidx.annotation) -fun CommonDataEntity.clearDefault(contactsApi: Contacts): Boolean { +fun DataEntity.clearDefault(contactsApi: Contacts): Boolean { val rawContactId = rawContactId val contactId = contactId @@ -101,14 +101,14 @@ fun CommonDataEntity.clearDefault(contactsApi: Contacts): Boolean { } /** - * Provides the operation to set all primary data rows with the same [CommonDataEntity.mimeType] + * Provides the operation to set all primary data rows with the same [DataEntity.mimeType] * belonging to the same RawContact to false (0). * * Supports profile/non-profile native/custom data. * * See DEV_NOTES "Data Primary and Super Primary Rows" section for more info. */ -private fun CommonDataEntity.clearPrimary(rawContactId: Long): ContentProviderOperation = +private fun DataEntity.clearPrimary(rawContactId: Long): ContentProviderOperation = newUpdate(if (isProfile) ProfileUris.DATA.uri else Table.Data.uri) .withSelection( (Fields.RawContact.Id equalTo rawContactId) @@ -118,14 +118,14 @@ private fun CommonDataEntity.clearPrimary(rawContactId: Long): ContentProviderOp .build() /** - * Provides the operation to set all super primary data rows with the same [CommonDataEntity.mimeType] + * Provides the operation to set all super primary data rows with the same [DataEntity.mimeType] * belonging to the same Contact to false (0). * * Supports profile/non-profile native/custom data. * * See DEV_NOTES "Data Primary and Super Primary Rows" section for more info. */ -private fun CommonDataEntity.clearSuperPrimary(contactId: Long): ContentProviderOperation = +private fun DataEntity.clearSuperPrimary(contactId: Long): ContentProviderOperation = newUpdate(if (isProfile) ProfileUris.DATA.uri else Table.Data.uri) .withSelection( (Fields.Contact.Id equalTo contactId) @@ -141,7 +141,7 @@ private fun CommonDataEntity.clearSuperPrimary(contactId: Long): ContentProvider * * See DEV_NOTES "Data Primary and Super Primary Rows" section for more info. */ -private fun CommonDataEntity.setPrimaryAndSuperPrimary(dataId: Long): ContentProviderOperation = +private fun DataEntity.setPrimaryAndSuperPrimary(dataId: Long): ContentProviderOperation = newUpdate(if (isProfile) ProfileUris.DATA.uri else Table.Data.uri) .withSelection(Fields.DataId equalTo dataId) .withValue(Fields.IsPrimary, 1) diff --git a/customdata-gender/src/main/java/contacts/entities/custom/gender/Gender.kt b/customdata-gender/src/main/java/contacts/entities/custom/gender/Gender.kt index 20a82e7f..2505fa19 100644 --- a/customdata-gender/src/main/java/contacts/entities/custom/gender/Gender.kt +++ b/customdata-gender/src/main/java/contacts/entities/custom/gender/Gender.kt @@ -2,10 +2,10 @@ package contacts.entities.custom.gender import android.content.res.Resources import android.provider.ContactsContract -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity import contacts.core.entities.MimeType -import contacts.core.entities.custom.CustomDataEntity -import contacts.core.entities.custom.MutableCustomDataEntityWithType +import contacts.core.entities.custom.ImmutableCustomData +import contacts.core.entities.custom.MutableCustomDataWithType import contacts.core.entities.propertiesAreAllNullOrBlank import contacts.entities.custom.gender.Gender.Type import contacts.entities.custom.gender.Gender.Type.* @@ -40,7 +40,7 @@ data class Gender internal constructor( */ val label: String? -) : CustomDataEntity { +) : ImmutableCustomData { @IgnoredOnParcel override val mimeType: MimeType.Custom = GenderMimeType @@ -66,7 +66,7 @@ data class Gender internal constructor( * * For other types of genders, use [CUSTOM] and [Gender.label] */ - enum class Type(override val value: Int) : CommonDataEntity.Type { + enum class Type(override val value: Int) : DataEntity.Type { MALE(1), FEMALE(2), @@ -119,7 +119,7 @@ data class MutableGender internal constructor( */ override var label: String? -) : MutableCustomDataEntityWithType { +) : MutableCustomDataWithType { constructor() : this(null, null, null, false, false, null, null) diff --git a/customdata-gender/src/main/java/contacts/entities/custom/gender/GenderDataQuery.kt b/customdata-gender/src/main/java/contacts/entities/custom/gender/GenderDataQuery.kt index bd7f5961..e534347f 100644 --- a/customdata-gender/src/main/java/contacts/entities/custom/gender/GenderDataQuery.kt +++ b/customdata-gender/src/main/java/contacts/entities/custom/gender/GenderDataQuery.kt @@ -1,9 +1,9 @@ package contacts.entities.custom.gender -import contacts.core.data.CommonDataQuery import contacts.core.data.DataQuery +import contacts.core.data.DataQueryFactory /** * Queries for [Gender]s. */ -fun DataQuery.genders(): CommonDataQuery = customData(GenderMimeType) \ No newline at end of file +fun DataQueryFactory.genders(): DataQuery = customData(GenderMimeType) \ No newline at end of file diff --git a/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleName.kt b/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleName.kt index 8c7d1147..1413e02b 100644 --- a/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleName.kt +++ b/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleName.kt @@ -1,8 +1,8 @@ package contacts.entities.custom.handlename import contacts.core.entities.MimeType -import contacts.core.entities.custom.CustomDataEntity -import contacts.core.entities.custom.MutableCustomDataEntity +import contacts.core.entities.custom.ImmutableCustomData +import contacts.core.entities.custom.MutableCustomData import contacts.core.entities.propertiesAreAllNullOrBlank import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize @@ -35,7 +35,7 @@ data class HandleName internal constructor( */ val handle: String? -) : CustomDataEntity { +) : ImmutableCustomData { @IgnoredOnParcel override val mimeType: MimeType.Custom = HandleNameMimeType @@ -76,7 +76,7 @@ data class MutableHandleName internal constructor( */ var handle: String? -) : MutableCustomDataEntity { +) : MutableCustomData { constructor() : this(null, null, null, false, false, null) diff --git a/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleNameDataQuery.kt b/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleNameDataQuery.kt index 7584ca80..1b3120f5 100644 --- a/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleNameDataQuery.kt +++ b/customdata-handlename/src/main/java/contacts/entities/custom/handlename/HandleNameDataQuery.kt @@ -1,10 +1,10 @@ package contacts.entities.custom.handlename -import contacts.core.data.CommonDataQuery import contacts.core.data.DataQuery +import contacts.core.data.DataQueryFactory /** * Queries for [HandleName]s. */ -fun DataQuery.handleNames(): CommonDataQuery = +fun DataQueryFactory.handleNames(): DataQuery = customData(HandleNameMimeType) \ No newline at end of file diff --git a/howto/howto-learn-more-about-api-entities.md b/howto/howto-learn-more-about-api-entities.md index 5618d44f..f8c77b9f 100644 --- a/howto/howto-learn-more-about-api-entities.md +++ b/howto/howto-learn-more-about-api-entities.md @@ -53,7 +53,7 @@ This library provides entities that model everything in the Contacts Provider da - `RawContact` - Contains contact data that belong to an account. - There may be more than one RawContact per Contact. -- `CommonDataEntity` +- `DataEntity` - A specific kind of data of a RawContact. These entities model the common data kinds that are provided by the Contacts Provider. - `Address` @@ -84,7 +84,7 @@ mutating API functions). Custom data types may also be integrated into the contacts database (though not synced across devices). Read more in [How do I integrate custom data?](/howto/howto-integrate-custom-data.md) -## Common data kinds count restrictions +## Data kinds count restrictions A `RawContact` may have at most one OR no limits of certain kinds of data. @@ -115,7 +115,7 @@ disables consumers from violating them. The core library does not explicitly expose count restrictions to consumers. However, it is exposed when integrating custom data via the `CustomDataCountRestriction`. -## Common data kinds Account restrictions +## Data kinds Account restrictions Entries of some data kinds should not be allowed to exist for local RawContacts (those that are not associated with an Account). These data kinds are; @@ -133,7 +133,7 @@ The Contacts Provider may or may not enforce these Account restrictions. However app imposes these restrictions. Therefore, this library also imposes these restrictions and disables consumers from violating them. -## Automatic common data kinds creation +## Automatic data kinds creation An entry of each of the following data kinds are automatically created for all contacts, if not provided; diff --git a/howto/howto-query-accounts.md b/howto/howto-query-accounts.md index a04efd07..efb7c3e4 100644 --- a/howto/howto-query-accounts.md +++ b/howto/howto-query-accounts.md @@ -54,7 +54,7 @@ The `accountsFor` functions optionally takes in a function that, if it returns t query processing as soon as possible. The function is called numerous times during query processing to check if processing should stop or continue. This gives you the option to cancel the query. -This is useful when used in multi-threaded environments. One scenario where this would be commonly +This is useful when used in multi-threaded environments. One scenario where this would be frequently used is when performing queries as the user types a search text. You are able to cancel the current query when the user enters new text. diff --git a/howto/howto-query-contacts-advanced.md b/howto/howto-query-contacts-advanced.md index 287c0eed..ace97e37 100644 --- a/howto/howto-query-contacts-advanced.md +++ b/howto/howto-query-contacts-advanced.md @@ -240,7 +240,7 @@ The `find` function optionally takes in a function that, if it returns true, wil processing as soon as possible. The function is called numerous times during query processing to check if processing should stop or continue. This gives you the option to cancel the query. -This is useful when used in multi-threaded environments. One scenario where this would be commonly +This is useful when used in multi-threaded environments. One scenario where this would be frequently used is when performing queries as the user types a search text. You are able to cancel the current query when the user enters new text. diff --git a/howto/howto-query-contacts.md b/howto/howto-query-contacts.md index 411eb694..41f85d1c 100644 --- a/howto/howto-query-contacts.md +++ b/howto/howto-query-contacts.md @@ -195,7 +195,7 @@ The `find` function optionally takes in a function that, if it returns true, wil processing as soon as possible. The function is called numerous times during query processing to check if processing should stop or continue. This gives you the option to cancel the query. -This is useful when used in multi-threaded environments. One scenario where this would be commonly +This is useful when used in multi-threaded environments. One scenario where this would be frequently used is when performing queries as the user types a search text. You are able to cancel the current query when the user enters new text. diff --git a/howto/howto-query-data-sets.md b/howto/howto-query-data-sets.md index 471d082e..08cff194 100644 --- a/howto/howto-query-data-sets.md +++ b/howto/howto-query-data-sets.md @@ -1,9 +1,9 @@ # How do I get a list of specific data kinds? -This library provides the `DataQuery` API that allows you to get a list of specific data kinds +This library provides the `DataQueryFactory` API that allows you to get a list of specific data kinds directly without having to get them from Contacts/RawContacts. -An instance of the `DataQuery` API is obtained by, +An instance of the `DataQueryFactory` API is obtained by, ```kotlin val query = Contacts(context).data().query() @@ -13,28 +13,28 @@ val query = Contacts(context).data().query() > [How do I get a list of contacts in the simplest way?](/howto/howto-query-contacts.md) > and [How do I get a list of contacts in a more advanced way?](/howto/howto-query-contacts-advanced.md) -## Common data queries +## Data queries -The `DataQuery` API provides instances of `CommonDataQuery` for every data kind in the library. +The `DataQueryFactory` API provides instances of `DataQuery` for every data kind in the library. -The full list of queries are defined in the `CommonDataQuery` interface. Here it is for reference, +The full list of queries are defined in the `DataQueryFactory` interface. Here it is for reference, ```kotlin -val dataQuery = Contacts(context).data().query() - -val addressesQuery = dataQuery.addresses() -val emailsQuery = dataQuery.emails() -val eventsQuery = dataQuery.events() -val groupMembershipsQuery = dataQuery.groupMemberships() -val imsQuery = dataQuery.ims() -val namesQuery = dataQuery.names() -val nicknamesQuery = dataQuery.nicknames() -val notesQuery = dataQuery.notes() -val organizationsQuery = dataQuery.organizations() -val phonesQuery = dataQuery.phones() -val relationsQuery = dataQuery.relations() -val sipAddressesQuery = dataQuery.sipAddresses() -val websitesQuery = dataQuery.websites() +val dataQueryFactory = Contacts(context).data().query() + +val addressesQuery = dataQueryFactory.addresses() +val emailsQuery = dataQueryFactory.emails() +val eventsQuery = dataQueryFactory.events() +val groupMembershipsQuery = dataQueryFactory.groupMemberships() +val imsQuery = dataQueryFactory.ims() +val namesQuery = dataQueryFactory.names() +val nicknamesQuery = dataQueryFactory.nicknames() +val notesQuery = dataQueryFactory.notes() +val organizationsQuery = dataQueryFactory.organizations() +val phonesQuery = dataQueryFactory.phones() +val relationsQuery = dataQueryFactory.relations() +val sipAddressesQuery = dataQueryFactory.sipAddresses() +val websitesQuery = dataQueryFactory.websites() // Photos are intentionally left out as it is internal to the library. ``` @@ -166,7 +166,7 @@ The `find` function optionally takes in a function that, if it returns true, wil processing as soon as possible. The function is called numerous times during query processing to check if processing should stop or continue. This gives you the option to cancel the query. -This is useful when used in multi-threaded environments. One scenario where this would be commonly +This is useful when used in multi-threaded environments. One scenario where this would be frequently used is when performing queries as the user types a search text. You are able to cancel the current query when the user enters new text. @@ -205,18 +205,19 @@ You may, of course, use other permission handling libraries or just do it yourse ## Profile data -The `DataQuery` API also supports querying the Profile (device owner) contact data. To get an -instance of this API for Profile data queries, +The `DataQueryFactory` API (and its `DataQuery` instances) also supports querying the Profile +(device owner) contact data. To get an instance of this API for Profile data queries, ```kotlin -val profileDataQuery = Contacts(context).profile().data().query() +val profileDataQueryFactory = Contacts(context).profile().data().query() ``` All queries will be limited to the Profile, whether it exists or not. ## Custom data support -The `DataQuery` API supports custom data. For more info, read [How do I use query APIs to get custom data?](/howto/howto-query-custom-data.md) +The `DataQueryFactory` API (and its `DataQuery` instances) supports custom data. For more info, +read [How do I use query APIs to get custom data?](/howto/howto-query-custom-data.md) ## Using the `where` function to specify matching criteria diff --git a/howto/howto-query-groups.md b/howto/howto-query-groups.md index 69967b14..17256f8f 100644 --- a/howto/howto-query-groups.md +++ b/howto/howto-query-groups.md @@ -104,7 +104,7 @@ The `find` function optionally takes in a function that, if it returns true, wil processing as soon as possible. The function is called numerous times during query processing to check if processing should stop or continue. This gives you the option to cancel the query. -This is useful when used in multi-threaded environments. One scenario where this would be commonly +This is useful when used in multi-threaded environments. One scenario where this would be frequently used is when performing queries as the user types a search text. You are able to cancel the current query when the user enters new text. diff --git a/howto/howto-query-raw-contacts.md b/howto/howto-query-raw-contacts.md index 77dc2e18..d88462f4 100644 --- a/howto/howto-query-raw-contacts.md +++ b/howto/howto-query-raw-contacts.md @@ -112,7 +112,7 @@ The `find` function optionally takes in a function that, if it returns true, wil processing as soon as possible. The function is called numerous times during query processing to check if processing should stop or continue. This gives you the option to cancel the query. -This is useful when used in multi-threaded environments. One scenario where this would be commonly +This is useful when used in multi-threaded environments. One scenario where this would be frequently used is when performing queries as the user types a search text. You are able to cancel the current query when the user enters new text. diff --git a/howto/howto-update-data-sets.md b/howto/howto-update-data-sets.md index 5fdc07e1..65c5dc7e 100644 --- a/howto/howto-update-data-sets.md +++ b/howto/howto-update-data-sets.md @@ -13,7 +13,7 @@ val update = Contacts(context).data().update() ## A basic update -To update a set of `MutableCommonDataEntity`, +To update a set of `MutableData`, ```kotlin val updateResult = Contacts(context) @@ -81,7 +81,8 @@ To check if a particular update succeeded, val emailUpdateSuccessful = updateResult.isSuccessful(mutableEmail) ``` -Once you have performed the updates, you can retrieve the updated data references via the `DataQuery` API, +Once you have performed the updates, you can retrieve the updated data references via the +`DataQuery` APIs, ```kotlin val updatedEmail = contactsApi diff --git a/permissions/src/main/java/contacts/permissions/data/DataPermissionsRequest.kt b/permissions/src/main/java/contacts/permissions/data/DataPermissionsRequest.kt index e8c37d84..2b0db208 100644 --- a/permissions/src/main/java/contacts/permissions/data/DataPermissionsRequest.kt +++ b/permissions/src/main/java/contacts/permissions/data/DataPermissionsRequest.kt @@ -3,18 +3,18 @@ package contacts.permissions.data import contacts.core.ContactsPermissions import contacts.core.data.Data import contacts.core.data.DataDelete -import contacts.core.data.DataQuery +import contacts.core.data.DataQueryFactory import contacts.core.data.DataUpdate import contacts.permissions.requestReadPermission import contacts.permissions.requestWritePermission /** * If [ContactsPermissions.READ_PERMISSION] is not yet granted, suspends the current coroutine, - * requests for the permission, and then returns a new [DataQuery] instance. + * requests for the permission, and then returns a new [DataQueryFactory] instance. * - * If permission is already granted, then immediately returns a new [DataQuery] instance. + * If permission is already granted, then immediately returns a new [DataQueryFactory] instance. */ -suspend fun Data.queryWithPermission(): DataQuery { +suspend fun Data.queryWithPermission(): DataQueryFactory { if (!permissions.canQuery()) { applicationContext.requestReadPermission() } diff --git a/test/src/main/java/contacts/test/entities/TestData.kt b/test/src/main/java/contacts/test/entities/TestData.kt index f663cef4..47bbdaa9 100644 --- a/test/src/main/java/contacts/test/entities/TestData.kt +++ b/test/src/main/java/contacts/test/entities/TestData.kt @@ -1,7 +1,7 @@ package contacts.test.entities import contacts.core.entities.MimeType -import contacts.core.entities.custom.MutableCustomDataEntity +import contacts.core.entities.custom.MutableCustomData import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize @@ -27,7 +27,7 @@ internal data class TestData( */ val value: String = VALUE -) : MutableCustomDataEntity { +) : MutableCustomData { // MutableCustomDataEntity are also CustomDataEntity so this serves as both the mutable and // immutable implementations. This is okay because this isn't really mutable. diff --git a/test/src/main/java/contacts/test/entities/TestDataQuery.kt b/test/src/main/java/contacts/test/entities/TestDataQuery.kt index fd5d27b3..b1d636ec 100644 --- a/test/src/main/java/contacts/test/entities/TestDataQuery.kt +++ b/test/src/main/java/contacts/test/entities/TestDataQuery.kt @@ -1,7 +1,7 @@ package contacts.test.entities -import contacts.core.data.CommonDataQuery import contacts.core.data.DataQuery +import contacts.core.data.DataQueryFactory -internal fun DataQuery.testData(): CommonDataQuery = +internal fun DataQueryFactory.testData(): DataQuery = customData(TestDataMimeType) \ No newline at end of file diff --git a/ui/src/main/java/contacts/ui/entities/CommonDataEntityFactory.kt b/ui/src/main/java/contacts/ui/entities/CommonDataEntityFactory.kt deleted file mode 100644 index 0fd1ab05..00000000 --- a/ui/src/main/java/contacts/ui/entities/CommonDataEntityFactory.kt +++ /dev/null @@ -1,42 +0,0 @@ -package contacts.ui.entities - -import contacts.core.entities.* - -/** - * Creates instances of [CommonDataEntity]. - */ -interface CommonDataEntityFactory { - - /** - * Returns a new instance of [E]. - */ - fun create(): E -} - -object AddressFactory : CommonDataEntityFactory { - override fun create() = MutableAddress() -} - -object EmailFactory : CommonDataEntityFactory { - override fun create() = MutableEmail() -} - -object EventFactory : CommonDataEntityFactory { - override fun create() = MutableEvent() -} - -object ImFactory : CommonDataEntityFactory { - override fun create() = MutableIm() -} - -object PhoneFactory : CommonDataEntityFactory { - override fun create() = MutablePhone() -} - -object RelationFactory : CommonDataEntityFactory { - override fun create() = MutableRelation() -} - -object WebsiteFactory : CommonDataEntityFactory { - override fun create() = MutableWebsite() -} \ No newline at end of file diff --git a/ui/src/main/java/contacts/ui/entities/CommonDataEntityTypeFactory.kt b/ui/src/main/java/contacts/ui/entities/CommonDataEntityTypeFactory.kt deleted file mode 100644 index 1233a3fd..00000000 --- a/ui/src/main/java/contacts/ui/entities/CommonDataEntityTypeFactory.kt +++ /dev/null @@ -1,161 +0,0 @@ -package contacts.ui.entities - -import android.content.res.Resources -import contacts.core.entities.* - -/** - * Creates instance of [CommonDataEntityType]. - */ -interface CommonDataEntityTypeFactory { - - /** - * Returns all the system types. - * - * The [CommonDataEntityType.typeLabel] is a system-defined string. - */ - fun systemTypes(resources: Resources): MutableList> - - /** - * Creates a new user custom [CommonDataEntityType] with the given [labelStr]. - * - * The [CommonDataEntityType.typeLabel] is a user input string. - */ - fun userCustomType(labelStr: String): CommonDataEntityType - - /** - * Returns the [CommonDataEntityType] of the given [data] [E]. - * - * If the [CommonDataEntity.Type] [T] is null, it will default to a non-null system type. - * - * The [CommonDataEntityType.typeLabel] may be a user input string or a system-defined string. - */ - fun from(resources: Resources, data: E): CommonDataEntityType -} - -object AddressTypeFactory : CommonDataEntityTypeFactory { - - override fun systemTypes(resources: Resources): MutableList> = - Address.Type.values() - .asSequence() - .map { type -> CommonDataEntityType(type, type.labelStr(resources, null), false) } - .toMutableList() - - override fun userCustomType(labelStr: String): CommonDataEntityType = - CommonDataEntityType(Address.Type.CUSTOM, labelStr, true) - - override fun from( - resources: Resources, data: MutableAddress - ): CommonDataEntityType = - (data.type ?: DEFAULT_TYPE).let { type -> - CommonDataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) - } - - private val DEFAULT_TYPE = Address.Type.HOME -} - -object EmailTypeFactory : CommonDataEntityTypeFactory { - - override fun systemTypes(resources: Resources): MutableList> = - Email.Type.values() - .asSequence() - .map { type -> CommonDataEntityType(type, type.labelStr(resources, null), false) } - .toMutableList() - - override fun userCustomType(labelStr: String): CommonDataEntityType = - CommonDataEntityType(Email.Type.CUSTOM, labelStr, true) - - override fun from(resources: Resources, data: MutableEmail): CommonDataEntityType = - (data.type ?: DEFAULT_TYPE).let { type -> - CommonDataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) - } - - private val DEFAULT_TYPE = Email.Type.HOME -} - -object EventTypeFactory : CommonDataEntityTypeFactory { - - override fun systemTypes(resources: Resources): MutableList> = - Event.Type.values() - .asSequence() - .map { type -> CommonDataEntityType(type, type.labelStr(resources, null), false) } - .toMutableList() - - override fun userCustomType(labelStr: String): CommonDataEntityType = - CommonDataEntityType(Event.Type.CUSTOM, labelStr, true) - - override fun from( - resources: Resources, data: MutableEvent - ): CommonDataEntityType = - (data.type ?: DEFAULT_TYPE).let { type -> - CommonDataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) - } - - private val DEFAULT_TYPE = Event.Type.BIRTHDAY -} - -object ImsTypeFactory : CommonDataEntityTypeFactory { - - override fun systemTypes(resources: Resources): MutableList> = - Im.Protocol.values() - .asSequence() - .map { protocol -> - CommonDataEntityType(protocol, protocol.labelStr(resources, null), false) - } - .toMutableList() - - override fun userCustomType(labelStr: String): CommonDataEntityType = - CommonDataEntityType(Im.Protocol.CUSTOM, labelStr, true) - - override fun from( - resources: Resources, data: MutableIm - ): CommonDataEntityType = - (data.type ?: DEFAULT_TYPE).let { protocol -> - CommonDataEntityType( - protocol, - protocol.labelStr(resources, data.label), - protocol.isCustomType - ) - } - - private val DEFAULT_TYPE = Im.Protocol.AIM -} - -object PhoneTypeFactory : CommonDataEntityTypeFactory { - - override fun systemTypes(resources: Resources): MutableList> = - Phone.Type.values() - .asSequence() - .map { type -> CommonDataEntityType(type, type.labelStr(resources, null), false) } - .toMutableList() - - override fun userCustomType(labelStr: String): CommonDataEntityType = - CommonDataEntityType(Phone.Type.CUSTOM, labelStr, true) - - override fun from(resources: Resources, data: MutablePhone): CommonDataEntityType = - (data.type ?: DEFAULT_TYPE).let { type -> - CommonDataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) - } - - private val DEFAULT_TYPE = Phone.Type.MOBILE -} - -object RelationTypeFactory : CommonDataEntityTypeFactory { - - override fun systemTypes(resources: Resources): MutableList> = - Relation.Type.values() - .asSequence() - .map { type -> CommonDataEntityType(type, type.labelStr(resources, null), false) } - .toMutableList() - - override fun userCustomType(labelStr: String): CommonDataEntityType = - CommonDataEntityType(Relation.Type.CUSTOM, labelStr, true) - - override fun from( - resources: Resources, data: MutableRelation - ): CommonDataEntityType = - (data.type ?: DEFAULT_TYPE).let { type -> - CommonDataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) - } - - private val DEFAULT_TYPE = Relation.Type.ASSISTANT -} \ No newline at end of file diff --git a/ui/src/main/java/contacts/ui/entities/DataEntityFactory.kt b/ui/src/main/java/contacts/ui/entities/DataEntityFactory.kt new file mode 100644 index 00000000..3d977640 --- /dev/null +++ b/ui/src/main/java/contacts/ui/entities/DataEntityFactory.kt @@ -0,0 +1,42 @@ +package contacts.ui.entities + +import contacts.core.entities.* + +/** + * Creates instances of [DataEntity]. + */ +interface DataEntityFactory { + + /** + * Returns a new instance of [E]. + */ + fun create(): E +} + +object AddressFactory : DataEntityFactory { + override fun create() = MutableAddress() +} + +object EmailFactory : DataEntityFactory { + override fun create() = MutableEmail() +} + +object EventFactory : DataEntityFactory { + override fun create() = MutableEvent() +} + +object ImFactory : DataEntityFactory { + override fun create() = MutableIm() +} + +object PhoneFactory : DataEntityFactory { + override fun create() = MutablePhone() +} + +object RelationFactory : DataEntityFactory { + override fun create() = MutableRelation() +} + +object WebsiteFactory : DataEntityFactory { + override fun create() = MutableWebsite() +} \ No newline at end of file diff --git a/ui/src/main/java/contacts/ui/entities/CommonDataEntityType.kt b/ui/src/main/java/contacts/ui/entities/DataEntityType.kt similarity index 75% rename from ui/src/main/java/contacts/ui/entities/CommonDataEntityType.kt rename to ui/src/main/java/contacts/ui/entities/DataEntityType.kt index 0516645b..f0c47340 100644 --- a/ui/src/main/java/contacts/ui/entities/CommonDataEntityType.kt +++ b/ui/src/main/java/contacts/ui/entities/DataEntityType.kt @@ -1,16 +1,16 @@ package contacts.ui.entities -import contacts.core.entities.CommonDataEntity +import contacts.core.entities.DataEntity /** - * A wrapper around a [CommonDataEntity.Type] [T] that pairs the underlying type with its string - * representation [typeLabel] (derived from the [CommonDataEntity.Type.labelStr]). + * A wrapper around a [DataEntity.Type] [T] that pairs the underlying type with its string + * representation [typeLabel] (derived from the [DataEntity.Type.labelStr]). * * This is useful for displaying user-created and system-provided types in a UI adapter * (e.g. [android.widget.ArrayAdapter] for [android.widget.Spinner]) without having to create * custom adapters. */ -data class CommonDataEntityType internal constructor( +data class DataEntityType internal constructor( /** * The type of data. diff --git a/ui/src/main/java/contacts/ui/entities/DataEntityTypeFactory.kt b/ui/src/main/java/contacts/ui/entities/DataEntityTypeFactory.kt new file mode 100644 index 00000000..dd70b1a5 --- /dev/null +++ b/ui/src/main/java/contacts/ui/entities/DataEntityTypeFactory.kt @@ -0,0 +1,161 @@ +package contacts.ui.entities + +import android.content.res.Resources +import contacts.core.entities.* + +/** + * Creates instance of [DataEntityType]. + */ +interface DataEntityTypeFactory { + + /** + * Returns all the system types. + * + * The [DataEntityType.typeLabel] is a system-defined string. + */ + fun systemTypes(resources: Resources): MutableList> + + /** + * Creates a new user custom [DataEntityType] with the given [labelStr]. + * + * The [DataEntityType.typeLabel] is a user input string. + */ + fun userCustomType(labelStr: String): DataEntityType + + /** + * Returns the [DataEntityType] of the given [data] [E]. + * + * If the [DataEntity.Type] [T] is null, it will default to a non-null system type. + * + * The [DataEntityType.typeLabel] may be a user input string or a system-defined string. + */ + fun from(resources: Resources, data: E): DataEntityType +} + +object AddressTypeFactory : DataEntityTypeFactory { + + override fun systemTypes(resources: Resources): MutableList> = + Address.Type.values() + .asSequence() + .map { type -> DataEntityType(type, type.labelStr(resources, null), false) } + .toMutableList() + + override fun userCustomType(labelStr: String): DataEntityType = + DataEntityType(Address.Type.CUSTOM, labelStr, true) + + override fun from( + resources: Resources, data: MutableAddress + ): DataEntityType = + (data.type ?: DEFAULT_TYPE).let { type -> + DataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) + } + + private val DEFAULT_TYPE = Address.Type.HOME +} + +object EmailTypeFactory : DataEntityTypeFactory { + + override fun systemTypes(resources: Resources): MutableList> = + Email.Type.values() + .asSequence() + .map { type -> DataEntityType(type, type.labelStr(resources, null), false) } + .toMutableList() + + override fun userCustomType(labelStr: String): DataEntityType = + DataEntityType(Email.Type.CUSTOM, labelStr, true) + + override fun from(resources: Resources, data: MutableEmail): DataEntityType = + (data.type ?: DEFAULT_TYPE).let { type -> + DataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) + } + + private val DEFAULT_TYPE = Email.Type.HOME +} + +object EventTypeFactory : DataEntityTypeFactory { + + override fun systemTypes(resources: Resources): MutableList> = + Event.Type.values() + .asSequence() + .map { type -> DataEntityType(type, type.labelStr(resources, null), false) } + .toMutableList() + + override fun userCustomType(labelStr: String): DataEntityType = + DataEntityType(Event.Type.CUSTOM, labelStr, true) + + override fun from( + resources: Resources, data: MutableEvent + ): DataEntityType = + (data.type ?: DEFAULT_TYPE).let { type -> + DataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) + } + + private val DEFAULT_TYPE = Event.Type.BIRTHDAY +} + +object ImsTypeFactory : DataEntityTypeFactory { + + override fun systemTypes(resources: Resources): MutableList> = + Im.Protocol.values() + .asSequence() + .map { protocol -> + DataEntityType(protocol, protocol.labelStr(resources, null), false) + } + .toMutableList() + + override fun userCustomType(labelStr: String): DataEntityType = + DataEntityType(Im.Protocol.CUSTOM, labelStr, true) + + override fun from( + resources: Resources, data: MutableIm + ): DataEntityType = + (data.type ?: DEFAULT_TYPE).let { protocol -> + DataEntityType( + protocol, + protocol.labelStr(resources, data.label), + protocol.isCustomType + ) + } + + private val DEFAULT_TYPE = Im.Protocol.AIM +} + +object PhoneTypeFactory : DataEntityTypeFactory { + + override fun systemTypes(resources: Resources): MutableList> = + Phone.Type.values() + .asSequence() + .map { type -> DataEntityType(type, type.labelStr(resources, null), false) } + .toMutableList() + + override fun userCustomType(labelStr: String): DataEntityType = + DataEntityType(Phone.Type.CUSTOM, labelStr, true) + + override fun from(resources: Resources, data: MutablePhone): DataEntityType = + (data.type ?: DEFAULT_TYPE).let { type -> + DataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) + } + + private val DEFAULT_TYPE = Phone.Type.MOBILE +} + +object RelationTypeFactory : DataEntityTypeFactory { + + override fun systemTypes(resources: Resources): MutableList> = + Relation.Type.values() + .asSequence() + .map { type -> DataEntityType(type, type.labelStr(resources, null), false) } + .toMutableList() + + override fun userCustomType(labelStr: String): DataEntityType = + DataEntityType(Relation.Type.CUSTOM, labelStr, true) + + override fun from( + resources: Resources, data: MutableRelation + ): DataEntityType = + (data.type ?: DEFAULT_TYPE).let { type -> + DataEntityType(type, type.labelStr(resources, data.label), type.isCustomType) + } + + private val DEFAULT_TYPE = Relation.Type.ASSISTANT +} \ No newline at end of file diff --git a/ui/src/main/java/contacts/ui/view/AddressesView.kt b/ui/src/main/java/contacts/ui/view/AddressesView.kt index bb9ae8b5..9cfd2209 100644 --- a/ui/src/main/java/contacts/ui/view/AddressesView.kt +++ b/ui/src/main/java/contacts/ui/view/AddressesView.kt @@ -10,13 +10,13 @@ import contacts.ui.entities.AddressFactory import contacts.ui.entities.AddressTypeFactory /** - * A [CommonDataEntityWithTypeListView] for [MutableAddress]es. + * A [DataEntityWithTypeListView] for [MutableAddress]es. */ class AddressesView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityWithTypeListView( +) : DataEntityWithTypeListView( context, attributeSet, defStyleAttr, dataFactory = AddressFactory, dataViewFactory = AddressViewFactory, @@ -24,9 +24,9 @@ class AddressesView @JvmOverloads constructor( ) private object AddressViewFactory : - CommonDataEntityWithTypeView.Factory { - override fun create(context: Context): CommonDataEntityWithTypeView = - CommonDataEntityWithTypeView( + DataEntityWithTypeView.Factory { + override fun create(context: Context): DataEntityWithTypeView = + DataEntityWithTypeView( context, dataFieldInputType = InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS, dataFieldHintResId = R.string.contacts_ui_address_hint, diff --git a/ui/src/main/java/contacts/ui/view/CommonDataEntityListView.kt b/ui/src/main/java/contacts/ui/view/DataEntityListView.kt similarity index 88% rename from ui/src/main/java/contacts/ui/view/CommonDataEntityListView.kt rename to ui/src/main/java/contacts/ui/view/DataEntityListView.kt index 018afa20..a17a287a 100644 --- a/ui/src/main/java/contacts/ui/view/CommonDataEntityListView.kt +++ b/ui/src/main/java/contacts/ui/view/DataEntityListView.kt @@ -3,12 +3,12 @@ package contacts.ui.view import android.content.Context import android.util.AttributeSet import android.widget.LinearLayout -import contacts.core.entities.MutableCommonDataEntity +import contacts.core.entities.MutableData import contacts.core.entities.removeAll -import contacts.ui.entities.CommonDataEntityFactory +import contacts.ui.entities.DataEntityFactory /** - * A (vertical) [LinearLayout] that displays a list of [MutableCommonDataEntity] and handles + * A (vertical) [LinearLayout] that displays a list of [MutableData] and handles * the modifications to the given mutable list. * * Setting the [dataList] will automatically update the views. Any modifications in the views will @@ -33,12 +33,12 @@ import contacts.ui.entities.CommonDataEntityFactory * I usually am a proponent of passive views and don't add any logic to views. However, I will make * an exception for this basic view that I don't really encourage consumers to use. */ -abstract class CommonDataEntityListView>( +abstract class DataEntityListView>( context: Context, attributeSet: AttributeSet?, defStyleAttr: Int, - private val dataFactory: CommonDataEntityFactory, - private val dataViewFactory: CommonDataEntityView.Factory, + private val dataFactory: DataEntityFactory, + private val dataViewFactory: DataEntityView.Factory, ) : LinearLayout(context, attributeSet, defStyleAttr) { /** @@ -106,7 +106,7 @@ abstract class CommonDataEntityListView -@JvmOverloads constructor( +open class DataEntityView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0, - layoutRes: Int = R.layout.view_common_data_entity, + layoutRes: Int = R.layout.view_data_entity, dataFieldInputType: Int? = null, dataFieldHintResId: Int? = null, dataFieldIsFocusable: Boolean = true, @@ -143,7 +142,7 @@ open class CommonDataEntityView fun onDataBegin() } - interface Factory> { + interface Factory> { fun create(context: Context): V } } \ No newline at end of file diff --git a/ui/src/main/java/contacts/ui/view/CommonDataEntityWithTypeListView.kt b/ui/src/main/java/contacts/ui/view/DataEntityWithTypeListView.kt similarity index 78% rename from ui/src/main/java/contacts/ui/view/CommonDataEntityWithTypeListView.kt rename to ui/src/main/java/contacts/ui/view/DataEntityWithTypeListView.kt index 2b120238..8e576f2c 100644 --- a/ui/src/main/java/contacts/ui/view/CommonDataEntityWithTypeListView.kt +++ b/ui/src/main/java/contacts/ui/view/DataEntityWithTypeListView.kt @@ -3,14 +3,14 @@ package contacts.ui.view import android.content.Context import android.util.AttributeSet import android.widget.LinearLayout -import contacts.core.entities.CommonDataEntity -import contacts.core.entities.MutableCommonDataEntityWithType -import contacts.ui.entities.CommonDataEntityFactory +import contacts.core.entities.DataEntity +import contacts.core.entities.MutableDataWithType +import contacts.ui.entities.DataEntityFactory /** - * A (vertical) [LinearLayout] that displays a list of [MutableCommonDataEntityWithType] and handles + * A (vertical) [LinearLayout] that displays a list of [MutableDataWithType] and handles * the modifications to the given mutable list. Each of the mutable entity in the list is displayed - * in a [CommonDataEntityWithTypeView]. + * in a [DataEntityWithTypeView]. * * Setting the [dataList] will automatically update the views. Any modifications in the views will * also be made to the [dataList]. @@ -34,15 +34,14 @@ import contacts.ui.entities.CommonDataEntityFactory * I usually am a proponent of passive views and don't add any logic to views. However, I will make * an exception for this basic view that I don't really encourage consumers to use. */ -abstract class CommonDataEntityWithTypeListView ->( +abstract class DataEntityWithTypeListView>( context: Context, attributeSet: AttributeSet?, defStyleAttr: Int, - dataFactory: CommonDataEntityFactory, - dataViewFactory: CommonDataEntityWithTypeView.Factory, + dataFactory: DataEntityFactory, + dataViewFactory: DataEntityWithTypeView.Factory, private val defaultUnderlyingDataTypes: List -) : CommonDataEntityListView>( +) : DataEntityListView>( context, attributeSet, defStyleAttr, diff --git a/ui/src/main/java/contacts/ui/view/CommonDataEntityWithTypeView.kt b/ui/src/main/java/contacts/ui/view/DataEntityWithTypeView.kt similarity index 86% rename from ui/src/main/java/contacts/ui/view/CommonDataEntityWithTypeView.kt rename to ui/src/main/java/contacts/ui/view/DataEntityWithTypeView.kt index 6725705e..25831b38 100644 --- a/ui/src/main/java/contacts/ui/view/CommonDataEntityWithTypeView.kt +++ b/ui/src/main/java/contacts/ui/view/DataEntityWithTypeView.kt @@ -7,16 +7,16 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.RelativeLayout import android.widget.Spinner -import contacts.core.entities.CommonDataEntity -import contacts.core.entities.MutableCommonDataEntityWithType +import contacts.core.entities.DataEntity +import contacts.core.entities.MutableDataWithType import contacts.ui.R -import contacts.ui.entities.CommonDataEntityType -import contacts.ui.entities.CommonDataEntityTypeFactory +import contacts.ui.entities.DataEntityType +import contacts.ui.entities.DataEntityTypeFactory import contacts.ui.util.CustomLabelInputDialog /** - * A [RelativeLayout] that displays a [MutableCommonDataEntityWithType] [E] that has a - * [CommonDataEntityType] and handles the modifications to it. + * A [RelativeLayout] that displays a [MutableDataWithType] [E] that has a + * [DataEntityType] and handles the modifications to it. * * Setting the [data] will automatically update the views and vice versa. * @@ -37,8 +37,7 @@ import contacts.ui.util.CustomLabelInputDialog * I usually am a proponent of passive views and don't add any logic to views. However, I will make * an exception for this basic view that I don't really encourage consumers to use. */ -open class CommonDataEntityWithTypeView -> +open class DataEntityWithTypeView> @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, @@ -46,16 +45,16 @@ open class CommonDataEntityWithTypeView dataFieldInputType: Int? = null, dataFieldHintResId: Int? = null, dataFieldIsFocusable: Boolean = true, - private val dataTypeFactory: CommonDataEntityTypeFactory? = null, -) : CommonDataEntityView( + private val dataTypeFactory: DataEntityTypeFactory? = null, +) : DataEntityView( context, attributeSet, defStyleAttr, - layoutRes = R.layout.view_common_data_entity_with_type, + layoutRes = R.layout.view_data_entity_with_type, dataFieldInputType = dataFieldInputType, dataFieldHintResId = dataFieldHintResId, dataFieldIsFocusable = dataFieldIsFocusable ) { - private var selectedType: CommonDataEntityType? = null + private var selectedType: DataEntityType? = null set(value) { field = value @@ -66,7 +65,7 @@ open class CommonDataEntityWithTypeView } private val dataTypeField: Spinner = findViewById(R.id.dataTypeField) - private val dataTypesAdapter: ArrayAdapter> + private val dataTypesAdapter: ArrayAdapter> init { dataTypeField.apply { @@ -171,8 +170,8 @@ open class CommonDataEntityWithTypeView } } - interface Factory> : - CommonDataEntityView.Factory> + interface Factory> : + DataEntityView.Factory> } /** diff --git a/ui/src/main/java/contacts/ui/view/EmailsView.kt b/ui/src/main/java/contacts/ui/view/EmailsView.kt index 6147bd1c..dfad8ec8 100644 --- a/ui/src/main/java/contacts/ui/view/EmailsView.kt +++ b/ui/src/main/java/contacts/ui/view/EmailsView.kt @@ -10,13 +10,13 @@ import contacts.ui.entities.EmailFactory import contacts.ui.entities.EmailTypeFactory /** - * A [CommonDataEntityWithTypeListView] for [MutableEmail]s. + * A [DataEntityWithTypeListView] for [MutableEmail]s. */ class EmailsView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityWithTypeListView( +) : DataEntityWithTypeListView( context, attributeSet, defStyleAttr, dataFactory = EmailFactory, dataViewFactory = EmailViewFactory, @@ -24,9 +24,9 @@ class EmailsView @JvmOverloads constructor( ) private object EmailViewFactory : - CommonDataEntityWithTypeView.Factory { - override fun create(context: Context): CommonDataEntityWithTypeView = - CommonDataEntityWithTypeView( + DataEntityWithTypeView.Factory { + override fun create(context: Context): DataEntityWithTypeView = + DataEntityWithTypeView( context, dataFieldInputType = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS, dataFieldHintResId = R.string.contacts_ui_email_hint, diff --git a/ui/src/main/java/contacts/ui/view/EventsView.kt b/ui/src/main/java/contacts/ui/view/EventsView.kt index 85f06c0e..448ea7a2 100644 --- a/ui/src/main/java/contacts/ui/view/EventsView.kt +++ b/ui/src/main/java/contacts/ui/view/EventsView.kt @@ -14,20 +14,20 @@ import contacts.ui.entities.EventTypeFactory import java.util.* /** - * A [CommonDataEntityWithTypeListView] for [MutableEvent]s. + * A [DataEntityWithTypeListView] for [MutableEvent]s. */ class EventsView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityWithTypeListView( +) : DataEntityWithTypeListView( context, attributeSet, defStyleAttr, dataFactory = EventFactory, dataViewFactory = EventsViewFactory, defaultUnderlyingDataTypes = Event.Type.values().filter { !it.isCustomType } ) -private class EventView(context: Context) : CommonDataEntityWithTypeView( +private class EventView(context: Context) : DataEntityWithTypeView( context, dataFieldInputType = InputType.TYPE_NULL, dataFieldHintResId = R.string.contacts_ui_event_hint, @@ -55,7 +55,7 @@ private class EventView(context: Context) : CommonDataEntityWithTypeView { - override fun create(context: Context): CommonDataEntityWithTypeView = + DataEntityWithTypeView.Factory { + override fun create(context: Context): DataEntityWithTypeView = EventView(context) } \ No newline at end of file diff --git a/ui/src/main/java/contacts/ui/view/ImsView.kt b/ui/src/main/java/contacts/ui/view/ImsView.kt index 515303d8..9778535f 100644 --- a/ui/src/main/java/contacts/ui/view/ImsView.kt +++ b/ui/src/main/java/contacts/ui/view/ImsView.kt @@ -10,13 +10,13 @@ import contacts.ui.entities.ImFactory import contacts.ui.entities.ImsTypeFactory /** - * A [CommonDataEntityWithTypeListView] for [MutableIm]s. + * A [DataEntityWithTypeListView] for [MutableIm]s. */ class ImsView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityWithTypeListView( +) : DataEntityWithTypeListView( context, attributeSet, defStyleAttr, dataFactory = ImFactory, dataViewFactory = ImViewFactory, @@ -24,9 +24,9 @@ class ImsView @JvmOverloads constructor( ) private object ImViewFactory : - CommonDataEntityWithTypeView.Factory { - override fun create(context: Context): CommonDataEntityWithTypeView = - CommonDataEntityWithTypeView( + DataEntityWithTypeView.Factory { + override fun create(context: Context): DataEntityWithTypeView = + DataEntityWithTypeView( context, dataFieldInputType = InputType.TYPE_CLASS_TEXT, dataFieldHintResId = R.string.contacts_ui_im_hint, diff --git a/ui/src/main/java/contacts/ui/view/NicknameView.kt b/ui/src/main/java/contacts/ui/view/NicknameView.kt index eba2cece..13d94dd5 100644 --- a/ui/src/main/java/contacts/ui/view/NicknameView.kt +++ b/ui/src/main/java/contacts/ui/view/NicknameView.kt @@ -7,13 +7,13 @@ import contacts.core.entities.MutableNickname import contacts.ui.R /** - * A [CommonDataEntityView] for a [MutableNickname]. + * A [DataEntityView] for a [MutableNickname]. */ class NicknameView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityView( +) : DataEntityView( context, attributeSet, defStyleAttr, dataFieldInputType = InputType.TYPE_TEXT_VARIATION_PERSON_NAME, dataFieldHintResId = R.string.contacts_ui_nickname_hint, diff --git a/ui/src/main/java/contacts/ui/view/OrganizationView.kt b/ui/src/main/java/contacts/ui/view/OrganizationView.kt index d8721e7e..16e9745b 100644 --- a/ui/src/main/java/contacts/ui/view/OrganizationView.kt +++ b/ui/src/main/java/contacts/ui/view/OrganizationView.kt @@ -9,13 +9,13 @@ import contacts.ui.R import contacts.ui.text.AbstractTextWatcher /** - * A [CommonDataEntityView] for a [MutableOrganization]. + * A [DataEntityView] for a [MutableOrganization]. */ class OrganizationView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityView( +) : DataEntityView( context, attributeSet, defStyleAttr, layoutRes = R.layout.view_organization, dataFieldInputType = InputType.TYPE_CLASS_TEXT, diff --git a/ui/src/main/java/contacts/ui/view/PhonesView.kt b/ui/src/main/java/contacts/ui/view/PhonesView.kt index e6a0bfc4..580f5ffc 100644 --- a/ui/src/main/java/contacts/ui/view/PhonesView.kt +++ b/ui/src/main/java/contacts/ui/view/PhonesView.kt @@ -10,13 +10,13 @@ import contacts.ui.entities.PhoneFactory import contacts.ui.entities.PhoneTypeFactory /** - * A [CommonDataEntityWithTypeListView] for [MutablePhone]s. + * A [DataEntityWithTypeListView] for [MutablePhone]s. */ class PhonesView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityWithTypeListView( +) : DataEntityWithTypeListView( context, attributeSet, defStyleAttr, dataFactory = PhoneFactory, dataViewFactory = PhoneViewFactory, @@ -27,9 +27,9 @@ class PhonesView @JvmOverloads constructor( ) private object PhoneViewFactory : - CommonDataEntityWithTypeView.Factory { - override fun create(context: Context): CommonDataEntityWithTypeView = - CommonDataEntityWithTypeView( + DataEntityWithTypeView.Factory { + override fun create(context: Context): DataEntityWithTypeView = + DataEntityWithTypeView( context, dataFieldInputType = InputType.TYPE_CLASS_PHONE, dataFieldHintResId = R.string.contacts_ui_phone_number_hint, diff --git a/ui/src/main/java/contacts/ui/view/RelationsView.kt b/ui/src/main/java/contacts/ui/view/RelationsView.kt index 817baa70..76880a8e 100644 --- a/ui/src/main/java/contacts/ui/view/RelationsView.kt +++ b/ui/src/main/java/contacts/ui/view/RelationsView.kt @@ -10,13 +10,13 @@ import contacts.ui.entities.RelationFactory import contacts.ui.entities.RelationTypeFactory /** - * A [CommonDataEntityWithTypeListView] for [MutableRelation]s. + * A [DataEntityWithTypeListView] for [MutableRelation]s. */ class RelationsView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityWithTypeListView( +) : DataEntityWithTypeListView( context, attributeSet, defStyleAttr, dataFactory = RelationFactory, dataViewFactory = RelationViewFactory, @@ -24,9 +24,9 @@ class RelationsView @JvmOverloads constructor( ) private object RelationViewFactory : - CommonDataEntityWithTypeView.Factory { - override fun create(context: Context): CommonDataEntityWithTypeView = - CommonDataEntityWithTypeView( + DataEntityWithTypeView.Factory { + override fun create(context: Context): DataEntityWithTypeView = + DataEntityWithTypeView( context, dataFieldInputType = InputType.TYPE_CLASS_TEXT, dataFieldHintResId = R.string.contacts_ui_relation_hint, diff --git a/ui/src/main/java/contacts/ui/view/SipAddressView.kt b/ui/src/main/java/contacts/ui/view/SipAddressView.kt index 37270310..6271d158 100644 --- a/ui/src/main/java/contacts/ui/view/SipAddressView.kt +++ b/ui/src/main/java/contacts/ui/view/SipAddressView.kt @@ -7,13 +7,13 @@ import contacts.core.entities.MutableSipAddress import contacts.ui.R /** - * A [CommonDataEntityView] for a [MutableSipAddress]. + * A [DataEntityView] for a [MutableSipAddress]. */ class SipAddressView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityView( +) : DataEntityView( context, attributeSet, defStyleAttr, dataFieldInputType = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS, dataFieldHintResId = R.string.contacts_ui_sip_address_hint, diff --git a/ui/src/main/java/contacts/ui/view/WebsitesView.kt b/ui/src/main/java/contacts/ui/view/WebsitesView.kt index 573efc64..9244af68 100644 --- a/ui/src/main/java/contacts/ui/view/WebsitesView.kt +++ b/ui/src/main/java/contacts/ui/view/WebsitesView.kt @@ -8,22 +8,22 @@ import contacts.ui.R import contacts.ui.entities.WebsiteFactory /** - * A [CommonDataEntityListView] for [MutableWebsite]s. + * A [DataEntityListView] for [MutableWebsite]s. */ class WebsitesView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 -) : CommonDataEntityListView>( +) : DataEntityListView>( context, attributeSet, defStyleAttr, dataFactory = WebsiteFactory, dataViewFactory = WebsiteViewFactory ) private object WebsiteViewFactory : - CommonDataEntityView.Factory> { - override fun create(context: Context): CommonDataEntityView = - CommonDataEntityView( + DataEntityView.Factory> { + override fun create(context: Context): DataEntityView = + DataEntityView( context, dataFieldInputType = InputType.TYPE_TEXT_VARIATION_URI, dataFieldHintResId = R.string.contacts_ui_website_hint, diff --git a/ui/src/main/res/layout/view_common_data_entity.xml b/ui/src/main/res/layout/view_data_entity.xml similarity index 100% rename from ui/src/main/res/layout/view_common_data_entity.xml rename to ui/src/main/res/layout/view_data_entity.xml diff --git a/ui/src/main/res/layout/view_common_data_entity_with_type.xml b/ui/src/main/res/layout/view_data_entity_with_type.xml similarity index 100% rename from ui/src/main/res/layout/view_common_data_entity_with_type.xml rename to ui/src/main/res/layout/view_data_entity_with_type.xml