添加发现界面隐藏配置

pull/1006/head 3.21.052320
gedoor 4 years ago
parent cbaac7e0dc
commit 6e69efb34e
  1. 41
      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 val fragmentMap = hashMapOf<Long, Fragment>()
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<ActivityMainBinding, MainViewModel>(),
}
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++
realPositions[1] = 1
realPositions[2] = 2
when {
showDiscovery -> bottomMenuCount++
showRss -> {
realPositions[1] = 2
realPositions[2] = 3
}
else -> {
realPositions[1] = 3
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) {
if (AppConfig.showRSS) 2 else 3
if (showRss) {
bottomMenuCount++
} else {
3
}
else -> position
realPositions[2] = 3
}
}
@ -215,7 +214,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
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<ActivityMainBinding, MainViewModel>(),
}
override fun getItemId(position: Int): Long {
return getRealBottomMenuPosition(position).toLong()
return realPositions[position].toLong()
}
override fun createFragment(position: Int): Fragment {

Loading…
Cancel
Save