Created
March 30, 2015 22:01
-
-
Save frogermcs/709651d65dafe8e62378 to your computer and use it in GitHub Desktop.
Sources for Dagger 1 -> 2 migration process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Scope | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface ActivityScope { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App extends Application { | |
private AppComponent component; | |
@Inject | |
AnalyticsManager analyticsManager; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
setupGraph(); | |
analyticsManager.registerAppEnter(); | |
} | |
private void setupGraph() { | |
component = Dagger_AppComponent.builder() | |
.appModule(new AppModule(this)) | |
.build(); | |
component.inject(this); | |
} | |
public AppComponent component() { | |
return component; | |
} | |
public static App get(Context context) { | |
return (App) context.getApplicationContext(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'com.neenbedankt.android-apt' | |
android { | |
compileSdkVersion 22 | |
buildToolsVersion "22.0.1" | |
defaultConfig { | |
minSdkVersion 14 | |
targetSdkVersion 22 | |
versionCode 1 | |
versionName "1.0" | |
} | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_7 | |
targetCompatibility JavaVersion.VERSION_1_7 | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' | |
} | |
} | |
} | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
compile 'com.google.dagger:dagger:2.0-SNAPSHOT' | |
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT' | |
provided 'org.glassfish:javax.annotation:10.0-b28' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component( | |
modules = { | |
AppModule.class, | |
DomainModule.class, | |
InteractorsModule.class | |
} | |
) | |
public interface AppComponent { | |
void inject(App app); | |
AnalyticsManager getAnalyticsManager(); | |
LoginInteractor getLoginInteractor(); | |
FindItemsInteractor getFindItemsInteractor(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module( | |
injects = { | |
App.class | |
}, | |
includes = { | |
DomainModule.class, | |
InteractorsModule.class | |
} | |
) | |
public class AppModule { | |
private App app; | |
public AppModule(App app) { | |
this.app = app; | |
} | |
@Provides public Application provideApplication() { | |
return app; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class AppModule { | |
private App app; | |
public AppModule(App app) { | |
this.app = app; | |
} | |
@Provides public Application provideApplication() { | |
return app; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:1.1.3' | |
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' | |
} | |
} | |
allprojects { | |
repositories { | |
mavenCentral() | |
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ActivityScope | |
@Component( | |
dependencies = AppComponent.class, | |
modules = LoginModule.class | |
) | |
public interface LoginComponent { | |
void inject(LoginActivity activity); | |
LoginPresenter getLoginPresenter(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ActivityScope | |
@Component( | |
dependencies = AppComponent.class, | |
modules = MainModule.class | |
) | |
public interface MainComponent { | |
void inject(MainActivity activity); | |
MainPresenter getLoginPresenter(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void setupComponent(AppComponent appComponent) { | |
Dagger_MainComponent.builder() | |
.appComponent(appComponent) | |
.mainModule(new MainModule(this)) | |
.build() | |
.inject(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment