Skip to content

Instantly share code, notes, and snippets.

@vicky7230
Created February 19, 2018 06:20
Show Gist options
  • Select an option

  • Save vicky7230/10843f9775c49c5bd717dfe1d28c961b to your computer and use it in GitHub Desktop.

Select an option

Save vicky7230/10843f9775c49c5bd717dfe1d28c961b to your computer and use it in GitHub Desktop.
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