Created
November 23, 2017 15:28
-
-
Save luks91/4b8662c95940cadb37f7d7e206711875 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data class SimpleContact(val displayName: String, val isStarred: Boolean) { | |
| companion object { | |
| fun from(cursor: Cursor) = | |
| SimpleContact( | |
| cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME)), | |
| cursor.getInt(cursor.getColumnIndex(Contacts.STARRED)) == 1) | |
| } | |
| } | |
| fun contacts(contentResolver: ContentResolver): Flowable<SimpleContact> = | |
| contentResolver.uriChangesOf( | |
| { | |
| itemsFor( | |
| { query(Contacts.CONTENT_URI, | |
| arrayOf(Contacts.DISPLAY_NAME, Contacts.STARRED), | |
| null, null, "${Contacts.DISPLAY_NAME} ASC") }, | |
| { SimpleContact.from(it) } | |
| ) | |
| }, Contacts.CONTENT_URI) | |
| .subscribeOn(AndroidSchedulers.mainThread()) | |
| .observeOn(Schedulers.io()) | |
| .switchMap { obs -> obs } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment