Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switches for HasSupportFragmentInjector and HasFragmentInjector #43

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,14 @@ 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.support.HasSupportFragmentInjector
import javax.inject.Inject
import android.support.v4.app.Fragment as SupportFragment

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

@Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@Inject lateinit var dispatchingSupportFragmentInjector: DispatchingAndroidInjector<SupportFragment>

override fun onCreate() {
super.onCreate()
Expand All @@ -21,5 +24,6 @@ class SampleApp : Application(), HasActivityInjector {
}

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

}