Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Forked from Aldikitta/ViewModel.kt
Created June 18, 2023 13:13
Show Gist options
  • Save virendersran01/4e7aaba1df8d7e696b53b3b897e4e550 to your computer and use it in GitHub Desktop.
Save virendersran01/4e7aaba1df8d7e696b53b3b897e4e550 to your computer and use it in GitHub Desktop.
val visitId = savedStateHandle.get<Int>("visitId")
val agentDetail: StateFlow<VisitingDetailUiState>? =
visitId?.let {
useCase.getDetailAgentVisitFullResponseFlow(id = it).map { visitDetail ->
Log.d("MYTAG", ": got exec")
when (visitDetail) {
is SallyResponseResource.Loading -> {
VisitingDetailUiState.Loading
}
is SallyResponseResource.Success -> {
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
)
)
VisitingDetailUiState.Error(error = visitDetail.exception.toString())
}
}
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5_000),
VisitingDetailUiState.Loading
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment