Last active
June 16, 2025 06:10
-
-
Save mahesaiqbal/5144803670b9f974c85b7c0d0cbfbac2 to your computer and use it in GitHub Desktop.
Explaining about MVI Architecture
This file contains hidden or 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
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