Skip to content

Instantly share code, notes, and snippets.

@surajsau
Created July 18, 2019 11:06
Show Gist options
  • Save surajsau/4c2d8010c7eda76c279711119b8e846d to your computer and use it in GitHub Desktop.
Save surajsau/4c2d8010c7eda76c279711119b8e846d to your computer and use it in GitHub Desktop.
MVP to MVVM: MainPresenter
class MainPresenter(val service: GithubService) {
var view: MainView? = null
fun search(searchString: String) {
view?.showProgress()
service.getRequest(searchString, 0)
.subscribeOn(..)
.observeOn(..)
.doOnSuccess { onSearchResultReceived(it) }
.doOnError{
view?.showError()
view?.hideProgress()
}
.subscribe()
}
private fun onSearchResultReceived(apiResponse: ApiResponse?) {
view?.hideError()
view?.hideProgress()
view?.setItems(apiResponse?.items)
}
fun onResultFavoriteClickReceive(message: ResultFavoriteMessage?) {
message?.let { view?.openRepositoryDetails(it.repo, it.owner) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment