File tree Expand file tree Collapse file tree 8 files changed +56
-18
lines changed
app/src/main/java/com/donnfelker/android/bootstrap Expand file tree Collapse file tree 8 files changed +56
-18
lines changed Original file line number Diff line number Diff line change 1818public class BootstrapApplication extends Application {
1919
2020private static BootstrapApplication instance ;
21- ObjectGraph objectGraph ;
2221
2322/**
2423 * Create main application
@@ -46,10 +45,9 @@ public void onCreate(){
4645super .onCreate ();
4746
4847instance = this ;
49- // Perform Injection
50- objectGraph = ObjectGraph .create (getRootModule ());
51- objectGraph .inject (this );
52- objectGraph .injectStatics ();
48+
49+ // Perform injection
50+ Injector .init (getRootModule (), this );
5351
5452 }
5553
@@ -68,13 +66,6 @@ public BootstrapApplication(final Instrumentation instrumentation){
6866attachBaseContext (instrumentation .getTargetContext ());
6967 }
7068
71- public void inject (Object object )
72- {
73- objectGraph .inject (object );
74- }
75-
76-
77-
7869public static BootstrapApplication getInstance (){
7970return instance ;
8071 }
Original file line number Diff line number Diff line change 1+ package com .donnfelker .android .bootstrap ;
2+
3+ import dagger .ObjectGraph ;
4+
5+ public final class Injector
6+ {
7+ public static ObjectGraph objectGraph = null ;
8+
9+
10+ public static void init (final Object rootModule ){
11+
12+ if (objectGraph == null )
13+ {
14+ objectGraph = ObjectGraph .create (rootModule );
15+ }
16+ else
17+ {
18+ objectGraph = objectGraph .plus (rootModule );
19+ }
20+
21+ // Inject statics
22+ objectGraph .injectStatics ();
23+
24+ }
25+
26+ public static void init (final Object rootModule , final Object target )
27+ {
28+ init (rootModule );
29+ inject (target );
30+ }
31+
32+ public static final void inject (final Object target )
33+ {
34+ objectGraph .inject (target );
35+ }
36+
37+ public static <T > T resolve (Class <T > type )
38+ {
39+ return objectGraph .get (type );
40+ }
41+ }
Original file line number Diff line number Diff line change 1212import android .support .v4 .app .NotificationCompat ;
1313
1414import com .donnfelker .android .bootstrap .BootstrapApplication ;
15+ import com .donnfelker .android .bootstrap .Injector ;
1516import com .donnfelker .android .bootstrap .R ;
1617import com .donnfelker .android .bootstrap .ui .BootstrapTimerActivity ;
1718import javax .inject .Inject ;
@@ -46,7 +47,7 @@ public IBinder onBind(Intent intent){
4647public void onCreate (){
4748super .onCreate ();
4849
49- BootstrapApplication . getInstance () .inject (this );
50+ Injector .inject (this );
5051
5152// Register the bus so we can send notifications.
5253BUS .register (this );
Original file line number Diff line number Diff line change 88import com .actionbarsherlock .app .SherlockActivity ;
99import com .actionbarsherlock .view .MenuItem ;
1010import com .donnfelker .android .bootstrap .BootstrapApplication ;
11+ import com .donnfelker .android .bootstrap .Injector ;
1112
1213import butterknife .Views ;
1314
@@ -20,7 +21,7 @@ public abstract class BootstrapActivity extends SherlockActivity{
2021protected void onCreate (Bundle savedInstanceState ){
2122super .onCreate (savedInstanceState );
2223
23- BootstrapApplication . getInstance () .inject (this );
24+ Injector .inject (this );
2425 }
2526
2627@ Override
Original file line number Diff line number Diff line change 44
55import com .actionbarsherlock .app .SherlockFragmentActivity ;
66import com .donnfelker .android .bootstrap .BootstrapApplication ;
7+ import com .donnfelker .android .bootstrap .Injector ;
78
89import butterknife .Views ;
910
@@ -16,7 +17,7 @@ public class BootstrapFragmentActivity extends SherlockFragmentActivity{
1617protected void onCreate (Bundle savedInstanceState ){
1718super .onCreate (savedInstanceState );
1819
19- BootstrapApplication . getInstance () .inject (this );
20+ Injector .inject (this );
2021 }
2122
2223@ Override
Original file line number Diff line number Diff line change 1111
1212import com .donnfelker .android .bootstrap .BootstrapApplication ;
1313import com .donnfelker .android .bootstrap .BootstrapServiceProvider ;
14+ import com .donnfelker .android .bootstrap .Injector ;
1415import com .donnfelker .android .bootstrap .R ;
1516import com .donnfelker .android .bootstrap .authenticator .LogoutService ;
1617import com .donnfelker .android .bootstrap .core .CheckIn ;
@@ -29,7 +30,7 @@ public class CheckInsListFragment extends ItemListFragment<CheckIn>{
2930@ Override
3031public void onCreate (Bundle savedInstanceState ){
3132super .onCreate (savedInstanceState );
32- BootstrapApplication . getInstance () .inject (this );
33+ Injector .inject (this );
3334 }
3435
3536@ Override
Original file line number Diff line number Diff line change 1111
1212import com .donnfelker .android .bootstrap .BootstrapApplication ;
1313import com .donnfelker .android .bootstrap .BootstrapServiceProvider ;
14+ import com .donnfelker .android .bootstrap .Injector ;
1415import com .donnfelker .android .bootstrap .R ;
1516import com .donnfelker .android .bootstrap .authenticator .LogoutService ;
1617import com .donnfelker .android .bootstrap .core .News ;
@@ -29,7 +30,7 @@ public class NewsListFragment extends ItemListFragment<News>{
2930@ Override
3031public void onCreate (Bundle savedInstanceState ){
3132super .onCreate (savedInstanceState );
32- BootstrapApplication . getInstance () .inject (this );
33+ Injector .inject (this );
3334 }
3435
3536@ Override
Original file line number Diff line number Diff line change 1212
1313import com .donnfelker .android .bootstrap .BootstrapApplication ;
1414import com .donnfelker .android .bootstrap .BootstrapServiceProvider ;
15+ import com .donnfelker .android .bootstrap .Injector ;
1516import com .donnfelker .android .bootstrap .R ;
1617import com .donnfelker .android .bootstrap .authenticator .LogoutService ;
1718import com .donnfelker .android .bootstrap .core .AvatarLoader ;
@@ -33,7 +34,7 @@ public class UserListFragment extends ItemListFragment<User>{
3334@ Override
3435public void onCreate (Bundle savedInstanceState ){
3536super .onCreate (savedInstanceState );
36- BootstrapApplication . getInstance () .inject (this );
37+ Injector .inject (this );
3738 }
3839
3940@ Override
You can’t perform that action at this time.
0 commit comments