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