Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace MathUtils.clamp with Kotlin coerceIn #10224

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import android.view.ViewGroup
import android.widget.Button
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.core.math.MathUtils
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -589,7 +588,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
// state until the user scrolls them out of the visible area which causes a update/bind-call
groupAdapter.notifyItemRangeChanged(
0,
MathUtils.clamp(highlightCount, lastNewItemsCount, groupAdapter.itemCount)
highlightCount.coerceIn(lastNewItemsCount, groupAdapter.itemCount)
)

if (highlightCount > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.view.View.OnTouchListener
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.math.MathUtils
import androidx.core.view.isVisible
import org.schabi.newpipe.MainActivity
import org.schabi.newpipe.R
Expand Down Expand Up @@ -113,7 +112,7 @@ class MainPlayerGestureListener(

// Update progress bar
val oldBrightness = layoutParams.screenBrightness
bar.progress = (bar.max * MathUtils.clamp(oldBrightness, 0f, 1f)).toInt()
bar.progress = (bar.max * oldBrightness.coerceIn(0f, 1f)).toInt()
bar.incrementProgressBy(distanceY.toInt())

// Update brightness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.view.ViewConfiguration
import androidx.core.math.MathUtils
import androidx.core.view.isVisible
import org.schabi.newpipe.MainActivity
import org.schabi.newpipe.ktx.AnimationType
import org.schabi.newpipe.ktx.animate
Expand Down Expand Up @@ -235,14 +235,16 @@ class PopupPlayerGestureListener(
isMoving = true

val diffX = (movingEvent.rawX - initialEvent.rawX)
val posX = MathUtils.clamp(
initialPopupX + diffX,
0f, (playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat()
val posX = (initialPopupX + diffX).coerceIn(
0f,
(playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat()
.coerceAtLeast(0f)
)
val diffY = (movingEvent.rawY - initialEvent.rawY)
val posY = MathUtils.clamp(
initialPopupY + diffY,
0f, (playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat()
val posY = (initialPopupY + diffY).coerceIn(
0f,
(playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat()
.coerceAtLeast(0f)
)

playerUi.popupLayoutParams.x = posX.toInt()
Expand All @@ -251,8 +253,7 @@ class PopupPlayerGestureListener(
// -- Determine if the ClosingOverlayView (red X) has to be shown or hidden --
val showClosingOverlayView: Boolean = playerUi.isInsideClosingRadius(movingEvent)
// Check if an view is in expected state and if not animate it into the correct state
val expectedVisibility = if (showClosingOverlayView) View.VISIBLE else View.GONE
if (binding.closingOverlay.visibility != expectedVisibility) {
if (binding.closingOverlay.isVisible != showClosingOverlayView) {
binding.closingOverlay.animate(showClosingOverlayView, 200)
}

Expand Down