pull/433/head
gedoor 4 years ago
parent 15c8fef424
commit 3d530ca191
  1. 53
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -178,48 +178,23 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
private inner class TabFragmentPageAdapter(fm: FragmentManager) :
FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
val bookshelfFragment: Fragment
get() {
if (!fragmentMap.containsKey(0)) {
fragmentMap[0] = BookshelfFragment()
}
return fragmentMap.getValue(0)
}
val exploreFragment: Fragment
get() {
if (!fragmentMap.containsKey(1)) {
fragmentMap[1] = ExploreFragment()
}
return fragmentMap.getValue(1)
}
val rssFragment: Fragment
get() {
if (!fragmentMap.containsKey(2)) {
fragmentMap[2] = RssFragment()
}
return fragmentMap.getValue(2)
}
val myFragment: Fragment
get() {
if (!fragmentMap.containsKey(3)) {
fragmentMap[3] = MyFragment()
}
return fragmentMap.getValue(3)
private fun getId(position: Int): Int {
return when (position) {
2 -> if (AppConfig.isShowRSS) 2 else 3
else -> position
}
}
override fun getItemPosition(`object`: Any): Int {
return POSITION_NONE
}
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> bookshelfFragment
1 -> exploreFragment
2 -> if (AppConfig.isShowRSS) rssFragment else myFragment
else -> myFragment
return when (getId(position)) {
0 -> BookshelfFragment()
1 -> ExploreFragment()
2 -> RssFragment()
else -> MyFragment()
}
}
@ -229,13 +204,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val fragment = super.instantiateItem(container, position) as Fragment
val id = when (position) {
2 -> if (AppConfig.isShowRSS) 2 else 3
else -> position
}
if (!fragmentMap.containsKey(id)) {
fragmentMap[id] = fragment
}
fragmentMap[getId(position)] = fragment
return fragment
}

@ -232,9 +232,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val fragment = super.instantiateItem(container, position) as BooksFragment
val group = bookGroups[position]
if (!fragmentMap.containsKey(group.groupId)) {
fragmentMap[group.groupId] = fragment
}
fragmentMap[group.groupId] = fragment
return fragment
}

Loading…
Cancel
Save