pull/401/head^2
gedoor 4 years ago
parent 19313fc44f
commit 2d7fd29def
  1. 56
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -170,33 +170,37 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
private inner class TabFragmentPageAdapter(fm: FragmentManager) :
FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
private fun getBookshelfFragment(): Fragment {
if (!fragmentMap.containsKey(0)) {
fragmentMap[0] = BookshelfFragment()
val bookshelfFragment: Fragment
get() {
if (!fragmentMap.containsKey(0)) {
fragmentMap[0] = BookshelfFragment()
}
return fragmentMap.getValue(0)
}
return fragmentMap.getValue(0)
}
private fun getExploreFragment(): Fragment {
if (!fragmentMap.containsKey(1)) {
fragmentMap[1] = ExploreFragment()
val exploreFragment: Fragment
get() {
if (!fragmentMap.containsKey(1)) {
fragmentMap[1] = ExploreFragment()
}
return fragmentMap.getValue(1)
}
return fragmentMap.getValue(1)
}
private fun getRssFragment(): Fragment {
if (!fragmentMap.containsKey(2)) {
fragmentMap[2] = RssFragment()
val rssFragment: Fragment
get() {
if (!fragmentMap.containsKey(2)) {
fragmentMap[2] = RssFragment()
}
return fragmentMap.getValue(2)
}
return fragmentMap.getValue(2)
}
private fun getMyFragment(): Fragment {
if (!fragmentMap.containsKey(3)) {
fragmentMap[3] = MyFragment()
val myFragment: Fragment
get() {
if (!fragmentMap.containsKey(3)) {
fragmentMap[3] = MyFragment()
}
return fragmentMap.getValue(3)
}
return fragmentMap.getValue(3)
}
override fun getItemPosition(`object`: Any): Int {
return POSITION_NONE
@ -204,14 +208,10 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> getBookshelfFragment()
1 -> getExploreFragment()
2 -> if (AppConfig.isShowRSS) {
getRssFragment()
} else {
getMyFragment()
}
else -> getMyFragment()
0 -> bookshelfFragment
1 -> exploreFragment
2 -> if (AppConfig.isShowRSS) rssFragment else myFragment
else -> myFragment
}
}

Loading…
Cancel
Save