Skip to content

Commit

Permalink
Switches for HasSupportFragmentInjector and HasFragmentInjector
Browse files Browse the repository at this point in the history
  • Loading branch information
bhm authored and Kuzniarski Jacek committed Oct 13, 2017
1 parent 457a499 commit 9b7cd60
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@
suggest="${applicationPackage}"
help="Path to .R of this app/module" />

<parameter
id="useApplicationComponent"
name="Use ApplicationComponent"
type="boolean"
default="true"
help="If true, ApplicationComponent will be used in generated Graph" />

<parameter
id="appComponentPackage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ import ${relativePackage}.di.Dagger${componentClass}
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
<#if addDispatchingFragmentInjector>
import android.app.Fragment
import dagger.android.HasFragmentInjector
</#if>
<#if addDispatchingSupportFragmentInjector>
import dagger.android.support.HasSupportFragmentInjector
import android.support.v4.app.Fragment as SupportFragment
</#if>
import javax.inject.Inject

class ${applicationClass} : Application(), HasActivityInjector {
class ${applicationClass} : Application(), HasActivityInjector<#if addDispatchingFragmentInjector>, HasFragmentInjector</#if><#if addDispatchingSupportFragmentInjector>, HasSupportFragmentInjector</#if> {

@Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@Inject lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity>
<#if addDispatchingFragmentInjector>
@Inject lateinit var dispatchingFragmentInjector: DispatchingAndroidInjector<Fragment>
</#if>
<#if addDispatchingSupportFragmentInjector>
@Inject lateinit var dispatchingSupportFragmentInjector: DispatchingAndroidInjector<SupportFragment>
</#if>

override fun onCreate() {
super.onCreate()
Expand All @@ -20,5 +34,14 @@ class ${applicationClass} : Application(), HasActivityInjector {
.inject(this)
}

override fun activityInjector(): AndroidInjector<Activity> = dispatchingAndroidInjector
override fun activityInjector(): AndroidInjector<Activity> = dispatchingActivityInjector
<#if addDispatchingFragmentInjector>

override fun fragmentInjector(): AndroidInjector<Fragment> = dispatchingFragmentInjector
</#if>
<#if addDispatchingSupportFragmentInjector>

override fun supportFragmentInjector(): AndroidInjector<SupportFragment> = dispatchingSupportFragmentInjector
</#if>

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
type="string"
visibility="useApplicationComponent"/>

<parameter
name="with HasSupportFragmentInjector"
default="true"
help="Adds HasSupportFragmentInjector and logic for injecting support Fragments"
id="addDispatchingSupportFragmentInjector"
type="boolean"/>

<parameter
name="With HasFragmentInjector"
default="false"
help="Adds HasFragmentInjector and logic for injecting Fragments"
id="addDispatchingFragmentInjector"
type="boolean"/>

<thumbs>
<thumb>ifmdagger.png</thumb>
</thumbs>
Expand Down
Binary file modified android-studio-plugin/template_usecause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import com.infullmobile.android.infullmvp.sample_dagger21x.application.di.Dagger
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import dagger.android.HasFragmentInjector
import dagger.android.support.HasSupportFragmentInjector
import android.support.v4.app.Fragment as SupportFragment
import javax.inject.Inject

class SampleApp : Application(), HasActivityInjector {
class SampleApp : Application(), HasActivityInjector, HasSupportFragmentInjector, HasFragmentInjector {

@Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@Inject lateinit var dispatchingSupportFragmentInjector: DispatchingAndroidInjector<SupportFragment>
@Inject lateinit var dispatchingFragmentInjector: DispatchingAndroidInjector<android.app.Fragment>

override fun onCreate() {
super.onCreate()
Expand All @@ -22,4 +27,8 @@ class SampleApp : Application(), HasActivityInjector {

override fun activityInjector(): AndroidInjector<Activity> = dispatchingAndroidInjector

override fun fragmentInjector(): AndroidInjector<android.app.Fragment> = dispatchingFragmentInjector

override fun supportFragmentInjector(): AndroidInjector<SupportFragment> = dispatchingSupportFragmentInjector

}

0 comments on commit 9b7cd60

Please sign in to comment.