|
|
@ -1,6 +1,7 @@ |
|
|
|
package io.legado.app.ui.main |
|
|
|
package io.legado.app.ui.main |
|
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
|
|
|
|
import android.view.KeyEvent |
|
|
|
import android.view.MenuItem |
|
|
|
import android.view.MenuItem |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
@ -34,6 +35,8 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), |
|
|
|
override val viewModel: MainViewModel |
|
|
|
override val viewModel: MainViewModel |
|
|
|
get() = getViewModel(MainViewModel::class.java) |
|
|
|
get() = getViewModel(MainViewModel::class.java) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var pagePosition = 0 |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
ATH.applyEdgeEffectColor(view_pager_main) |
|
|
|
ATH.applyEdgeEffectColor(view_pager_main) |
|
|
|
ATH.applyBottomNavigationColor(bottom_navigation_view) |
|
|
|
ATH.applyBottomNavigationColor(bottom_navigation_view) |
|
|
@ -80,9 +83,26 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onPageSelected(position: Int) { |
|
|
|
override fun onPageSelected(position: Int) { |
|
|
|
|
|
|
|
pagePosition = position |
|
|
|
bottom_navigation_view.menu.getItem(position).isChecked = true |
|
|
|
bottom_navigation_view.menu.getItem(position).isChecked = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { |
|
|
|
|
|
|
|
event?.let { |
|
|
|
|
|
|
|
when (keyCode) { |
|
|
|
|
|
|
|
KeyEvent.KEYCODE_BACK -> if ( |
|
|
|
|
|
|
|
pagePosition != 0 |
|
|
|
|
|
|
|
&& event.isTracking |
|
|
|
|
|
|
|
&& !event.isCanceled |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
view_pager_main.currentItem = 0 |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return super.onKeyUp(keyCode, event) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : |
|
|
|
private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : |
|
|
|
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { |
|
|
|
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { |
|
|
|
|
|
|
|
|
|
|
@ -98,6 +118,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), |
|
|
|
override fun getCount(): Int { |
|
|
|
override fun getCount(): Int { |
|
|
|
return 4 |
|
|
|
return 4 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun observeLiveBus() { |
|
|
|
override fun observeLiveBus() { |
|
|
|