fix(reader): Prevent potential NPE

This commit is contained in:
Ahmad Ansori Palembani 2024-12-08 06:47:02 +07:00
parent 8bc22fec28
commit a4ab7f11e2
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -301,34 +301,31 @@ class PagerPageHolder(
private fun SubsamplingScaleImageView.landscapeZoom(forward: Boolean?) { private fun SubsamplingScaleImageView.landscapeZoom(forward: Boolean?) {
forward ?: return forward ?: return
if (viewer.config.landscapeZoom && viewer.config.imageScaleType == SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE && sWidth > sHeight && scale == minScale) { if (viewer.config.landscapeZoom && viewer.config.imageScaleType == SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE && sWidth > sHeight && scale == minScale) {
handler.postDelayed( handler.postDelayed(500) {
{ val point = when (viewer.config.imageZoomType) {
val point = when (viewer.config.imageZoomType) { ZoomType.Left -> if (forward) PointF(0F, 0F) else PointF(sWidth.toFloat(), 0F)
ZoomType.Left -> if (forward) PointF(0F, 0F) else PointF(sWidth.toFloat(), 0F) ZoomType.Right -> if (forward) PointF(sWidth.toFloat(), 0F) else PointF(0F, 0F)
ZoomType.Right -> if (forward) PointF(sWidth.toFloat(), 0F) else PointF(0F, 0F) ZoomType.Center -> center.also { it?.y = 0F }
ZoomType.Center -> center.also { it?.y = 0F } }
}
val rootInsets = viewer.activity.window.decorView.rootWindowInsets val rootInsets = viewer.activity.window.decorView.rootWindowInsets
val topInsets = if (viewer.activity.isSplitScreen) { val topInsets = if (viewer.activity.isSplitScreen) {
0f 0f
} else { } else {
rootInsets?.topCutoutInset()?.toFloat() ?: 0f rootInsets?.topCutoutInset()?.toFloat() ?: 0f
} }
val bottomInsets = if (viewer.activity.isSplitScreen) { val bottomInsets = if (viewer.activity.isSplitScreen) {
0f 0f
} else { } else {
rootInsets?.bottomCutoutInset()?.toFloat() ?: 0f rootInsets?.bottomCutoutInset()?.toFloat() ?: 0f
} }
val targetScale = (height.toFloat() - topInsets - bottomInsets) / sHeight.toFloat() val targetScale = (height.toFloat() - topInsets - bottomInsets) / sHeight.toFloat()
animateScaleAndCenter(min(targetScale, minScale * 2), point)!! (animateScaleAndCenter(min(targetScale, minScale * 2), point) ?: return@postDelayed)
.withDuration(500) .withDuration(500)
.withEasing(SubsamplingScaleImageView.EASE_IN_OUT_QUAD) .withEasing(SubsamplingScaleImageView.EASE_IN_OUT_QUAD)
.withInterruptible(true) .withInterruptible(true)
.start() .start()
}, }
500,
)
} }
} }