Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Forked from Aldikitta/Fragment.kt
Created June 18, 2023 13:12
Show Gist options
  • Save virendersran01/2c4229661096631ef965a7dc706f822f to your computer and use it in GitHub Desktop.
Save virendersran01/2c4229661096631ef965a7dc706f822f to your computer and use it in GitHub Desktop.
override fun onViewCreated() {
observeVisitDetail()
}
private fun observeVisitDetail() {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.agentDetail?.collect { visitingUiState ->
when (visitingUiState) {
is VisitingDetailUiState.Success -> {
// HANDLE SUCCESS EVENT
}
is VisitingDetailUiState.Error -> {
viewModel.eventFlow.collectLatest {
when (it) {
is VisitingUiEvent.ShowErrorMessageStatic -> {
Timber.tag("MYTAG")
.d("observeVisitDetail: %s", it.staticError)
Timber.tag("MYTAG")
.d("observeVisitDetail: %s", it.dynamicError)
Timber.tag("MYTAG")
.d("observeVisitDetail: %s", it.errorCode)
}
}
}
}
is VisitingDetailUiState.Loading -> {
// HANDLE LOADING EVENT
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment