forked from GitHub-Mirror/riotX-android
Dagger: inject dependencies earlier into activity/fragment
This commit is contained in:
parent
3960742f38
commit
4739aea793
@ -117,11 +117,11 @@ abstract class VectorBaseActivity : BaseMvRxActivity(), HasScreenInjector {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
screenComponent = DaggerScreenComponent.factory().create(getVectorComponent(), this)
|
||||
super.onCreate(savedInstanceState)
|
||||
val timeForInjection = measureTimeMillis {
|
||||
injectWith(screenComponent)
|
||||
}
|
||||
Timber.v("Injecting dependencies into ${javaClass.simpleName} took $timeForInjection ms")
|
||||
super.onCreate(savedInstanceState)
|
||||
viewModelFactory = screenComponent.viewModelFactory()
|
||||
configurationViewModel = ViewModelProviders.of(this, viewModelFactory).get(ConfigurationViewModel::class.java)
|
||||
bugReporter = screenComponent.bugReporter()
|
||||
|
@ -65,10 +65,10 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed, HasScreen
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
screenComponent = DaggerScreenComponent.factory().create(vectorBaseActivity.getVectorComponent(), vectorBaseActivity)
|
||||
super.onAttach(context)
|
||||
navigator = vectorBaseActivity.getVectorComponent().navigator()
|
||||
viewModelFactory = screenComponent.viewModelFactory()
|
||||
injectWith(injector())
|
||||
super.onAttach(context)
|
||||
}
|
||||
|
||||
protected open fun injectWith(injector: ScreenComponent) = Unit
|
||||
|
Loading…
Reference in New Issue
Block a user