Created
June 6, 2019 09:13
-
-
Save ntngel1/1dba4c022def00c21ba9e1efc0a73d03 to your computer and use it in GitHub Desktop.
shit
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
override fun currentUserCollection(page: Int?, limit: Int?): Single<PaginationResponse<UserCurrentEntity>> = | |
Single.create<PaginationResponse<UserCurrentEntity>> { emitter -> | |
realm.executeTransaction { realm -> | |
realm.where(RealmUserCurrentEntity::class.java) | |
.findAll() | |
.run { | |
val items = this.drop(page * limit) | |
.take(limit) | |
.let { realm.copyFromRealm(it) } | |
.map { it.toDomain() } | |
val totalItems = this.count() | |
val extraPage = if (totalItems % limit > 0) 1 else 0 | |
return@run PaginationResponse( | |
totalItems = totalItems, | |
itemsPerPage = limit, | |
countOfPages = totalItems / limit + extraPage, | |
items = items | |
) | |
} | |
.let(emitter::onSuccess) | |
} | |
}.subscribeOn(scheduler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment