添加发现界面隐藏配置

pull/1006/head 3.21.052320
gedoor 4 years ago
parent cbaac7e0dc
commit 6e69efb34e
  1. 45
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -42,6 +42,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
private var pagePosition = 0 private var pagePosition = 0
private val fragmentMap = hashMapOf<Long, Fragment>() private val fragmentMap = hashMapOf<Long, Fragment>()
private var bottomMenuCount = 2 private var bottomMenuCount = 2
private val realPositions = arrayOf(0, 1, 2, 3)
override fun getViewBinding(): ActivityMainBinding { override fun getViewBinding(): ActivityMainBinding {
return ActivityMainBinding.inflate(layoutInflater) return ActivityMainBinding.inflate(layoutInflater)
@ -182,32 +183,30 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
} }
private fun upBottomMenu() { private fun upBottomMenu() {
val showDiscovery = AppConfig.showDiscovery
val showRss = AppConfig.showRSS
binding.bottomNavigationView.menu.let { menu -> binding.bottomNavigationView.menu.let { menu ->
menu.findItem(R.id.menu_discovery).isVisible = AppConfig.showDiscovery menu.findItem(R.id.menu_discovery).isVisible = showDiscovery
menu.findItem(R.id.menu_rss).isVisible = AppConfig.showRSS menu.findItem(R.id.menu_rss).isVisible = showRss
} }
bottomMenuCount = 2 bottomMenuCount = 2
if (AppConfig.showDiscovery) { realPositions[1] = 1
bottomMenuCount++ realPositions[2] = 2
} when {
if (AppConfig.showRSS) { showDiscovery -> bottomMenuCount++
bottomMenuCount++ showRss -> {
} realPositions[1] = 2
} realPositions[2] = 3
private fun getRealBottomMenuPosition(position: Int): Int {
return when (position) {
1 -> when {
AppConfig.showDiscovery -> 1
AppConfig.showRSS -> 2
else -> 3
} }
2 -> if (AppConfig.showDiscovery) { else -> {
if (AppConfig.showRSS) 2 else 3 realPositions[1] = 3
} else { realPositions[2] = 3
3
} }
else -> position }
if (showRss) {
bottomMenuCount++
} else {
realPositions[2] = 3
} }
} }
@ -215,7 +214,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
pagePosition = position pagePosition = position
binding.bottomNavigationView.menu binding.bottomNavigationView.menu
.getItem(getRealBottomMenuPosition(position)).isChecked = true .getItem(realPositions[position]).isChecked = true
} }
} }
@ -231,7 +230,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
} }
override fun getItemId(position: Int): Long { override fun getItemId(position: Int): Long {
return getRealBottomMenuPosition(position).toLong() return realPositions[position].toLong()
} }
override fun createFragment(position: Int): Fragment { override fun createFragment(position: Int): Fragment {

Loading…
Cancel
Save