New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support setting/removing Contact/RawContact Photos as part of Insert and Update API calls #119
Comments
… functions and also prepare for insert and update API usage
Migration guide (to be included in release notes)PREVIOUSLY, to set /remove the Contact or RawContact photo, you would use one of these extension functions that immediately commits the changes directly into the database. These can only be used for Contact and RawContacts that are already inserted. [contact|rawContact].setPhoto(
contactsApi,
[photoInputStream|photoBytes|photoBitmap|photoBitmapDrawable]
)
[contact|rawContact].removePhoto(contactsApi) NOW, the above functions still exist with a different name and parameter types. [contact|rawContact].setPhotoDirect(
contactsApi,
PhotoData.from([photoInputStream|photoBytes|photoBitmap|photoBitmapDrawable])
)
[contact|rawContact].removePhotoDirect(contactsApi) More importantly, you are now also able to set/remove Contact and RawContact photos as part of insert and update API calls! Contacts(this).insert().rawContact { setPhoto(PhotoData.from(...)) }.commit()
Contacts(this)
.update()
.contacts(contact.mutableCopy { setPhoto(PhotoData.from(...)) })
.contacts(contact.mutableCopy { removePhoto() })
.rawContacts(rawContact.mutableCopy { setPhoto(PhotoData.from(...)) })
.rawContacts(rawContact.mutableCopy { removePhoto() })
.commit() Read the new documentation for the full guide; https://vestrel00.github.io/contacts-android/other/get-set-remove-contact-raw-contact-photo/ |
This is included in 0.3.0! |
Problem
As suggested in #116 (comment) (another big thanks to @lau1944 for this brilliant suggestion), the current way photos are set for new contacts that have not yet been inserted into the database is not very intuitive from a consumer point of view. I 100% agree.
Currently, the recommended way is to,
Instead, or additionally, consumers should be able to do the following,
The current functions in
contacts.core.util.ContactPhoto.kt
andcontacts.core.util.RawContactPhoto.kt
perform blocking work that touches the database immediately. This is completely different from the functions incontacts.core.util.MutableRawContactData.kt
that does not touch the database but use similarly named functions.For example,
In the above,
setPhoto
is a blocking call that touches the DB and should be done asynchronously with permission. On the other hand,setName
just modifies the value in memory (no DB operations are performed).Solution
To allow consumers to set/remove the photo as part of insert and update APIs...
setPhoto
functions tosetPhotoDirect
.photoData
property toMutableContact
,MutableRawContact
, andNewRawContact
. Make sure to support multiple formats;ByteArray
,Bitmap
,BitmapDrawable
, andInputStream
.allowBlanks
.deleteBlanks
.Other things to do
Notes
The text was updated successfully, but these errors were encountered: