I'm fairly new to Jetpack Compose. Currently, I have a ViewModel making 1 network call.
class PlatformViewModel @Inject constructor(
private val getProductListUseCase: GetListUseCase
) : ViewModel()
I had 3 states.
sealed class PlatformState {
object Loading : PlatformState()
data class Success(val listOfProducts: List<Product>) : PlatformState()
object Error : PlatformState()
}
In the UI, it Was easy to handle observing 1 live data.
val state = viewModel.platformState.observeAsState(PlatformState.Loading)
when (state) {
is PlatformState.Success -> SuccessView(listOfProducts = state.listOfProducts)
is PlatformState.Loading -> LoadingView()
is PlatformState.Error -> ErrorView()
}
now, I need to add 1 more network call in viewModel for the same screen
class PlatformViewModel @Inject constructor(
private val getProductListUseCase: GetListUseCase,
private val getHeaderUseCase: GetHeaderUseCase,
) : ViewModel()
-Should I add 3 more states and 1 more live data to observe for the UI, what is the best way to handle this?
Note: both network calls are unrelated but their result populates the same composable.
fun bodyContent(listOfProducts:List<Products>,headerDetails:HeaderDetails){
LazyColumn{
item{ HeaderDetails(details=headerDetails)}
items(listOfProducts.size){
ProductItem()
}