pull/32/head
gedoor 6 years ago
parent 5b8ad639d8
commit 292fb1edd2
  1. 9
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -28,6 +28,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(layoutID) setContentView(layoutID)
onViewModelCreated(viewModel, savedInstanceState) onViewModelCreated(viewModel, savedInstanceState)
observeLiveBus()
} }
abstract fun onViewModelCreated(viewModel: VM, savedInstanceState: Bundle?) abstract fun onViewModelCreated(viewModel: VM, savedInstanceState: Bundle?)
@ -59,7 +60,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
protected fun initTheme() { private fun initTheme() {
window.decorView.setBackgroundColor(ThemeStore.backgroundColor(this)) window.decorView.setBackgroundColor(ThemeStore.backgroundColor(this))
if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) { if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) {
setTheme(R.style.AppTheme_Light) setTheme(R.style.AppTheme_Light)
@ -68,7 +69,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
} }
} }
protected fun setupSystemBar() { private fun setupSystemBar() {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
@ -78,4 +79,8 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
window.statusBarColor = getCompatColor(R.color.status_bar_bag) window.statusBarColor = getCompatColor(R.color.status_bar_bag)
} }
} }
open fun observeLiveBus() {
}
} }

@ -36,7 +36,6 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager) view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager)
view_pager_main.addOnPageChangeListener(this) view_pager_main.addOnPageChangeListener(this)
bottom_navigation_view.setOnNavigationItemSelectedListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this)
observeLiveBus()
} }
override fun onNavigationItemSelected(item: MenuItem): Boolean { override fun onNavigationItemSelected(item: MenuItem): Boolean {
@ -87,7 +86,7 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
} }
} }
private fun observeLiveBus() { override fun observeLiveBus() {
LiveEventBus.get().with("recreate", String::class.java) LiveEventBus.get().with("recreate", String::class.java)
.observe(this, Observer { .observe(this, Observer {
recreate() recreate()

Loading…
Cancel
Save