feat: 优化代码

pull/133/head
kunfei 5 years ago
parent 2ed01ecd9c
commit e0f9525fc0
  1. 22
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -34,11 +34,12 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
get() = getViewModel(MainViewModel::class.java) get() = getViewModel(MainViewModel::class.java)
private var pagePosition = 0 private var pagePosition = 0
private val fragmentMap = mapOf<String, Fragment>( private val fragmentId = arrayOf(0, 1, 2, 3)
Pair("bookshelf", BookshelfFragment()), private val fragmentMap = mapOf<Int, Fragment>(
Pair("explore", ExploreFragment()), Pair(fragmentId[0], BookshelfFragment()),
Pair("rss", RssFragment()), Pair(fragmentId[1], ExploreFragment()),
Pair("myConfig", MyFragment()) Pair(fragmentId[2], RssFragment()),
Pair(fragmentId[3], MyFragment())
) )
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -147,14 +148,14 @@ 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 (position) {
0 -> fragmentMap.getValue("bookshelf") 0 -> fragmentMap.getValue(fragmentId[0])
1 -> fragmentMap.getValue("explore") 1 -> fragmentMap.getValue(fragmentId[1])
2 -> if (AppConfig.isShowRSS) { 2 -> if (AppConfig.isShowRSS) {
fragmentMap.getValue("rss") fragmentMap.getValue(fragmentId[2])
} else { } else {
fragmentMap.getValue("myConfig") fragmentMap.getValue(fragmentId[3])
} }
else -> fragmentMap.getValue("myConfig") else -> fragmentMap.getValue(fragmentId[3])
} }
} }
@ -163,4 +164,5 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
} }
} }
} }
Loading…
Cancel
Save