This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Composable | |
| Fun stateFullScreen(){ | |
| // lets say we done handle our viewmodels | |
| Val uiState by viewmodel.uiState.collectWithLifeCycle() | |
| LaunchedEffect() { | |
| viewmodel.getAgentVisitDetailFullResponse() | |
| } | |
| stateLessScreen( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun onViewCreated() { | |
| viewModel.getAgentVisitDetailFullResponse() | |
| observeVisitDetail() | |
| } | |
| private fun observeVisitDetail() { | |
| viewLifecycleOwner.lifecycleScope.launch { | |
| viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { | |
| viewModel.uiStateDetail.collect { visitingUiState -> | |
| when (visitingUiState) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun getAgentVisitDetailFullResponse() { | |
| val visitId = savedStateHandle.get<Int>("visitId") | |
| viewModelScope.launch { | |
| val visitDetail = visitId?.let { useCase.getDetailAgentVisitWithFullResponse(id = it) } | |
| when (visitDetail) { | |
| is SallyResponseResource.Loading -> { | |
| _uiStateDetail.value = VisitingDetailUiState.Loading | |
| } | |
| is SallyResponseResource.Success -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val _uiStateDetail = | |
| MutableStateFlow<VisitingDetailUiState>(VisitingDetailUiState.Loading) | |
| val uiStateDetail = _uiStateDetail.asStateFlow() | |
| private val _eventFlow = MutableSharedFlow<VisitingUiEvent>(replay = 1) | |
| val eventFlow = _eventFlow.asSharedFlow() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sealed interface VisitingDetailUiState { | |
| object Loading : VisitingDetailUiState | |
| data class Error(val error: String) : VisitingDetailUiState | |
| data class Success( | |
| val agentVisitingDetail: GetAgentDetailResponse? = null | |
| ) : VisitingDetailUiState | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sealed interface VisitingUiEvent { | |
| data class ShowErrorMessageStatic( | |
| val staticError: String?, | |
| val dynamicError: String?, | |
| val errorCode: String? | |
| ) : VisitingUiEvent | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override suspend fun getDetailAgentVisitWithFullResponse(id: Int): SallyResponseResource<BaseResponse<GetAgentDetailResponse>> { | |
| return iAgentVisitRepository.getDetailAgentVisitWithFullResponse(id) | |
| } | |
| override fun getDetailAgentVisitFullResponseFlow(id: Int): Flow<SallyResponseResource<BaseResponse<GetAgentDetailResponse>>> { | |
| return iAgentVisitRepository.getDetailAgentVisitFullResponseFlow(id) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun getDetailAgentVisitFullResponseFlow(id: Int): Flow<SallyResponseResource<BaseResponse<GetAgentDetailResponse>>> { | |
| return agentVisitDataSource.getDetailAgentVisitFullResponseFlow( | |
| token = "", | |
| id = id | |
| ).asSallyResponseResourceFlow() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override suspend fun getDetailAgentVisitWithFullResponse(id: Int): SallyResponseResource<BaseResponse<GetAgentDetailResponse>> { | |
| return agentVisitDataSource.getDetailAgentVisitFullResponse( | |
| token = "", | |
| id = id | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun getDetailAgentVisitFullResponseFlow( | |
| token: String, | |
| id: Int | |
| ): Flow<BaseResponse<GetAgentDetailResponse>> { | |
| return flow { | |
| while (true) { | |
| val getDetailAgent = agentVisitService.getDetailAgentVisitWithFullResponse( | |
| token = token, | |
| id = id | |
| ) |