From 94496e2a541917609f5ac225d41ae167c80c49f4 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 17 Nov 2020 22:19:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=BC=E8=88=AA=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 1 + .../java/io/legado/app/base/BaseActivity.kt | 8 ++ .../app/ui/book/read/page/ContentView.kt | 78 +++++++++---------- .../legado/app/ui/book/read/page/PageView.kt | 2 +- 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index d6849f488..e43ce9ac7 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -34,6 +34,7 @@ class App : MultiDexApplication() { lateinit var androidId: String var versionCode = 0 var versionName = "" + var navigationBarHeight = 0 } override fun onCreate() { diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index d156c294a..53d2f860a 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -10,6 +10,7 @@ import android.view.MenuItem import android.view.View import android.widget.FrameLayout import androidx.appcompat.app.AppCompatActivity +import io.legado.app.App import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.Theme @@ -71,6 +72,13 @@ abstract class BaseActivity( observeLiveBus() } + override fun onWindowFocusChanged(hasFocus: Boolean) { + super.onWindowFocusChanged(hasFocus) + if (hasFocus) { + App.navigationBarHeight = navigationBarHeight + } + } + override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, newConfig: Configuration?) { super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig) findViewById(R.id.title_bar) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 95b7ae318..09daf30de 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable import android.widget.FrameLayout import androidx.core.view.isGone import androidx.core.view.isInvisible +import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.constant.AppConst.timeFormat @@ -51,49 +52,42 @@ class ContentView(context: Context) : FrameLayout(context) { } } - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { - super.onSizeChanged(w, h, oldw, oldh) - upStyle() - } - - fun upStyle() { - ReadBookConfig.apply { - bv_header_left.typeface = ChapterProvider.typeface - tv_header_left.typeface = ChapterProvider.typeface - tv_header_middle.typeface = ChapterProvider.typeface - tv_header_right.typeface = ChapterProvider.typeface - bv_footer_left.typeface = ChapterProvider.typeface - tv_footer_left.typeface = ChapterProvider.typeface - tv_footer_middle.typeface = ChapterProvider.typeface - tv_footer_right.typeface = ChapterProvider.typeface - bv_header_left.setColor(textColor) - tv_header_left.setColor(textColor) - tv_header_middle.setColor(textColor) - tv_header_right.setColor(textColor) - bv_footer_left.setColor(textColor) - tv_footer_left.setColor(textColor) - tv_footer_middle.setColor(textColor) - tv_footer_right.setColor(textColor) - upStatusBar() - ll_header.setPadding( - headerPaddingLeft.dp, - headerPaddingTop.dp, - headerPaddingRight.dp, - headerPaddingBottom.dp - ) - ll_footer.setPadding( - footerPaddingLeft.dp, - footerPaddingTop.dp, - footerPaddingRight.dp, - footerPaddingBottom.dp - ) - vw_top_divider.visible(showHeaderLine) - vw_bottom_divider.visible(showFooterLine) - page_nv_bar.layoutParams = page_nv_bar.layoutParams.apply { - height = if (hideNavigationBar) 0 else activity!!.navigationBarHeight - } - content_text_view.upVisibleRect() + fun upStyle() = ReadBookConfig.apply { + bv_header_left.typeface = ChapterProvider.typeface + tv_header_left.typeface = ChapterProvider.typeface + tv_header_middle.typeface = ChapterProvider.typeface + tv_header_right.typeface = ChapterProvider.typeface + bv_footer_left.typeface = ChapterProvider.typeface + tv_footer_left.typeface = ChapterProvider.typeface + tv_footer_middle.typeface = ChapterProvider.typeface + tv_footer_right.typeface = ChapterProvider.typeface + bv_header_left.setColor(textColor) + tv_header_left.setColor(textColor) + tv_header_middle.setColor(textColor) + tv_header_right.setColor(textColor) + bv_footer_left.setColor(textColor) + tv_footer_left.setColor(textColor) + tv_footer_middle.setColor(textColor) + tv_footer_right.setColor(textColor) + upStatusBar() + ll_header.setPadding( + headerPaddingLeft.dp, + headerPaddingTop.dp, + headerPaddingRight.dp, + headerPaddingBottom.dp + ) + ll_footer.setPadding( + footerPaddingLeft.dp, + footerPaddingTop.dp, + footerPaddingRight.dp, + footerPaddingBottom.dp + ) + vw_top_divider.visible(showHeaderLine) + vw_bottom_divider.visible(showFooterLine) + page_nv_bar.layoutParams = page_nv_bar.layoutParams.apply { + height = if (hideNavigationBar) 0 else App.navigationBarHeight } + content_text_view.upVisibleRect() upTime() upBattery(battery) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 4bd777ab8..4abc569e7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -112,7 +112,7 @@ class PageView(context: Context, attrs: AttributeSet) : brRect.set(width * 0.66f, height * 0.66f, width - 10f, height - 10f) prevPage.x = -w.toFloat() pageDelegate?.setViewSize(w, h) - if (oldw != 0 && oldh != 0) { + if (w != 0 && h != 0) { ReadBook.loadContent(resetPageOffset = false) } }