Skip to content

Instantly share code, notes, and snippets.

@Syex
Created June 12, 2019 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Syex/0c737976f4f33bf4e8923a6b196fc97a to your computer and use it in GitHub Desktop.
Save Syex/0c737976f4f33bf4e8923a6b196fc97a to your computer and use it in GitHub Desktop.
class PopularMoviesPresenter(
private val getPopularMovies: GetPopularMovies,
coroutineContext: CoroutineContext = defaultDispatcher
) : BasePresenter<PopularMoviesView>(coroutineContext) {
override fun onViewAttached(view: PopularMoviesView) {
view.setLoadingVisible(true)
getPopularMovies()
}
private fun getPopularMovies() {
scope.launch {
getPopularMovies(
UseCase.None,
onSuccess = { view?.setPopularMovies(it.results) },
onFailure = { view?.showMoviesFailedToLoad() }
)
view?.setLoadingVisible(false)
}
}
}
interface PopularMoviesView {
fun setPopularMovies(movies: List<Movie>)
fun showMoviesFailedToLoad()
fun setLoadingVisible(visible: Boolean)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment