in azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/presentation/fragment/calling/participant/grid/ParticipantGridView.kt [65:190]
fun start(
participantGridViewModel: ParticipantGridViewModel,
videoViewManager: VideoViewManager,
viewLifecycleOwner: LifecycleOwner,
showFloatingHeader: () -> Unit,
avatarViewManager: AvatarViewManager,
) {
accessibilityManager =
context?.applicationContext?.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
if (accessibilityManager.isEnabled) {
ViewCompat.setAccessibilityDelegate(
this,
object : AccessibilityDelegateCompat() {
override fun onInitializeAccessibilityNodeInfo(
host: View,
info: AccessibilityNodeInfoCompat,
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info.removeAction(AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK)
info.isClickable = false
}
}
)
}
this.videoViewManager = videoViewManager
this.viewLifecycleOwner = viewLifecycleOwner
this.participantGridViewModel = participantGridViewModel
this.showFloatingHeaderCallBack = showFloatingHeader
this.getVideoStreamCallback = { participantID: String, videoStreamID: String ->
this.videoViewManager.getRemoteVideoStreamRenderer(
participantID,
videoStreamID
)
}
this.getScreenShareVideoStreamRendererCallback = {
this.videoViewManager.getScreenShareVideoStreamRenderer()
}
this.participantGridViewModel.setUpdateVideoStreamsCallback { users: List<Pair<String, String>> ->
this.videoViewManager.removeRemoteParticipantVideoRenderer(users)
}
this.getParticipantViewDataCallback = { participantID: String ->
avatarViewManager.getRemoteParticipantViewData(participantID)
}
viewLifecycleOwner.lifecycleScope.launch {
avatarViewManager.getRemoteParticipantsPersonaSharedFlow()
.collect { remoteParticipantViewData ->
if (::displayedRemoteParticipantsView.isInitialized && displayedRemoteParticipantsView.isNotEmpty()) {
displayedRemoteParticipantsView.forEach { displayedParticipant ->
val identifier = displayedParticipant.getParticipantIdentifier()
if (remoteParticipantViewData.keys.contains(identifier)) {
displayedParticipant.updateParticipantViewData()
}
}
}
}
}
viewLifecycleOwner.lifecycleScope.launch {
participantGridViewModel.getRemoteParticipantsUpdateStateFlow().collect {
post {
updateGrid(it)
}
}
}
viewLifecycleOwner.lifecycleScope.launch {
participantGridViewModel.getIsOverlayDisplayedFlow().collect {
if (it) {
ViewCompat.setImportantForAccessibility(
gridView,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
)
} else {
ViewCompat.setImportantForAccessibility(
gridView,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES
)
}
}
}
addOnLayoutChangeListener(object : OnLayoutChangeListener {
override fun onLayoutChange(
v: View,
left: Int,
top: Int,
right: Int,
bottom: Int,
oldLeft: Int,
oldTop: Int,
oldRight: Int,
oldBottom: Int,
) {
if (isLaidOut) {
removeOnLayoutChangeListener(this)
post {
updateGrid(participantGridViewModel.getRemoteParticipantsUpdateStateFlow().value)
}
}
}
})
addOnLayoutChangeListener { _, left, top, right, bottom,
oldLeft, oldTop, oldRight, oldBottom ->
if (left != oldLeft ||
right != oldRight ||
top != oldTop ||
bottom != oldBottom
) {
// The playerView's bounds changed, update the source hint rect to
// reflect its new bounds.
val sourceRectHint = Rect()
getGlobalVisibleRect(sourceRectHint)
}
}
viewLifecycleOwner.lifecycleScope.launch {
participantGridViewModel.participantUpdated.events.collect { updateContentDescription() }
}
}