Created
February 19, 2018 06:20
-
-
Save vicky7230/10843f9775c49c5bd717dfe1d28c961b 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
| override fun search(subject: PublishSubject<String>) { | |
| compositeDisposable.add( | |
| subject | |
| .debounce(300, TimeUnit.MILLISECONDS) | |
| .filter(Predicate { it: String -> | |
| return@Predicate it.isNotEmpty() | |
| }) | |
| .distinctUntilChanged() | |
| .switchMap(Function<String, ObservableSource<Recipes>> { it -> | |
| query = it | |
| return@Function dataManager.searchRecipes( | |
| Config.API_KEY, | |
| it, | |
| "1" | |
| ) | |
| .subscribeOn(Schedulers.io()) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| }) | |
| .subscribe({ recipes -> | |
| if (!isViewAttached()) | |
| return@subscribe | |
| if (recipes.recipes != null) { | |
| mvpView?.refreshSearchList(recipes.recipes!!) | |
| page = 2 | |
| } | |
| }, { throwable -> | |
| if (!isViewAttached()) | |
| return@subscribe | |
| mvpView?.showMessage(throwable.message!!) | |
| Timber.e(throwable.message) | |
| }) | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment