pull/279/head
gedoor 4 years ago
parent b0bc9661e4
commit 137c39211c
  1. 2
      app/build.gradle
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  4. 62
      app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt

@ -124,7 +124,7 @@ dependencies {
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
//androidX //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.appcompat:appcompat:1.1.0'
implementation 'androidx.media:media:1.1.0' implementation 'androidx.media:media:1.1.0'
implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.preference:preference:1.1.1'

@ -22,6 +22,7 @@ data class TextPage(
fun upLinesPosition() = ChapterProvider.apply { fun upLinesPosition() = ChapterProvider.apply {
if (!ReadBookConfig.textBottomJustify) return@apply if (!ReadBookConfig.textBottomJustify) return@apply
if (textLines.size <= 1) return@apply if (textLines.size <= 1) return@apply
if (textLines.last().isImage) return@apply
if (visibleHeight - height >= with(textLines.last()) { lineBottom - lineTop }) return@apply if (visibleHeight - height >= with(textLines.last()) { lineBottom - lineTop }) return@apply
val surplus = (visibleBottom - textLines.last().lineBottom) val surplus = (visibleBottom - textLines.last().lineBottom)
if (surplus == 0f) return@apply if (surplus == 0f) return@apply

@ -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.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.utils.* import io.legado.app.utils.*
import java.util.*
import java.util.regex.Pattern import java.util.regex.Pattern
@ -122,9 +123,13 @@ object ChapterProvider {
): Float { ): Float {
var durY = y var durY = y
ImageProvider.getImage(book, chapter.index, src)?.let { ImageProvider.getImage(book, chapter.index, src)?.let {
if (durY > visibleHeight) {
textPages.add(TextPage())
durY = 0f
}
var height = it.height var height = it.height
var width = it.width var width = it.width
when (imageStyle?.toUpperCase()) { when (imageStyle?.toUpperCase(Locale.ROOT)) {
"FULL" -> { "FULL" -> {
width = visibleWidth width = visibleWidth
height = it.height * visibleWidth / it.width height = it.height * visibleWidth / it.width

@ -200,7 +200,7 @@ class PhotoView : ImageView {
override fun setImageResource(resId: Int) { override fun setImageResource(resId: Int) {
var drawable: Drawable? = null var drawable: Drawable? = null
try { try {
drawable = resources.getDrawable(resId) drawable = resources.getDrawable(resId, null)
} catch (e: Exception) { } catch (e: Exception) {
} }
setImageDrawable(drawable) setImageDrawable(drawable)
@ -402,8 +402,8 @@ class PhotoView : ImageView {
val pHeight = MeasureSpec.getSize(heightMeasureSpec) val pHeight = MeasureSpec.getSize(heightMeasureSpec)
val widthMode = MeasureSpec.getMode(widthMeasureSpec) val widthMode = MeasureSpec.getMode(widthMeasureSpec)
val heightMode = MeasureSpec.getMode(heightMeasureSpec) val heightMode = MeasureSpec.getMode(heightMeasureSpec)
var width = 0 var width: Int
var height = 0 var height: Int
var p = layoutParams var p = layoutParams
if (p == null) { if (p == null) {
p = ViewGroup.LayoutParams( p = ViewGroup.LayoutParams(
@ -703,47 +703,47 @@ class PhotoView : ImageView {
distanceX: Float, distanceX: Float,
distanceY: Float distanceY: Float
): Boolean { ): Boolean {
var distanceX = distanceX var x = distanceX
var distanceY = distanceY var y = distanceY
if (mTranslate.isRunning) { if (mTranslate.isRunning) {
mTranslate.stop() mTranslate.stop()
} }
if (canScrollHorizontallySelf(distanceX)) { if (canScrollHorizontallySelf(x)) {
if (distanceX < 0 && mImgRect.left - distanceX > mWidgetRect.left) distanceX = if (x < 0 && mImgRect.left - x > mWidgetRect.left)
mImgRect.left x = mImgRect.left
if (distanceX > 0 && mImgRect.right - distanceX < mWidgetRect.right) distanceX = if (x > 0 && mImgRect.right - x < mWidgetRect.right)
mImgRect.right - mWidgetRect.right x = mImgRect.right - mWidgetRect.right
mAnimMatrix.postTranslate(-distanceX, 0f) mAnimMatrix.postTranslate(-x, 0f)
mTranslateX -= distanceX.toInt() mTranslateX -= x.toInt()
} else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) { } else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) {
checkRect() checkRect()
if (!hasMultiTouch) { if (!hasMultiTouch) {
if (distanceX < 0 && mImgRect.left - distanceX > mCommonRect.left) distanceX = if (x < 0 && mImgRect.left - x > mCommonRect.left) x =
resistanceScrollByX(mImgRect.left - mCommonRect.left, distanceX) resistanceScrollByX(mImgRect.left - mCommonRect.left, x)
if (distanceX > 0 && mImgRect.right - distanceX < mCommonRect.right) distanceX = if (x > 0 && mImgRect.right - x < mCommonRect.right) x =
resistanceScrollByX(mImgRect.right - mCommonRect.right, distanceX) resistanceScrollByX(mImgRect.right - mCommonRect.right, x)
} }
mTranslateX -= distanceX.toInt() mTranslateX -= x.toInt()
mAnimMatrix.postTranslate(-distanceX, 0f) mAnimMatrix.postTranslate(-x, 0f)
hasOverTranslate = true hasOverTranslate = true
} }
if (canScrollVerticallySelf(distanceY)) { if (canScrollVerticallySelf(y)) {
if (distanceY < 0 && mImgRect.top - distanceY > mWidgetRect.top) distanceY = if (y < 0 && mImgRect.top - y > mWidgetRect.top) y =
mImgRect.top mImgRect.top
if (distanceY > 0 && mImgRect.bottom - distanceY < mWidgetRect.bottom) distanceY = if (y > 0 && mImgRect.bottom - y < mWidgetRect.bottom) y =
mImgRect.bottom - mWidgetRect.bottom mImgRect.bottom - mWidgetRect.bottom
mAnimMatrix.postTranslate(0f, -distanceY) mAnimMatrix.postTranslate(0f, -y)
mTranslateY -= distanceY.toInt() mTranslateY -= y.toInt()
} else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) { } else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) {
checkRect() checkRect()
if (!hasMultiTouch) { if (!hasMultiTouch) {
if (distanceY < 0 && mImgRect.top - distanceY > mCommonRect.top) distanceY = if (y < 0 && mImgRect.top - y > mCommonRect.top) y =
resistanceScrollByY(mImgRect.top - mCommonRect.top, distanceY) resistanceScrollByY(mImgRect.top - mCommonRect.top, y)
if (distanceY > 0 && mImgRect.bottom - distanceY < mCommonRect.bottom) distanceY = if (y > 0 && mImgRect.bottom - y < mCommonRect.bottom) y =
resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, distanceY) resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, y)
} }
mAnimMatrix.postTranslate(0f, -distanceY) mAnimMatrix.postTranslate(0f, -y)
mTranslateY -= distanceY.toInt() mTranslateY -= y.toInt()
hasOverTranslate = true hasOverTranslate = true
} }
executeTranslate() executeTranslate()
@ -757,8 +757,8 @@ class PhotoView : ImageView {
override fun onDoubleTap(e: MotionEvent): Boolean { override fun onDoubleTap(e: MotionEvent): Boolean {
mTranslate.stop() mTranslate.stop()
var from = 1f val from: Float
var to = 1f val to: Float
val imgCx = mImgRect.left + mImgRect.width() / 2 val imgCx = mImgRect.left + mImgRect.width() / 2
val imgCy = mImgRect.top + mImgRect.height() / 2 val imgCy = mImgRect.top + mImgRect.height() / 2
mScaleCenter[imgCx] = imgCy mScaleCenter[imgCx] = imgCy

Loading…
Cancel
Save