Double reader fixes

This commit is contained in:
Koitharu
2024-02-03 16:50:42 +02:00
parent 2d61209696
commit eae40d9b90
2 changed files with 18 additions and 14 deletions

View File

@@ -25,6 +25,10 @@ class DoublePageHolder(
private val isEven: Boolean
get() = bindingAdapterPosition and 1 == 0
init {
binding.ssiv.panLimit = SubsamplingScaleImageView.PAN_LIMIT_INSIDE
}
override fun onBind(data: ReaderPage) {
super.onBind(data)
(binding.textViewNumber.layoutParams as FrameLayout.LayoutParams)
@@ -41,7 +45,7 @@ class DoublePageHolder(
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
setScaleAndCenter(
minScale,
PointF(if (isEven) sWidth.toFloat() else 0f, 0f),
PointF(if (isEven) 0f else sWidth.toFloat(), sHeight / 2f),
)
}
}

View File

@@ -158,7 +158,7 @@ class DoublePageSnapHelper : SnapHelper() {
}
private fun roundDownToBlockSize(trialPosition: Int): Int {
return trialPosition - trialPosition % blockSize
return trialPosition and 1.inv()
}
private fun roundUpToBlockSize(trialPosition: Int): Int {
@@ -197,19 +197,17 @@ class DoublePageSnapHelper : SnapHelper() {
private inner class LayoutDirectionHelper(direction: Int) {
// Is the layout an RTL one?
private val mIsRTL: Boolean
init {
mIsRTL = direction == View.LAYOUT_DIRECTION_RTL
}
private val isRTL = direction == View.LAYOUT_DIRECTION_RTL
/*
Calculate the amount of scroll needed to align the target view with the layout edge.
*/
fun getScrollToAlignView(targetView: View?): Int {
return if (mIsRTL) orientationHelper.getDecoratedEnd(targetView) - recyclerView.width else orientationHelper.getDecoratedStart(
targetView,
)
return if (isRTL) {
orientationHelper.getDecoratedEnd(targetView) - recyclerView.width
} else {
orientationHelper.getDecoratedStart(targetView)
}
}
/**
@@ -225,7 +223,7 @@ class DoublePageSnapHelper : SnapHelper() {
val firstVisiblePos = layoutManager.findFirstVisibleItemPosition()
if (layoutManager.canScrollHorizontally()) {
if (targetPos <= firstVisiblePos) { // scrolling toward top of data
if (mIsRTL) {
if (isRTL) {
val lastView = layoutManager.findViewByPosition(layoutManager.findLastVisibleItemPosition())
out[0] = (orientationHelper.getDecoratedEnd(lastView)
+ (firstVisiblePos - targetPos) * itemDimension)
@@ -263,18 +261,20 @@ class DoublePageSnapHelper : SnapHelper() {
if (scroll < 0) {
positionsToMove *= -1
}
if (mIsRTL) {
if (isRTL) {
positionsToMove *= -1
}
return if (layoutDirectionHelper.isDirectionToBottom(scroll < 0)) {
// Scrolling toward the bottom of data.
roundDownToBlockSize(llm.findFirstVisibleItemPosition()) + positionsToMove
} else roundDownToBlockSize(llm.findLastVisibleItemPosition()) + positionsToMove
} else {
roundDownToBlockSize(llm.findLastVisibleItemPosition()) + positionsToMove
}
// Scrolling toward the top of the data.
}
fun isDirectionToBottom(velocityNegative: Boolean): Boolean {
return if (mIsRTL) velocityNegative else !velocityNegative
return if (isRTL) velocityNegative else !velocityNegative
}
}
}