Skip to content

Instantly share code, notes, and snippets.

@mahesaiqbal
Last active June 16, 2025 06:10
Show Gist options
  • Save mahesaiqbal/5144803670b9f974c85b7c0d0cbfbac2 to your computer and use it in GitHub Desktop.
Save mahesaiqbal/5144803670b9f974c85b7c0d0cbfbac2 to your computer and use it in GitHub Desktop.
Explaining about MVI Architecture
package com.mahesaiqbal.mvisample.presentation.view.popularmovie
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import com.mahesaiqbal.mvisample.presentation.viewmodel.PopularMovieViewModel
@Composable
fun PopularMovieScreen(
modifier: Modifier = Modifier,
viewModel: PopularMovieViewModel = hiltViewModel(),
onShowInfo: (String) -> Unit
) {
LaunchedEffect(Unit) {
viewModel.onIntent(PopularMovieIntent.GetPopularMovies)
}
LaunchedEffect(Unit) {
viewModel.effect.collect { effect ->
when (effect) {
is PopularMovieEffect.ShowInfo -> onShowInfo(effect.message)
is PopularMovieEffect.NavigateToDetail -> {
// Navigate to detail screen
}
}
}
}
Column(modifier = modifier.fillMaxSize()) {
PopularMovieScreenContent(
state = viewModel.state.collectAsState().value,
onNavigateToDetail = { movieId ->
viewModel.onIntent(PopularMovieIntent.NavigateToDetail(movieId))
},
onTryAgain = {
viewModel.onIntent(PopularMovieIntent.GetPopularMovies)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment