From 585415c5418713410d6ed19502413c21f11a85d8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 3 Oct 2021 12:10:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=BC=E8=88=AA=E6=A0=8F?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookBaseActivity.kt | 6 ++--- .../io/legado/app/ui/book/read/ReadMenu.kt | 6 ++--- .../io/legado/app/utils/ActivityExtensions.kt | 22 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt index 582a3c793..71d2b760c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt @@ -157,17 +157,17 @@ abstract class ReadBookBaseActivity : 0 } when (navigationBarPos) { - 0 -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply { + POS.BOTTOM -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply { height = navigationBarHeight width = MATCH_PARENT gravity = Gravity.BOTTOM } - 1 -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply { + POS.LEFT -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply { height = MATCH_PARENT width = navigationBarHeight gravity = Gravity.LEFT } - 2 -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply { + POS.RIGHT -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply { height = MATCH_PARENT width = navigationBarHeight gravity = Gravity.RIGHT diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index bf37f1134..a4c5de847 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -316,9 +316,9 @@ class ReadMenu @JvmOverloads constructor( vwMenuBg.setOnClickListener { runMenuOut() } root.padding = 0 when (activity?.navigationBarPos) { - 0 -> root.bottomPadding = navigationBarHeight - 1 -> root.leftPadding = navigationBarHeight - 2 -> root.rightPadding = navigationBarHeight + POS.BOTTOM -> root.bottomPadding = navigationBarHeight + POS.LEFT -> root.leftPadding = navigationBarHeight + POS.RIGHT -> root.rightPadding = navigationBarHeight } } if (!LocalConfig.readMenuHelpVersionIsLast) { diff --git a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt index 77dc417bf..3163fcf98 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -77,24 +77,22 @@ val Activity.navigationBarHeight: Int * 1 left * 2 right */ -val Activity.navigationBarPos: Int +val Activity.navigationBarPos: POS get() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - var pos = 0 val display: Display = windowManager.defaultDisplay val rotate: Int = display.rotation val height: Int = display.height val width: Int = display.width - pos = if (width > height) { + return if (width > height) { if (rotate == Surface.ROTATION_270) { - 1 //left + POS.LEFT } else { - 2 //right + POS.RIGHT } } else { - 0 //bottom + POS.BOTTOM } - return pos } else { val display: Display = windowManager.defaultDisplay val metricsReal = DisplayMetrics() @@ -110,9 +108,13 @@ val Activity.navigationBarPos: Int val realH = metricsReal.heightPixels return if (currW != realW && currH == realH) { - 2 + POS.RIGHT } else { - 0 + POS.BOTTOM } } - } \ No newline at end of file + } + +enum class POS { + BOTTOM, LEFT, RIGHT +} \ No newline at end of file