Marco
05/21/2021, 8:10 AMprivate val _uiState: MutableStateFlow<UiState> = MutableStateFlow(State.loading())
val uiState: StateFlow<UiState> = _uiState
init {
viewModelScope.launch {
repository.getData()
.map { resource ->
Log.d("VM", "got $resource")
State.fromResource(resource)
}
.collect { state -> _uiState.value = state }
}
}
or
val uiState = repository.getData()
.map { resource ->
Log.d("VM", "got $resource")
State.fromResource(resource)
}
.stateIn(
scope = viewModelScope,
started = WhileSubscribed(5000),
initialValue = State.loading()
)
And calling them from the activity
val state by viewModel.uiState.collectAsState()
I am also noticing some heavy delay when the api is executed:
I/Choreographer: Skipped 136 frames! The application may be doing too much work on its main thread.
Adam Powell
05/21/2021, 1:22 PMAdam Powell
05/21/2021, 1:23 PM