override suspend fun onStateChange()

in azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/presentation/fragment/calling/CallingViewModel.kt [227:427]


    override suspend fun onStateChange(state: ReduxState) {
        if (!state.callState.isDefaultParametersCallStarted &&
            state.localParticipantState.initialCallJoinState.skipSetupScreen &&
            state.permissionState.audioPermissionState == PermissionStatus.GRANTED &&
            !callStartRequested
        ) {
            callStartRequested = true
            store.dispatch(action = CallingAction.CallRequestedWithoutSetup())
        }

        if (state.lifecycleState.state == LifecycleStatus.BACKGROUND) {
            participantGridViewModel.clear()
            localParticipantViewModel.clear()
            return
        }

        val remoteParticipantsForGridView = remoteParticipantsForGridView(state.remoteParticipantState.participantMap)
        val remoteParticipantsInAllStatesCount = state.remoteParticipantState.participantMap.count()
        val hiddenRemoteParticipantsCount = remoteParticipantsInAllStatesCount - remoteParticipantsForGridView.count()
        val totalParticipantCountExceptHidden = state.remoteParticipantState.totalParticipantCount - hiddenRemoteParticipantsCount

        controlBarViewModel.update(
            state.permissionState,
            state.localParticipantState.cameraState,
            state.localParticipantState.audioState,
            state.callState.callingStatus,
            state.visibilityState,
            state.localParticipantState.audioVideoMode,
            state.localParticipantState.capabilities,
            state.buttonState,
            deviceConfigurationState = state.deviceConfigurationState,
        )

        localParticipantViewModel.update(
            state.localParticipantState.displayName,
            state.localParticipantState.audioState.operation,
            state.localParticipantState.videoStreamID,
            remoteParticipantsForGridView.count(),
            state.callState.callingStatus,
            state.localParticipantState.cameraState.device,
            state.localParticipantState.cameraState.camerasCount,
            state.visibilityState.status,
            avMode,
            shouldDisplayLobbyOverlay(state),
        )

        audioDeviceListViewModel.update(
            state.localParticipantState.audioState,
            state.visibilityState
        )

        waitingLobbyOverlayViewModel.update(shouldDisplayLobbyOverlay(state))
        connectingLobbyOverlayViewModel.update(
            state.callState,
            state.localParticipantState.cameraState.operation,
            state.permissionState,
            state.localParticipantState.audioState.operation,
            state.localParticipantState.initialCallJoinState
        )
        holdOverlayViewModel.update(state.callState.callingStatus, state.audioSessionState.audioFocusStatus)

        if (state.callState.callingStatus == CallingStatus.LOCAL_HOLD) {
            participantGridViewModel.update(
                remoteParticipantsMapUpdatedTimestamp = System.currentTimeMillis(),
                remoteParticipantsMap = mapOf(),
                dominantSpeakersInfo = listOf(),
                dominantSpeakersModifiedTimestamp = System.currentTimeMillis(),
                visibilityStatus = state.visibilityState.status,
                rttState = state.rttState,
                isOverlayDisplayedOverGrid = isOverlayDisplayedOverGrid(state),
                deviceConfigurationState = state.deviceConfigurationState,
                captionsState = state.captionsState,
            )
            floatingHeaderViewModel.dismiss()
            lobbyHeaderViewModel.dismiss()
            lobbyErrorHeaderViewModel.dismiss()
            participantListViewModel.closeParticipantList()
            localParticipantViewModel.update(
                state.localParticipantState.displayName,
                state.localParticipantState.audioState.operation,
                state.localParticipantState.videoStreamID,
                0,
                state.callState.callingStatus,
                state.localParticipantState.cameraState.device,
                state.localParticipantState.cameraState.camerasCount,
                state.visibilityState.status,
                avMode,
                shouldDisplayLobbyOverlay(state),
            )
        }

        if (shouldUpdateRemoteParticipantsViewModels(state)) {
            participantGridViewModel.update(
                remoteParticipantsMapUpdatedTimestamp = state.remoteParticipantState.participantMapModifiedTimestamp,
                remoteParticipantsMap = remoteParticipantsForGridView,
                dominantSpeakersInfo = state.remoteParticipantState.dominantSpeakersInfo,
                dominantSpeakersModifiedTimestamp = state.remoteParticipantState.dominantSpeakersModifiedTimestamp,
                visibilityStatus = state.visibilityState.status,
                rttState = state.rttState,
                isOverlayDisplayedOverGrid = isOverlayDisplayedOverGrid(state),
                deviceConfigurationState = state.deviceConfigurationState,
                captionsState = state.captionsState,
            )

            floatingHeaderViewModel.update(
                totalParticipantCountExceptHidden,
                state.callScreenInfoHeaderState,
                state.buttonState,
                isOverlayDisplayedOverGrid(state),
                /* <CALL_START_TIME>
                state.callState.callStartTime,
                </CALL_START_TIME> */
                state.visibilityState.status,
            )

            lobbyHeaderViewModel.update(
                state.callState.callingStatus,
                getLobbyParticipantsForHeader(state),
                shouldShowLobby(
                    state.localParticipantState.capabilities,
                    state.visibilityState
                )
            )

            lobbyErrorHeaderViewModel.update(
                state.callState.callingStatus,
                state.remoteParticipantState.lobbyErrorCode,
                shouldShowLobby(
                    state.localParticipantState.capabilities,
                    state.visibilityState
                )
            )

            upperMessageBarNotificationLayoutViewModel.update(
                state.callDiagnosticsState
            )

            toastNotificationViewModel.update(
                state.toastNotificationState
            )

            participantMenuViewModel.update(
                state.localParticipantState.capabilities,
            )

            participantListViewModel.update(
                state.remoteParticipantState.participantMap,
                state.localParticipantState,
                state.visibilityState,
                shouldShowLobby(
                    state.localParticipantState.capabilities,
                    state.visibilityState
                ),
                totalParticipantCountExceptHidden
            )

            bannerViewModel.update(
                state.callState,
                state.visibilityState,
                isOverlayDisplayedOverGrid(state),
            )
        }

        confirmLeaveOverlayViewModel.update(state.visibilityState)
        moreCallOptionsListViewModel.update(
            state.visibilityState,
            state.buttonState,
            state.navigationState
        )

        state.localParticipantState.cameraState.error?.let {
            errorInfoViewModel.updateCallCompositeError(it)
        }

        captionsListViewModel.update(
            state.captionsState,
            state.callState.callingStatus,
            state.visibilityState,
            state.buttonState,
            state.rttState,
            state.navigationState,
        )
        captionsLanguageSelectionListViewModel.update(
            state.captionsState,
            state.visibilityState,
            state.navigationState
        )

        isCaptionsVisibleMutableFlow.value = shouldShowCaptionsUI(
            state.visibilityState,
            state.captionsState.status,
            state.rttState,
        )
        captionsLayoutViewModel.update(
            captionsState = state.captionsState,
            rttState = state.rttState,
            isVisible = isCaptionsVisibleMutableFlow.value,
            deviceConfigurationState = state.deviceConfigurationState,
        )
        isCaptionsMaximized = state.rttState.isMaximized
    }