Created
January 14, 2022 07:05
-
-
Save vikasmain/f3fb0b191e1f1f910da56c3bbcee270f 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
@MovieActivityScope | |
class MoviePresenter @Inject constructor( | |
private val movieView: MovieContract.MovieView, | |
private val scope: CoroutineScope, | |
private val movieModel: MovieModel | |
) { | |
fun onAttach() { | |
callMoviesApi() | |
observeOnClickStateFlow() | |
} | |
internal fun callMoviesApi() { | |
movieModel.callMoviesApi() | |
.onStart { | |
movieView.showLoadingView() | |
} | |
.catch { | |
movieView.showErrorView() | |
} | |
.onEach { | |
movieView.showMoviesList(it) | |
} | |
.onCompletion { | |
movieView.hideLoadingView() | |
} | |
.launchIn(scope) | |
} | |
internal fun observeOnClickStateFlow() { | |
MovieStateFlow.onClickStateFlow.asStateFlow() | |
.onEach { | |
it?.let { | |
movieView.openSingleItemView(it) | |
} | |
} | |
.catch { | |
Log.e("MovieActivity", "Error while observing stateflow$it") | |
}.launchIn(scope) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment