diff --git a/app/build.gradle b/app/build.gradle index 01ca59663..26acce2d3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -124,7 +124,7 @@ dependencies { implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' //androidX - implementation 'androidx.core:core-ktx:1.3.0' + implementation 'androidx.core:core-ktx:1.3.1' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.media:media:1.1.0' implementation 'androidx.preference:preference:1.1.1' diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index fadb9ff53..beb9e3673 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -22,6 +22,7 @@ data class TextPage( fun upLinesPosition() = ChapterProvider.apply { if (!ReadBookConfig.textBottomJustify) return@apply if (textLines.size <= 1) return@apply + if (textLines.last().isImage) return@apply if (visibleHeight - height >= with(textLines.last()) { lineBottom - lineTop }) return@apply val surplus = (visibleBottom - textLines.last().lineBottom) if (surplus == 0f) return@apply diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index c812da0e5..969d4830e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -17,6 +17,7 @@ import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.* +import java.util.* import java.util.regex.Pattern @@ -122,9 +123,13 @@ object ChapterProvider { ): Float { var durY = y ImageProvider.getImage(book, chapter.index, src)?.let { + if (durY > visibleHeight) { + textPages.add(TextPage()) + durY = 0f + } var height = it.height var width = it.width - when (imageStyle?.toUpperCase()) { + when (imageStyle?.toUpperCase(Locale.ROOT)) { "FULL" -> { width = visibleWidth height = it.height * visibleWidth / it.width diff --git a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt index e1cca4515..abfc81989 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt @@ -200,7 +200,7 @@ class PhotoView : ImageView { override fun setImageResource(resId: Int) { var drawable: Drawable? = null try { - drawable = resources.getDrawable(resId) + drawable = resources.getDrawable(resId, null) } catch (e: Exception) { } setImageDrawable(drawable) @@ -402,8 +402,8 @@ class PhotoView : ImageView { val pHeight = MeasureSpec.getSize(heightMeasureSpec) val widthMode = MeasureSpec.getMode(widthMeasureSpec) val heightMode = MeasureSpec.getMode(heightMeasureSpec) - var width = 0 - var height = 0 + var width: Int + var height: Int var p = layoutParams if (p == null) { p = ViewGroup.LayoutParams( @@ -703,47 +703,47 @@ class PhotoView : ImageView { distanceX: Float, distanceY: Float ): Boolean { - var distanceX = distanceX - var distanceY = distanceY + var x = distanceX + var y = distanceY if (mTranslate.isRunning) { mTranslate.stop() } - if (canScrollHorizontallySelf(distanceX)) { - if (distanceX < 0 && mImgRect.left - distanceX > mWidgetRect.left) distanceX = - mImgRect.left - if (distanceX > 0 && mImgRect.right - distanceX < mWidgetRect.right) distanceX = - mImgRect.right - mWidgetRect.right - mAnimMatrix.postTranslate(-distanceX, 0f) - mTranslateX -= distanceX.toInt() + if (canScrollHorizontallySelf(x)) { + if (x < 0 && mImgRect.left - x > mWidgetRect.left) + x = mImgRect.left + if (x > 0 && mImgRect.right - x < mWidgetRect.right) + x = mImgRect.right - mWidgetRect.right + mAnimMatrix.postTranslate(-x, 0f) + mTranslateX -= x.toInt() } else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) { checkRect() if (!hasMultiTouch) { - if (distanceX < 0 && mImgRect.left - distanceX > mCommonRect.left) distanceX = - resistanceScrollByX(mImgRect.left - mCommonRect.left, distanceX) - if (distanceX > 0 && mImgRect.right - distanceX < mCommonRect.right) distanceX = - resistanceScrollByX(mImgRect.right - mCommonRect.right, distanceX) + if (x < 0 && mImgRect.left - x > mCommonRect.left) x = + resistanceScrollByX(mImgRect.left - mCommonRect.left, x) + if (x > 0 && mImgRect.right - x < mCommonRect.right) x = + resistanceScrollByX(mImgRect.right - mCommonRect.right, x) } - mTranslateX -= distanceX.toInt() - mAnimMatrix.postTranslate(-distanceX, 0f) + mTranslateX -= x.toInt() + mAnimMatrix.postTranslate(-x, 0f) hasOverTranslate = true } - if (canScrollVerticallySelf(distanceY)) { - if (distanceY < 0 && mImgRect.top - distanceY > mWidgetRect.top) distanceY = + if (canScrollVerticallySelf(y)) { + if (y < 0 && mImgRect.top - y > mWidgetRect.top) y = mImgRect.top - if (distanceY > 0 && mImgRect.bottom - distanceY < mWidgetRect.bottom) distanceY = + if (y > 0 && mImgRect.bottom - y < mWidgetRect.bottom) y = mImgRect.bottom - mWidgetRect.bottom - mAnimMatrix.postTranslate(0f, -distanceY) - mTranslateY -= distanceY.toInt() + mAnimMatrix.postTranslate(0f, -y) + mTranslateY -= y.toInt() } else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) { checkRect() if (!hasMultiTouch) { - if (distanceY < 0 && mImgRect.top - distanceY > mCommonRect.top) distanceY = - resistanceScrollByY(mImgRect.top - mCommonRect.top, distanceY) - if (distanceY > 0 && mImgRect.bottom - distanceY < mCommonRect.bottom) distanceY = - resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, distanceY) + if (y < 0 && mImgRect.top - y > mCommonRect.top) y = + resistanceScrollByY(mImgRect.top - mCommonRect.top, y) + if (y > 0 && mImgRect.bottom - y < mCommonRect.bottom) y = + resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, y) } - mAnimMatrix.postTranslate(0f, -distanceY) - mTranslateY -= distanceY.toInt() + mAnimMatrix.postTranslate(0f, -y) + mTranslateY -= y.toInt() hasOverTranslate = true } executeTranslate() @@ -757,8 +757,8 @@ class PhotoView : ImageView { override fun onDoubleTap(e: MotionEvent): Boolean { mTranslate.stop() - var from = 1f - var to = 1f + val from: Float + val to: Float val imgCx = mImgRect.left + mImgRect.width() / 2 val imgCy = mImgRect.top + mImgRect.height() / 2 mScaleCenter[imgCx] = imgCy