From 394eb92e714e4c2f7375aea4bf22afd5a84ba660 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 18 Jul 2022 09:09:18 +0530 Subject: [PATCH] Use coerceIn(). --- .../gesture/PopupPlayerGestureListener.kt | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/gesture/PopupPlayerGestureListener.kt b/app/src/main/java/org/schabi/newpipe/player/gesture/PopupPlayerGestureListener.kt index bda6ee8d1..01b15f30a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/gesture/PopupPlayerGestureListener.kt +++ b/app/src/main/java/org/schabi/newpipe/player/gesture/PopupPlayerGestureListener.kt @@ -233,22 +233,14 @@ class PopupPlayerGestureListener( isMoving = true - val diffX: Float = (movingEvent.rawX - initialEvent.rawX) - var posX: Float = (initialPopupX + diffX) - val diffY: Float = (movingEvent.rawY - initialEvent.rawY) - var posY: Float = (initialPopupY + diffY) - - if (posX > playerUi.screenWidth - playerUi.popupLayoutParams.width) { - posX = (playerUi.screenWidth - playerUi.popupLayoutParams.width).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 - } + val diffX = (movingEvent.rawX - initialEvent.rawX) + val posX = (initialPopupX + diffX).coerceIn( + 0f, (playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat() + ) + val diffY = (movingEvent.rawY - initialEvent.rawY) + val posY = (initialPopupY + diffY).coerceIn( + 0f, (playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat() + ) playerUi.popupLayoutParams.x = posX.toInt() playerUi.popupLayoutParams.y = posY.toInt()