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 {