Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 }
Add Comment
Please, Sign In to add comment