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

Use range-limiting methods in more places. #8747

Merged
merged 1 commit into from
Oct 28, 2022
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 @@ -40,6 +40,7 @@ import androidx.annotation.Nullable
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources
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 @@ -584,7 +585,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,
minOf(groupAdapter.itemCount, maxOf(highlightCount, lastNewItemsCount))
MathUtils.clamp(highlightCount, lastNewItemsCount, groupAdapter.itemCount)
)

if (highlightCount > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 All @@ -18,8 +19,6 @@ import org.schabi.newpipe.player.helper.PlayerHelper
import org.schabi.newpipe.player.ui.MainPlayerUi
import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

/**
* GestureListener for the player
Expand Down Expand Up @@ -114,7 +113,7 @@ class MainPlayerGestureListener(

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

// Update brightness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void changePopupSize(final int width) {
}

final float minimumWidth = context.getResources().getDimension(R.dimen.popup_minimum_width);
final int actualWidth = Math.min((int) Math.max(width, minimumWidth), screenWidth);
final int actualWidth = MathUtils.clamp(width, (int) minimumWidth, screenWidth);
final int actualHeight = (int) getMinimumVideoHeight(width);
if (DEBUG) {
Log.d(TAG, "updatePopupSize() updated values:"
Expand Down
14 changes: 6 additions & 8 deletions app/src/main/java/org/schabi/newpipe/util/ReleaseVersionUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ object ReleaseVersionUtil {
* @return Epoch second of expiry date time
*/
fun coerceUpdateCheckExpiry(expiryString: String?): Long {
val now = ZonedDateTime.now()
return expiryString?.let {
var expiry =
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(expiryString))
expiry = maxOf(expiry, now.plusHours(6))
expiry = minOf(expiry, now.plusHours(72))
expiry.toEpochSecond()
} ?: now.plusHours(6).toEpochSecond()
val nowPlus6Hours = ZonedDateTime.now().plusHours(6)
val expiry = expiryString?.let {
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(it))
.coerceIn(nowPlus6Hours, nowPlus6Hours.plusHours(66))
} ?: nowPlus6Hours
return expiry.toEpochSecond()
}
}