Skip to content

Instantly share code, notes, and snippets.

@ntngel1
Created June 6, 2019 09:13
Show Gist options
  • Save ntngel1/1dba4c022def00c21ba9e1efc0a73d03 to your computer and use it in GitHub Desktop.
Save ntngel1/1dba4c022def00c21ba9e1efc0a73d03 to your computer and use it in GitHub Desktop.
shit
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