Created
June 12, 2019 08:24
-
-
Save Syex/0c737976f4f33bf4e8923a6b196fc97a to your computer and use it in GitHub Desktop.
This file contains 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
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