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