Skip to content

Commit

Permalink
dagger2 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-dev committed Mar 11, 2016
1 parent c1304a9 commit e9417c5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -7,6 +7,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
classpath 'me.tatarka:gradle-retrolambda:3.3.0-beta3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}

Expand Down
5 changes: 5 additions & 0 deletions sample/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion 23
Expand Down Expand Up @@ -31,4 +32,8 @@ dependencies {
testCompile 'junit:junit:4.12'
compile project(':library')
compile 'com.android.support:appcompat-v7:23.1.1'

compile 'com.google.dagger:dagger:2.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'
provided 'javax.annotation:jsr250-api:1.0'
}
3 changes: 2 additions & 1 deletion sample/src/main/AndroidManifest.xml
Expand Up @@ -10,7 +10,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:name=".di.App">
<activity android:name="cz.kinst.jakub.sample.viewmodelbinding.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
@@ -0,0 +1,14 @@
package cz.kinst.jakub.sample.viewmodelbinding.di;

import android.app.Application;

public class App extends Application {
public static MainComponent mainComponent;

@Override
public void onCreate() {
super.onCreate();

mainComponent = DaggerMainComponent.builder().appModule(new AppModule(this)).build();
}
}
@@ -0,0 +1,23 @@
package cz.kinst.jakub.sample.viewmodelbinding.di;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

@Module
public class AppModule {

private App app;


public AppModule(App app) {
this.app = app;
}

@Provides
@Singleton
public App provideApp() {
return app;
}
}
@@ -0,0 +1,16 @@
package cz.kinst.jakub.sample.viewmodelbinding.di;

import javax.inject.Singleton;

import cz.kinst.jakub.sample.viewmodelbinding.MainViewModel;
import dagger.Component;

@Singleton
@Component(
modules = {
AppModule.class
}
)
public interface MainComponent {
void inject(MainViewModel obj);
}
2 changes: 1 addition & 1 deletion settings.gradle
@@ -1 +1 @@
include ':sample', ':library', ':library-extensions'
include ':sample', ':library'/*, ':library-extensions'*/

0 comments on commit e9417c5

Please sign in to comment.