Guest User

Untitled

a guest
Nov 25th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. data class SimpleContact(val displayName: String, val isStarred: Boolean) {
  2. companion object {
  3. fun from(cursor: Cursor) =
  4. SimpleContact(
  5. cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME)),
  6. cursor.getInt(cursor.getColumnIndex(Contacts.STARRED)) == 1)
  7. }
  8. }
  9.  
  10. fun contacts(contentResolver: ContentResolver): Flowable<SimpleContact> =
  11. contentResolver.uriChangesOf(
  12. {
  13. itemsFor(
  14. { query(Contacts.CONTENT_URI,
  15. arrayOf(Contacts.DISPLAY_NAME, Contacts.STARRED),
  16. null, null, "${Contacts.DISPLAY_NAME} ASC") },
  17. { SimpleContact.from(it) }
  18. )
  19. }, Contacts.CONTENT_URI)
  20. .subscribeOn(AndroidSchedulers.mainThread())
  21. .observeOn(Schedulers.io())
  22. .switchMap { obs -> obs }
Add Comment
Please, Sign In to add comment