From b8c8a4465d4f87d05573b19cb8a33c1efc307439 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 4 Sep 2020 13:58:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 4 +-- .../read/page/provider/ChapterProvider.kt | 33 +++++++++++++------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 65bff96d2..1a469b3ba 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -65,9 +65,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) - ChapterProvider.viewWidth = w - ChapterProvider.viewHeight = h - ChapterProvider.upViewSize() + ChapterProvider.upViewSize(w, h) upVisibleRect() textPage.format() } 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 f39d6783b..a8cf1482d 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 @@ -22,8 +22,8 @@ import java.util.* @Suppress("DEPRECATION") object ChapterProvider { - var viewWidth = 0 - var viewHeight = 0 + private var viewWidth = 0 + private var viewHeight = 0 var paddingLeft = 0 var paddingTop = 0 var visibleWidth = 0 @@ -440,19 +440,32 @@ object ChapterProvider { paragraphSpacing = ReadBookConfig.paragraphSpacing titleTopSpacing = ReadBookConfig.titleTopSpacing.dp titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp - upViewSize() + upVisibleSize() } /** * 更新View尺寸 */ - fun upViewSize() { - paddingLeft = ReadBookConfig.paddingLeft.dp - paddingTop = ReadBookConfig.paddingTop.dp - visibleWidth = viewWidth - paddingLeft - ReadBookConfig.paddingRight.dp - visibleHeight = viewHeight - paddingTop - ReadBookConfig.paddingBottom.dp - visibleRight = paddingLeft + visibleWidth - visibleBottom = paddingTop + visibleHeight + fun upViewSize(width: Int, height: Int) { + if (width > 0 && height > 0) { + viewWidth = width + viewHeight = height + upVisibleSize() + } + } + + /** + * 更新绘制尺寸 + */ + private fun upVisibleSize() { + if (viewWidth > 0 && viewHeight > 0) { + paddingLeft = ReadBookConfig.paddingLeft.dp + paddingTop = ReadBookConfig.paddingTop.dp + visibleWidth = viewWidth - paddingLeft - ReadBookConfig.paddingRight.dp + visibleHeight = viewHeight - paddingTop - ReadBookConfig.paddingBottom.dp + visibleRight = paddingLeft + visibleWidth + visibleBottom = paddingTop + visibleHeight + } } val TextPaint.textHeight: Float