Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Working, life, and the universe!

Vandolf Estrellado vestrel00

👨‍💻
Working, life, and the universe!
View GitHub Profile
@vestrel00
vestrel00 / Contacts-async-permissions-coroutines.kt
Last active Dec 8, 2021
The Contacts, Reborn library provides Kotlin coroutine extensions for all API functions to handle permissions and executing work in background threads
View Contacts-async-permissions-coroutines.kt
launch {
val contacts = Contacts(context)
.queryWithPermission()
...
.findWithContext()
val deferredResult = Contacts(context)
.insertWithPermission()
...
.commitAsync()
@vestrel00
vestrel00 / Contacts-delete.kt
Created Oct 7, 2021
If we no longer like John Doe, we can DELETE him from our life
View Contacts-delete.kt
Contacts(context)
.delete()
.contacts(johnDoe)
.commit()
@vestrel00
vestrel00 / Contacts-update.kt
Last active Dec 18, 2021
If John Doe switches jobs and heads over to Microsoft, we can UPDATE his data
View Contacts-update.kt
Contacts(context)
.update()
.contacts(johnDoe.mutableCopy {
setOrganization {
company = "Microsoft"
title = "Newb"
}
emails().first().apply {
address = "john.doe@microsoft.com"
}
@vestrel00
vestrel00 / Contacts-insert-kotlinized.kt
Created Oct 7, 2021
CREATE/INSERT a contact with a name of "John Doe" who works at Amazon with a work email of "john.doe@amazon.com", Kotlinized
View Contacts-insert-kotlinized.kt
val insertResult = Contacts(context)
.insert()
.rawContact {
setName {
givenName = "John"
familyName = "Doe"
}
setOrganization {
company = "Amazon"
title = "Superstar"
@vestrel00
vestrel00 / Contacts-insert.kt
Last active Dec 18, 2021
CREATE/INSERT a contact with a name of "John Doe" who works at Amazon with a work email of "john.doe@amazon.com"
View Contacts-insert.kt
val insertResult = Contacts(context)
.insert()
.rawContacts(NewRawContact().apply {
name = NewName().apply {
givenName = "John"
familyName = "Doe"
}
organization = NewOrganization().apply {
company = "Amazon"
title = "Superstar"
@vestrel00
vestrel00 / Contacts-data-query.kt
Created Oct 7, 2021
A query to get the first 20 Gmail emails ordered by email address in descending order
View Contacts-data-query.kt
val emails = Contacts(context).data()
.query()
.emails()
.where(Fields.Email.Address endsWith "gmail.com")
.orderBy(Fields.Email.Address.desc(ignoreCase = true))
.offset(0)
.limit(20)
.find()
@vestrel00
vestrel00 / Contacts-data-access.kt
Last active Oct 10, 2021
You have full access to all contacts and their data
View Contacts-data-access.kt
Log.d(
"Contacts",
contacts.joinToString("\n\n") { contact ->
"""
ID: ${contact.id}
Display name: ${contact.displayNamePrimary}
Display name alt: ${contact.displayNameAlt}
Photo Uri: ${contact.photoUri}
@vestrel00
vestrel00 / Contacts-simple-query.kt
Created Oct 7, 2021
A query that searches for Contacts, yielding the exact same results as the native Contacts app
View Contacts-simple-query.kt
val contacts = Contacts(context)
.broadQuery()
.whereAnyContactDataPartiallyMatches(searchText)
.find()
@vestrel00
vestrel00 / Contacts-basic-query.kt
Last active Oct 7, 2021
A basic, barebones query to get all Contacts
View Contacts-basic-query.kt
val contacts = Contacts(context).query().find()
View Contacts-advanced-query.kt
val contacts = Contacts(context)
.query()
.where {
(Name.GivenName startsWith "leo") and
(Email.Address { endsWith("gmail.com") or endsWith("hotmail.com") }) and
(Address.Country equalToIgnoreCase "us") and
(Event { (Date lessThan Date().toWhereString()) and (Type equalTo EventEntity.Type.BIRTHDAY) }) and
(Contact.Options.Starred equalTo true) and
(Nickname.Name equalTo "DarEdEvil") and
(Organization.Company `in` listOf("facebook", "FB")) and