Skip to content

Commit e136a6f

Browse files
Use range-limiting methods in more places.
1 parent 74921d3 commit e136a6f

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import androidx.annotation.Nullable
4040
import androidx.appcompat.app.AlertDialog
4141
import androidx.appcompat.content.res.AppCompatResources
4242
import androidx.core.content.edit
43+
import androidx.core.math.MathUtils
4344
import androidx.core.os.bundleOf
4445
import androidx.core.view.isVisible
4546
import androidx.lifecycle.ViewModelProvider
@@ -584,7 +585,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
584585
// state until the user scrolls them out of the visible area which causes a update/bind-call
585586
groupAdapter.notifyItemRangeChanged(
586587
0,
587-
minOf(groupAdapter.itemCount, maxOf(highlightCount, lastNewItemsCount))
588+
MathUtils.clamp(highlightCount, lastNewItemsCount, groupAdapter.itemCount)
588589
)
589590

590591
if (highlightCount > 0) {

app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.view.View.OnTouchListener
77
import android.widget.ProgressBar
88
import androidx.appcompat.app.AppCompatActivity
99
import androidx.appcompat.content.res.AppCompatResources
10+
import androidx.core.math.MathUtils
1011
import androidx.core.view.isVisible
1112
import org.schabi.newpipe.MainActivity
1213
import org.schabi.newpipe.R
@@ -18,8 +19,6 @@ import org.schabi.newpipe.player.helper.PlayerHelper
1819
import org.schabi.newpipe.player.ui.MainPlayerUi
1920
import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx
2021
import kotlin.math.abs
21-
import kotlin.math.max
22-
import kotlin.math.min
2322

2423
/**
2524
* GestureListener for the player
@@ -114,7 +113,7 @@ class MainPlayerGestureListener(
114113

115114
// Update progress bar
116115
val oldBrightness = layoutParams.screenBrightness
117-
bar.progress = (bar.max * max(0f, min(1f, oldBrightness))).toInt()
116+
bar.progress = (bar.max * MathUtils.clamp(oldBrightness, 0f, 1f)).toInt()
118117
bar.incrementProgressBy(distanceY.toInt())
119118

120119
// Update brightness

app/src/main/java/org/schabi/newpipe/player/ui/PopupPlayerUi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public void changePopupSize(final int width) {
291291
}
292292

293293
final float minimumWidth = context.getResources().getDimension(R.dimen.popup_minimum_width);
294-
final int actualWidth = Math.min((int) Math.max(width, minimumWidth), screenWidth);
294+
final int actualWidth = MathUtils.clamp(width, (int) minimumWidth, screenWidth);
295295
final int actualHeight = (int) getMinimumVideoHeight(width);
296296
if (DEBUG) {
297297
Log.d(TAG, "updatePopupSize() updated values:"

app/src/main/java/org/schabi/newpipe/util/ReleaseVersionUtil.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,11 @@ object ReleaseVersionUtil {
100100
* @return Epoch second of expiry date time
101101
*/
102102
fun coerceUpdateCheckExpiry(expiryString: String?): Long {
103-
val now = ZonedDateTime.now()
104-
return expiryString?.let {
105-
var expiry =
106-
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(expiryString))
107-
expiry = maxOf(expiry, now.plusHours(6))
108-
expiry = minOf(expiry, now.plusHours(72))
109-
expiry.toEpochSecond()
110-
} ?: now.plusHours(6).toEpochSecond()
103+
val nowPlus6Hours = ZonedDateTime.now().plusHours(6)
104+
val expiry = expiryString?.let {
105+
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(it))
106+
.coerceIn(nowPlus6Hours, nowPlus6Hours.plusHours(66))
107+
} ?: nowPlus6Hours
108+
return expiry.toEpochSecond()
111109
}
112110
}

0 commit comments

Comments
 (0)