Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Forked from Aldikitta/ViewModel.kt
Created June 18, 2023 13:16
Show Gist options
  • Save virendersran01/f5ba913ee65c5c9caf10b9075ce02930 to your computer and use it in GitHub Desktop.
Save virendersran01/f5ba913ee65c5c9caf10b9075ce02930 to your computer and use it in GitHub Desktop.
fun getAgentVisitDetailFullResponseFlow() {
val visitId = savedStateHandle.get<Int>("visitId")
viewModelScope.launch {
if (visitId != null) {
useCase.getDetailAgentVisitFullResponseFlow(id = visitId)
.collectLatest { visitDetail ->
when (visitDetail) {
is SallyResponseResource.Loading -> {
_uiStateDetail.value = VisitingDetailUiState.Loading
}
is SallyResponseResource.Success -> {
_uiStateDetail.value =
VisitingDetailUiState.Success(visitDetail.data.data)
}
is SallyResponseResource.Error -> {
_eventFlow.emit(
VisitingUiEvent.ShowErrorMessageStatic(
staticError = visitDetail.exception.message,
dynamicError = visitDetail.exception.cause?.message.toString(),
errorCode = visitDetail.errorCode
)
)
_uiStateDetail.value =
VisitingDetailUiState.Error(error = visitDetail.exception.toString())
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment