Skip to content

Instantly share code, notes, and snippets.

View vestrel00's full-sized 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 December 8, 2021 01:34
The Contacts, Reborn library provides Kotlin coroutine extensions for all API functions to handle permissions and executing work in background threads
launch {
val contacts = Contacts(context)
.queryWithPermission()
...
.findWithContext()
val deferredResult = Contacts(context)
.insertWithPermission()
...
.commitAsync()
@vestrel00
vestrel00 / Contacts-delete.kt
Created October 7, 2021 20:10
If we no longer like John Doe, we can DELETE him from our life
Contacts(context)
.delete()
.contacts(johnDoe)
.commit()
@vestrel00
vestrel00 / Contacts-update.kt
Last active December 18, 2021 02:01
If John Doe switches jobs and heads over to Microsoft, we can UPDATE his data
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 October 7, 2021 20:08
CREATE/INSERT a contact with a name of "John Doe" who works at Amazon with a work email of "john.doe@amazon.com", Kotlinized
val insertResult = Contacts(context)
.insert()
.rawContact {
setName {
givenName = "John"
familyName = "Doe"
}
setOrganization {
company = "Amazon"
title = "Superstar"
@vestrel00
vestrel00 / Contacts-insert.kt
Last active December 18, 2021 02:00
CREATE/INSERT a contact with a name of "John Doe" who works at Amazon with a work email of "john.doe@amazon.com"
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 October 7, 2021 20:04
A query to get the first 20 Gmail emails ordered by email address in descending order
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 October 10, 2021 00:30
You have full access to all contacts and their data
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 October 7, 2021 19:56
A query that searches for Contacts, yielding the exact same results as the native Contacts app
val contacts = Contacts(context)
.broadQuery()
.whereAnyContactDataPartiallyMatches(searchText)
.find()
@vestrel00
vestrel00 / Contacts-basic-query.kt
Last active October 7, 2021 19:56
A basic, barebones query to get all Contacts
val contacts = Contacts(context).query().find()
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