How do I integrate the gender custom data?

Android Contacts API Library written in Kotlin with Java interoperability. No more ContentProviders and cursors. Say goodbye to ContactsContract. Build your own contacts app!

How do I integrate the gender custom data?

This library comes with Gender custom data that allows you to add gender information for all of you contacts. This custom data lives in the customdata-gender module. It is optional.

If you are looking to create your own custom data or get more insight on how the Gender custom data was built, read How do I integrate custom data?

Register the gender custom data with the Contacts API instance

You may register the Gender custom data when creating the Contacts API instance,

val contactsApi = Contacts(
    context,
    customDataRegistry = CustomDataRegistry().register(
        GenderRegistration()
    )
)

Or, alternatively after creating the Contacts API instance,

val contactsApi = Contacts(context)
GenderRegistration().registerTo(contacts.customDataRegistry)

Get/set gender custom data

Just like regular data kinds, gender custom data belong to a RawContact. A RawContact may only have 0 or 1 gender.

To get the gender of a RawContact,

val gender = rawContact.gender(contactsApi)

To get the genders of all RawContacts belonging to a Contact,

val genderSequence = contact.genders(contactsApi)
val genderList = contact.genderList(contactsApi)

To set the gender of a (mutable) RawContact,

mutableRawContact.setGender(contacts, mutableGender)
// or
mutableRawContact.setGender(contacts) {
    type = GenderEntity.Type.MALE
}

To set the gender of the first RawContact in a Contact,

mutableContact.setGender(contacts, mutableGender)
// or
mutableContact.setGender(contacts) {
    type = GenderEntity.Type.MALE
}

Use the gender custom data in queries, inserts, updates, and deletes

Once you have registered your custom data with the Contacts API instance, the API instance is now able to perform read and write operations on it.

Limitations

This library does not provide sync adapters for gender custom data. Unless you implement your own sync adapter, gender custom data…