Move setContentView out of onCreate

This commit is contained in:
topjohnwu
2020-09-11 02:31:41 -07:00
parent e66b0bf3b2
commit d7f7508fa2
5 changed files with 28 additions and 32 deletions
@@ -48,6 +48,9 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(themeRes)
super.onCreate(savedInstanceState)
startObserveEvents()
// We need to set the window background explicitly since for whatever reason it's not
// propagated upstream
@@ -55,16 +58,6 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
.use { it.getDrawable(0) }
.also { window.setBackgroundDrawable(it) }
super.onCreate(savedInstanceState)
startObserveEvents()
binding = DataBindingUtil.setContentView<Binding>(this, layoutRes).also {
it.setVariable(BR.viewModel, viewModel)
it.lifecycleOwner = this
}
ensureInsets()
directionsDispatcher.observe(this) {
it?.navigate()
// we don't want the directions to be re-dispatched, so we preemptively set them to null
@@ -74,6 +67,15 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
}
}
fun setContentView() {
binding = DataBindingUtil.setContentView<Binding>(this, layoutRes).also {
it.setVariable(BR.viewModel, viewModel)
it.lifecycleOwner = this
}
ensureInsets()
}
override fun onResume() {
super.onResume()
viewModel.requestRefresh()