Dagger: inject dependencies earlier into activity/fragment

This commit is contained in:
ganfra 2019-07-01 11:41:27 +02:00
parent 3960742f38
commit 4739aea793
2 changed files with 2 additions and 2 deletions

View File

@ -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()

View File

@ -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