|
|
@ -41,35 +41,24 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
private var exploreReselected: Long = 0 |
|
|
|
private var exploreReselected: Long = 0 |
|
|
|
private var pagePosition = 0 |
|
|
|
private var pagePosition = 0 |
|
|
|
private val fragmentMap = hashMapOf<Long, Fragment>() |
|
|
|
private val fragmentMap = hashMapOf<Long, Fragment>() |
|
|
|
|
|
|
|
private var bottomMenuCount = 2 |
|
|
|
|
|
|
|
|
|
|
|
override fun getViewBinding(): ActivityMainBinding { |
|
|
|
override fun getViewBinding(): ActivityMainBinding { |
|
|
|
return ActivityMainBinding.inflate(layoutInflater) |
|
|
|
return ActivityMainBinding.inflate(layoutInflater) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
|
|
|
|
upBottomMenu() |
|
|
|
binding.apply { |
|
|
|
binding.apply { |
|
|
|
ATH.applyEdgeEffectColor(viewPagerMain) |
|
|
|
ATH.applyEdgeEffectColor(viewPagerMain) |
|
|
|
ATH.applyBottomNavigationColor(bottomNavigationView) |
|
|
|
ATH.applyBottomNavigationColor(bottomNavigationView) |
|
|
|
viewPagerMain.offscreenPageLimit = 3 |
|
|
|
viewPagerMain.offscreenPageLimit = 3 |
|
|
|
viewPagerMain.adapter = TabFragmentPageAdapter() |
|
|
|
viewPagerMain.adapter = TabFragmentPageAdapter() |
|
|
|
viewPagerMain.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { |
|
|
|
viewPagerMain.registerOnPageChangeCallback(PageChangeCallback()) |
|
|
|
override fun onPageSelected(position: Int) { |
|
|
|
|
|
|
|
pagePosition = position |
|
|
|
|
|
|
|
when (position) { |
|
|
|
|
|
|
|
0, 1, 3 -> bottomNavigationView.menu.getItem(position).isChecked = true |
|
|
|
|
|
|
|
2 -> if (AppConfig.isShowRSS) { |
|
|
|
|
|
|
|
bottomNavigationView.menu.getItem(position).isChecked = true |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
bottomNavigationView.menu.getItem(3).isChecked = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
bottomNavigationView.elevation = |
|
|
|
bottomNavigationView.elevation = |
|
|
|
if (AppConfig.elevation < 0) elevation else AppConfig.elevation.toFloat() |
|
|
|
if (AppConfig.elevation < 0) elevation else AppConfig.elevation.toFloat() |
|
|
|
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity) |
|
|
|
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity) |
|
|
|
bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity) |
|
|
|
bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity) |
|
|
|
bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -90,9 +79,13 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) { |
|
|
|
override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) { |
|
|
|
when (item.itemId) { |
|
|
|
when (item.itemId) { |
|
|
|
R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false) |
|
|
|
R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false) |
|
|
|
R.id.menu_explore -> viewPagerMain.setCurrentItem(1, false) |
|
|
|
R.id.menu_discovery -> viewPagerMain.setCurrentItem(1, false) |
|
|
|
R.id.menu_rss -> viewPagerMain.setCurrentItem(2, false) |
|
|
|
R.id.menu_rss -> if (AppConfig.showDiscovery) { |
|
|
|
R.id.menu_my_config -> viewPagerMain.setCurrentItem(3, false) |
|
|
|
viewPagerMain.setCurrentItem(2, false) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
viewPagerMain.setCurrentItem(1, false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
R.id.menu_my_config -> viewPagerMain.setCurrentItem(bottomMenuCount - 1, false) |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
@ -106,7 +99,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
(fragmentMap[0] as? BookshelfFragment)?.gotoTop() |
|
|
|
(fragmentMap[0] as? BookshelfFragment)?.gotoTop() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_explore -> { |
|
|
|
R.id.menu_discovery -> { |
|
|
|
if (System.currentTimeMillis() - exploreReselected > 300) { |
|
|
|
if (System.currentTimeMillis() - exploreReselected > 300) { |
|
|
|
exploreReselected = System.currentTimeMillis() |
|
|
|
exploreReselected = System.currentTimeMillis() |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -176,12 +169,11 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
observeEvent<String>(EventBus.RECREATE) { |
|
|
|
observeEvent<String>(EventBus.RECREATE) { |
|
|
|
recreate() |
|
|
|
recreate() |
|
|
|
} |
|
|
|
} |
|
|
|
observeEvent<String>(EventBus.SHOW_RSS) { |
|
|
|
observeEvent<String>(EventBus.NOTIFY_MAIN) { |
|
|
|
binding.bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = |
|
|
|
binding.apply { |
|
|
|
AppConfig.isShowRSS |
|
|
|
upBottomMenu() |
|
|
|
binding.viewPagerMain.adapter?.notifyDataSetChanged() |
|
|
|
viewPagerMain.adapter?.notifyDataSetChanged() |
|
|
|
if (AppConfig.isShowRSS) { |
|
|
|
viewPagerMain.setCurrentItem(bottomMenuCount - 1, false) |
|
|
|
binding.viewPagerMain.setCurrentItem(3, false) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
observeEvent<String>(PreferKey.threadCount) { |
|
|
|
observeEvent<String>(PreferKey.threadCount) { |
|
|
@ -189,22 +181,57 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private inner class TabFragmentPageAdapter : |
|
|
|
private fun upBottomMenu() { |
|
|
|
FragmentStateAdapter(this) { |
|
|
|
binding.bottomNavigationView.menu.let { menu -> |
|
|
|
|
|
|
|
menu.findItem(R.id.menu_discovery).isVisible = AppConfig.showDiscovery |
|
|
|
|
|
|
|
menu.findItem(R.id.menu_rss).isVisible = AppConfig.showRSS |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bottomMenuCount = 2 |
|
|
|
|
|
|
|
if (AppConfig.showDiscovery) { |
|
|
|
|
|
|
|
bottomMenuCount++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (AppConfig.showRSS) { |
|
|
|
|
|
|
|
bottomMenuCount++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getItemId(position: Int): Long { |
|
|
|
private fun getRealBottomMenuPosition(position: Int): Int { |
|
|
|
return when (position) { |
|
|
|
return when (position) { |
|
|
|
2 -> if (AppConfig.isShowRSS) 2 else 3 |
|
|
|
1 -> when { |
|
|
|
else -> position.toLong() |
|
|
|
AppConfig.showDiscovery -> 1 |
|
|
|
|
|
|
|
AppConfig.showRSS -> 2 |
|
|
|
|
|
|
|
else -> 3 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
2 -> if (AppConfig.showDiscovery) { |
|
|
|
|
|
|
|
if (AppConfig.showRSS) 2 else 3 |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
3 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> position |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private inner class PageChangeCallback : ViewPager2.OnPageChangeCallback() { |
|
|
|
|
|
|
|
override fun onPageSelected(position: Int) { |
|
|
|
|
|
|
|
pagePosition = position |
|
|
|
|
|
|
|
binding.bottomNavigationView.menu |
|
|
|
|
|
|
|
.getItem(getRealBottomMenuPosition(position)).isChecked = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private inner class TabFragmentPageAdapter : |
|
|
|
|
|
|
|
FragmentStateAdapter(this) { |
|
|
|
|
|
|
|
|
|
|
|
override fun containsItem(itemId: Long): Boolean { |
|
|
|
override fun containsItem(itemId: Long): Boolean { |
|
|
|
return fragmentMap.containsKey(itemId) |
|
|
|
return fragmentMap.containsKey(itemId) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getItemCount(): Int { |
|
|
|
override fun getItemCount(): Int { |
|
|
|
return if (AppConfig.isShowRSS) 4 else 3 |
|
|
|
return bottomMenuCount |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun getItemId(position: Int): Long { |
|
|
|
|
|
|
|
return getRealBottomMenuPosition(position).toLong() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun createFragment(position: Int): Fragment { |
|
|
|
override fun createFragment(position: Int): Fragment { |
|
|
|