Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /**
  2. * initialize all resources
  3. * set current page to 1
  4. * create paginator and subscribe to events
  5. */
  6. override fun initialize() {
  7. currentPage = 1
  8. paginator = PublishProcessor.create()
  9.  
  10. val d = paginator.onBackpressureDrop()
  11. .doOnNext { view.showProgress() }
  12. .concatMap { contract.getItemsFromServer(it) }
  13. .observeOn(AndroidSchedulers.mainThread())
  14. .subscribe({
  15. view.hideProgress()
  16. view.showItems(it)
  17. currentPage++
  18. }, {
  19. view.hideProgress()
  20. view.showError(it.localizedMessage)
  21. })
  22.  
  23. disposables.add(d)
  24.  
  25. onLoadMore(currentPage)
  26. }
  27.  
  28. /**
  29. * called when list is scrolled to its bottom
  30. * @param page current page (not used)
  31. */
  32. override fun onLoadMore(page: Int) {
  33. paginator.onNext(currentPage)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement