Created
April 29, 2018 17:26
-
-
Save luks91/d006c60b21589a9dd68d66be9c2b4ecc to your computer and use it in GitHub Desktop.
This file contains 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
private fun contacts(): Flowable<SimpleContact> = | |
Flowable.generate<SimpleContact, Cursor>( | |
Callable<Cursor> { | |
contentResolver.query(Contacts.CONTENT_URI, | |
arrayOf(Contacts.DISPLAY_NAME, Contacts.STARRED), | |
null, null, | |
"${Contacts.DISPLAY_NAME} ASC") | |
}, | |
BiFunction<Cursor, Emitter<SimpleContact>, Cursor> { cursor, emitter -> | |
if (cursor.moveToNext()) { | |
emitter.onNext(SimpleContact.from(cursor)) | |
} else { | |
emitter.onComplete() | |
} | |
return@BiFunction cursor | |
}, | |
Consumer<Cursor> { | |
cursor -> cursor.close() | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment