Merge pull request #8747 from Isira-Seneviratne/Range_limit
Use range-limiting methods in more places.
This commit is contained in:
commit
9524c6245d
4 changed files with 11 additions and 13 deletions
|
@ -40,6 +40,7 @@ import androidx.annotation.Nullable
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
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.MenuItemCompat
|
import androidx.core.view.MenuItemCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -603,7 +604,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,
|
||||||
minOf(groupAdapter.itemCount, maxOf(highlightCount, lastNewItemsCount))
|
MathUtils.clamp(highlightCount, lastNewItemsCount, groupAdapter.itemCount)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (highlightCount > 0) {
|
if (highlightCount > 0) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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
|
||||||
|
@ -18,8 +19,6 @@ import org.schabi.newpipe.player.helper.PlayerHelper
|
||||||
import org.schabi.newpipe.player.ui.MainPlayerUi
|
import org.schabi.newpipe.player.ui.MainPlayerUi
|
||||||
import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx
|
import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GestureListener for the player
|
* GestureListener for the player
|
||||||
|
@ -114,7 +113,7 @@ class MainPlayerGestureListener(
|
||||||
|
|
||||||
// Update progress bar
|
// Update progress bar
|
||||||
val oldBrightness = layoutParams.screenBrightness
|
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())
|
bar.incrementProgressBy(distanceY.toInt())
|
||||||
|
|
||||||
// Update brightness
|
// Update brightness
|
||||||
|
|
|
@ -291,7 +291,7 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
||||||
}
|
}
|
||||||
|
|
||||||
final float minimumWidth = context.getResources().getDimension(R.dimen.popup_minimum_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);
|
final int actualHeight = (int) getMinimumVideoHeight(width);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "updatePopupSize() updated values:"
|
Log.d(TAG, "updatePopupSize() updated values:"
|
||||||
|
|
|
@ -100,13 +100,11 @@ object ReleaseVersionUtil {
|
||||||
* @return Epoch second of expiry date time
|
* @return Epoch second of expiry date time
|
||||||
*/
|
*/
|
||||||
fun coerceUpdateCheckExpiry(expiryString: String?): Long {
|
fun coerceUpdateCheckExpiry(expiryString: String?): Long {
|
||||||
val now = ZonedDateTime.now()
|
val nowPlus6Hours = ZonedDateTime.now().plusHours(6)
|
||||||
return expiryString?.let {
|
val expiry = expiryString?.let {
|
||||||
var expiry =
|
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(it))
|
||||||
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(expiryString))
|
.coerceIn(nowPlus6Hours, nowPlus6Hours.plusHours(66))
|
||||||
expiry = maxOf(expiry, now.plusHours(6))
|
} ?: nowPlus6Hours
|
||||||
expiry = minOf(expiry, now.plusHours(72))
|
return expiry.toEpochSecond()
|
||||||
expiry.toEpochSecond()
|
|
||||||
} ?: now.plusHours(6).toEpochSecond()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue