Use coerceIn().
This commit is contained in:
parent
d62cdc659f
commit
394eb92e71
1 changed files with 8 additions and 16 deletions
|
@ -233,22 +233,14 @@ class PopupPlayerGestureListener(
|
||||||
|
|
||||||
isMoving = true
|
isMoving = true
|
||||||
|
|
||||||
val diffX: Float = (movingEvent.rawX - initialEvent.rawX)
|
val diffX = (movingEvent.rawX - initialEvent.rawX)
|
||||||
var posX: Float = (initialPopupX + diffX)
|
val posX = (initialPopupX + diffX).coerceIn(
|
||||||
val diffY: Float = (movingEvent.rawY - initialEvent.rawY)
|
0f, (playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat()
|
||||||
var posY: Float = (initialPopupY + diffY)
|
)
|
||||||
|
val diffY = (movingEvent.rawY - initialEvent.rawY)
|
||||||
if (posX > playerUi.screenWidth - playerUi.popupLayoutParams.width) {
|
val posY = (initialPopupY + diffY).coerceIn(
|
||||||
posX = (playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat()
|
0f, (playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat()
|
||||||
} else if (posX < 0) {
|
)
|
||||||
posX = 0f
|
|
||||||
}
|
|
||||||
|
|
||||||
if (posY > playerUi.screenHeight - playerUi.popupLayoutParams.height) {
|
|
||||||
posY = (playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat()
|
|
||||||
} else if (posY < 0) {
|
|
||||||
posY = 0f
|
|
||||||
}
|
|
||||||
|
|
||||||
playerUi.popupLayoutParams.x = posX.toInt()
|
playerUi.popupLayoutParams.x = posX.toInt()
|
||||||
playerUi.popupLayoutParams.y = posY.toInt()
|
playerUi.popupLayoutParams.y = posY.toInt()
|
||||||
|
|
Loading…
Reference in a new issue