mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Merge pull request #10224 from TacoTheDank/moreKotlinMath
Replace MathUtils.clamp with Kotlin coerceIn
This commit is contained in:
commit
6859f73c54
@ -38,7 +38,6 @@ import android.view.ViewGroup
|
|||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.core.math.MathUtils
|
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
@ -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
|
// state until the user scrolls them out of the visible area which causes a update/bind-call
|
||||||
groupAdapter.notifyItemRangeChanged(
|
groupAdapter.notifyItemRangeChanged(
|
||||||
0,
|
0,
|
||||||
MathUtils.clamp(highlightCount, lastNewItemsCount, groupAdapter.itemCount)
|
highlightCount.coerceIn(lastNewItemsCount, groupAdapter.itemCount)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (highlightCount > 0) {
|
if (highlightCount > 0) {
|
||||||
|
@ -7,7 +7,6 @@ import android.view.View.OnTouchListener
|
|||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.core.math.MathUtils
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
@ -113,7 +112,7 @@ class MainPlayerGestureListener(
|
|||||||
|
|
||||||
// Update progress bar
|
// Update progress bar
|
||||||
val oldBrightness = layoutParams.screenBrightness
|
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())
|
bar.incrementProgressBy(distanceY.toInt())
|
||||||
|
|
||||||
// Update brightness
|
// Update brightness
|
||||||
|
@ -4,7 +4,7 @@ import android.util.Log
|
|||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewConfiguration
|
import android.view.ViewConfiguration
|
||||||
import androidx.core.math.MathUtils
|
import androidx.core.view.isVisible
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.ktx.AnimationType
|
import org.schabi.newpipe.ktx.AnimationType
|
||||||
import org.schabi.newpipe.ktx.animate
|
import org.schabi.newpipe.ktx.animate
|
||||||
@ -235,14 +235,16 @@ class PopupPlayerGestureListener(
|
|||||||
isMoving = true
|
isMoving = true
|
||||||
|
|
||||||
val diffX = (movingEvent.rawX - initialEvent.rawX)
|
val diffX = (movingEvent.rawX - initialEvent.rawX)
|
||||||
val posX = MathUtils.clamp(
|
val posX = (initialPopupX + diffX).coerceIn(
|
||||||
initialPopupX + diffX,
|
0f,
|
||||||
0f, (playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat()
|
(playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat()
|
||||||
|
.coerceAtLeast(0f)
|
||||||
)
|
)
|
||||||
val diffY = (movingEvent.rawY - initialEvent.rawY)
|
val diffY = (movingEvent.rawY - initialEvent.rawY)
|
||||||
val posY = MathUtils.clamp(
|
val posY = (initialPopupY + diffY).coerceIn(
|
||||||
initialPopupY + diffY,
|
0f,
|
||||||
0f, (playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat()
|
(playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat()
|
||||||
|
.coerceAtLeast(0f)
|
||||||
)
|
)
|
||||||
|
|
||||||
playerUi.popupLayoutParams.x = posX.toInt()
|
playerUi.popupLayoutParams.x = posX.toInt()
|
||||||
@ -251,8 +253,7 @@ class PopupPlayerGestureListener(
|
|||||||
// -- Determine if the ClosingOverlayView (red X) has to be shown or hidden --
|
// -- Determine if the ClosingOverlayView (red X) has to be shown or hidden --
|
||||||
val showClosingOverlayView: Boolean = playerUi.isInsideClosingRadius(movingEvent)
|
val showClosingOverlayView: Boolean = playerUi.isInsideClosingRadius(movingEvent)
|
||||||
// Check if an view is in expected state and if not animate it into the correct state
|
// 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.isVisible != showClosingOverlayView) {
|
||||||
if (binding.closingOverlay.visibility != expectedVisibility) {
|
|
||||||
binding.closingOverlay.animate(showClosingOverlayView, 200)
|
binding.closingOverlay.animate(showClosingOverlayView, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user