alexstyl / contactstore

A modern, strongly-typed contacts API for Android.
https://alexstyl.github.io/contactstore
Apache License 2.0
440 stars 15 forks source link

Primary Phone/Email support? #77

Open bmc08gt opened 1 year ago

bmc08gt commented 1 year ago

Does this exist in the current API scheme with fetching? Im not seeing an easy way to check this data without a secondary cursor query on the phones and emails.

alexstyl commented 1 year ago

This is not something currently supported by ContactStore but it seems like a straightforward thing to support.

It should be a as simple as adding a isPrimary boolean to LabeledValue and forwarding the respective value in ContactQueries If you are up for contributing. (Line 301ish)

columnsToFetch.contains(Phones) && mimetype == PhoneColumns.CONTENT_ITEM_TYPE -> {
                          val phoneNumberString = item.getAsStringOrEmpty(PhoneColumns.NUMBER)
                          val id = item.getAsLong(PhoneColumns._ID)
                          if (phoneNumberString.isNotBlank() && id != null) {
                              // check if primary
                              val isPrimary = item.getAsInteger(PhoneColumns.IS_PRIMARY) != 0
                              val value = PhoneNumber(phoneNumberString)
                              val phoneEntry =
                                  // forward primary to LabeledValue
                                  LabeledValue(value, phoneLabelFrom(item), id, account, isPrimary)
                              phones.add(phoneEntry)
                          }
                      }

this would need to be done for all ContactColumns.