Last active
December 2, 2017 10:19
-
-
Save chetdeva/3261f48a88c03168c6f0dbc2188f932d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * initialize all resources | |
| * set current page to 1 | |
| * create paginator and subscribe to events | |
| */ | |
| override fun initialize() { | |
| currentPage = 1 // set page = 1 | |
| paginator = PublishProcessor.create() // create PublishProcessor | |
| val d = paginator.onBackpressureDrop() | |
| .filter { !loading } // return if it is still loading | |
| .doOnNext { loading = view.showProgress() } // loading = true | |
| .concatMap { contract.getUsersFromServer(it) } // API call | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribe({ | |
| loading = view.hideProgress() // loading = false | |
| view.showItems(it) // show items | |
| currentPage++ // increment page | |
| }, { | |
| loading = view.hideProgress() // loading = false | |
| view.showError(it.localizedMessage) // show error | |
| }) | |
| disposables.add(d) | |
| onLoadMore(currentPage) | |
| } | |
| /** | |
| * called when list is scrolled to its bottom | |
| * @param page current page (not used) | |
| */ | |
| override fun onLoadMore(page: Int) { | |
| paginator.onNext(currentPage) // increment page if not loading | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment