override fun onTouch()

in azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/presentation/fragment/calling/captions/CaptionsRttView.kt [361:411]


        override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
            return when (motionEvent.action) {
                MotionEvent.ACTION_DOWN -> {
                    initialMarginTop = view.marginTop
                    initialTouchY = motionEvent.rawY

                    if (viewModel.isMaximizedFlow.value) {
                        maximizedHeight = view.height
                    }
                    true
                }

                MotionEvent.ACTION_MOVE -> {
                    val deltaY = motionEvent.rawY - initialTouchY

                    var newMarginTop = (deltaY + initialMarginTop).toInt()
                    if (viewModel.isMaximizedFlow.value) {
                        if (minHeight > maximizedHeight - newMarginTop) {
                            newMarginTop = maximizedHeight - minHeight
                        }
                        newMarginTop = max(0, newMarginTop)
                    } else {
                        if (-newMarginTop + minHeight > maxHeight) {
                            newMarginTop = -(maxHeight - minHeight)
                        }
                        newMarginTop = min(0, newMarginTop)
                    }

                    val layoutParams = view.layoutParams as MarginLayoutParams
                    layoutParams.topMargin = newMarginTop
                    view.layoutParams = layoutParams
                    true
                }
                MotionEvent.ACTION_UP -> {
                    val params = view.layoutParams as MarginLayoutParams

                    if (abs(params.topMargin) > RESIZE_DRAG_RELEASE_THRESHOLD) {
                        if (viewModel.isMaximizedFlow.value) {
                            viewModel.minimizeCaptionsLayout()
                        } else {
                            viewModel.maximizeCaptionsLayout()
                        }
                    }

                    params.topMargin = 0
                    view.layoutParams = params
                    true
                }
                else -> false
            }
        }