pull/1738/head
kunfei 3 years ago
parent 4df9b63022
commit ee7d31872d
  1. 22
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -88,12 +88,8 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
when (item.itemId) {
R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false)
R.id.menu_discovery -> viewPagerMain.setCurrentItem(1, false)
R.id.menu_rss -> if (AppConfig.showDiscovery) {
viewPagerMain.setCurrentItem(2, false)
} else {
viewPagerMain.setCurrentItem(1, false)
}
R.id.menu_my_config -> viewPagerMain.setCurrentItem(bottomMenuCount - 1, false)
R.id.menu_rss -> openPage(RssFragment.id)
R.id.menu_my_config -> openPage(MyFragment.id)
}
return false
}
@ -117,6 +113,14 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
}
}
private fun openPage(id: Int) {
realPositions.firstOrNull {
it == id
}?.let { index ->
binding.viewPagerMain.setCurrentItem(index, false)
}
}
private fun upVersion() {
if (LocalConfig.versionCode != appInfo.versionCode) {
LocalConfig.versionCode = appInfo.versionCode
@ -212,11 +216,11 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
}
private fun getFragmentId(position: Int): Int {
val p = realPositions[position]
if (p == BaseBookshelfFragment.id) {
val id = realPositions[position]
if (id == BaseBookshelfFragment.id) {
return if (AppConfig.bookGroupStyle == 1) BookshelfFragment2.id else BookshelfFragment1.id
}
return p
return id
}
private inner class PageChangeCallback : ViewPager.SimpleOnPageChangeListener() {

Loading…
Cancel
Save