Created
January 19, 2015 09:24
-
-
Save wuman/4319fb4f7760d266677c to your computer and use it in GitHub Desktop.
Dagger2 example fix
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
diff --git a/compiler/pom.xml b/compiler/pom.xml | |
index 8c67461..26b612c 100644 | |
--- a/compiler/pom.xml | |
+++ b/compiler/pom.xml | |
@@ -57,7 +57,6 @@ | |
<dependency> | |
<groupId>com.google.auto.value</groupId> | |
<artifactId>auto-value</artifactId> | |
- <version>1.0-SNAPSHOT</version> | |
<optional>true</optional> | |
</dependency> | |
diff --git a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/AbstractActivityComponent.java b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/AbstractActivityComponent.java | |
index 71afde1..b708d69 100644 | |
--- a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/AbstractActivityComponent.java | |
+++ b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/AbstractActivityComponent.java | |
@@ -23,8 +23,8 @@ import dagger.Component; | |
* A base component upon which fragment's components may depend. Activity-level components | |
* should extend this component. | |
*/ | |
-// @PerActivity - Subtypes of ActivityComponent should be decorated with @PerActivity | |
+@PerActivity //- Subtypes of ActivityComponent should be decorated with @PerActivity | |
@Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class) | |
-public interface AbstractDemoActivityComponent { | |
+public interface AbstractActivityComponent { | |
Activity activity(); // Expose the activity to sub-graphs. | |
} | |
diff --git a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/DemoApplication.java b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/DemoApplication.java | |
index 2b65da6..d3367a0 100644 | |
--- a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/DemoApplication.java | |
+++ b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/DemoApplication.java | |
@@ -28,11 +28,11 @@ public class DemoApplication extends Application { | |
@Override public void onCreate() { | |
super.onCreate(); | |
applicationComponent = Dagger_ApplicationComponent.builder() | |
- .androidModule(new DemoApplicationModule(this)) | |
+ .demoApplicationModule(new DemoApplicationModule(this)) | |
.build(); | |
} | |
- ApplicationComponent component() { | |
+ public ApplicationComponent component() { | |
return applicationComponent; | |
} | |
} | |
diff --git a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeActivity.java b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeActivity.java | |
index dd939d3..f0bd878 100644 | |
--- a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeActivity.java | |
+++ b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeActivity.java | |
@@ -17,22 +17,28 @@ package com.example.dagger.activitygraphs.ui; | |
import android.location.LocationManager; | |
import android.os.Bundle; | |
+import android.support.v4.app.FragmentActivity; | |
+import com.example.dagger.activitygraphs.ActivityModule; | |
+import com.example.dagger.activitygraphs.DemoApplication; | |
import javax.inject.Inject; | |
-public class HomeActivity extends Activity { | |
+public class HomeActivity extends FragmentActivity { | |
@Inject LocationManager locationManager; | |
+ private HomeComponent component; | |
- @Override HomeComponent initComponent() { | |
+ HomeComponent component() { | |
+ if (component == null) { | |
+ component = Dagger_HomeComponent.builder() | |
+ .applicationComponent(((DemoApplication) getApplication()).component()) | |
+ .activityModule(new ActivityModule(this)) | |
+ .build(); | |
+ } | |
return component; | |
} | |
@Override protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
- Dagger_HomeActivity$HomeComponent.builder() | |
- .applicationComponent(((DemoApplication) getApplication()).component()) | |
- .activityModule(new ActivityModule(this)) | |
- .build() | |
- .inject(this); | |
+ component().inject(this); | |
if (savedInstanceState == null) { | |
getSupportFragmentManager().beginTransaction() | |
diff --git a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeFragment.java b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeFragment.java | |
index 0cef1a0..1df2724 100644 | |
--- a/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeFragment.java | |
+++ b/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeFragment.java | |
@@ -30,7 +30,7 @@ public class HomeFragment extends Fragment { | |
@Override public void onActivityCreated(Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
- ((AbstractDemoActivity) getActivity()).inject(this); | |
+ ((HomeActivity) getActivity()).component().inject(this); | |
} | |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
diff --git a/examples/pom.xml b/examples/pom.xml | |
index 530438c..66807d0 100644 | |
--- a/examples/pom.xml | |
+++ b/examples/pom.xml | |
@@ -31,6 +31,8 @@ | |
<modules> | |
<module>simple</module> | |
+ <module>android-simple</module> | |
+ <module>android-activity-graphs</module> | |
</modules> | |
<!-- Travis CI currently has a problem building Android so we disable this profile --> | |
diff --git a/pom.xml b/pom.xml | |
index 9db58a1..9c172b7 100644 | |
--- a/pom.xml | |
+++ b/pom.xml | |
@@ -45,7 +45,7 @@ | |
<javawriter.version>2.5.0</javawriter.version> | |
<auto.common.version>1.0-SNAPSHOT</auto.common.version> | |
<auto.service.version>1.0-rc1</auto.service.version> | |
- <auto.value.version>1.0-SNAPSHOT</auto.value.version> | |
+ <auto.value.version>1.0</auto.value.version> | |
<guava.version>18.0</guava.version> | |
<!-- Test Dependencies --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment