From 6e69efb34e29269c4f6cd8abcabc19e4ec2a9d63 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 22 May 2021 22:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=91=E7=8E=B0=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E9=9A=90=E8=97=8F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainActivity.kt | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 1987cb286..9741e726d 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -42,6 +42,7 @@ class MainActivity : VMBaseActivity(), private var pagePosition = 0 private val fragmentMap = hashMapOf() private var bottomMenuCount = 2 + private val realPositions = arrayOf(0, 1, 2, 3) override fun getViewBinding(): ActivityMainBinding { return ActivityMainBinding.inflate(layoutInflater) @@ -182,32 +183,30 @@ class MainActivity : VMBaseActivity(), } private fun upBottomMenu() { + val showDiscovery = AppConfig.showDiscovery + val showRss = AppConfig.showRSS binding.bottomNavigationView.menu.let { menu -> - menu.findItem(R.id.menu_discovery).isVisible = AppConfig.showDiscovery - menu.findItem(R.id.menu_rss).isVisible = AppConfig.showRSS + menu.findItem(R.id.menu_discovery).isVisible = showDiscovery + menu.findItem(R.id.menu_rss).isVisible = showRss } bottomMenuCount = 2 - if (AppConfig.showDiscovery) { - bottomMenuCount++ - } - if (AppConfig.showRSS) { - bottomMenuCount++ - } - } - - private fun getRealBottomMenuPosition(position: Int): Int { - return when (position) { - 1 -> when { - AppConfig.showDiscovery -> 1 - AppConfig.showRSS -> 2 - else -> 3 + realPositions[1] = 1 + realPositions[2] = 2 + when { + showDiscovery -> bottomMenuCount++ + showRss -> { + realPositions[1] = 2 + realPositions[2] = 3 } - 2 -> if (AppConfig.showDiscovery) { - if (AppConfig.showRSS) 2 else 3 - } else { - 3 + else -> { + realPositions[1] = 3 + realPositions[2] = 3 } - else -> position + } + if (showRss) { + bottomMenuCount++ + } else { + realPositions[2] = 3 } } @@ -215,7 +214,7 @@ class MainActivity : VMBaseActivity(), override fun onPageSelected(position: Int) { pagePosition = position binding.bottomNavigationView.menu - .getItem(getRealBottomMenuPosition(position)).isChecked = true + .getItem(realPositions[position]).isChecked = true } } @@ -231,7 +230,7 @@ class MainActivity : VMBaseActivity(), } override fun getItemId(position: Int): Long { - return getRealBottomMenuPosition(position).toLong() + return realPositions[position].toLong() } override fun createFragment(position: Int): Fragment {