File tree 8 files changed +56
-18
lines changed
app/src/main/java/com/donnfelker/android/bootstrap
8 files changed +56
-18
lines changed Original file line number Diff line number Diff line change 18
18
public class BootstrapApplication extends Application {
19
19
20
20
private static BootstrapApplication instance ;
21
- ObjectGraph objectGraph ;
22
21
23
22
/**
24
23
* Create main application
@@ -46,10 +45,9 @@ public void onCreate() {
46
45
super .onCreate ();
47
46
48
47
instance = 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 );
53
51
54
52
}
55
53
@@ -68,13 +66,6 @@ public BootstrapApplication(final Instrumentation instrumentation) {
68
66
attachBaseContext (instrumentation .getTargetContext ());
69
67
}
70
68
71
- public void inject (Object object )
72
- {
73
- objectGraph .inject (object );
74
- }
75
-
76
-
77
-
78
69
public static BootstrapApplication getInstance () {
79
70
return instance ;
80
71
}
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 12
12
import android .support .v4 .app .NotificationCompat ;
13
13
14
14
import com .donnfelker .android .bootstrap .BootstrapApplication ;
15
+ import com .donnfelker .android .bootstrap .Injector ;
15
16
import com .donnfelker .android .bootstrap .R ;
16
17
import com .donnfelker .android .bootstrap .ui .BootstrapTimerActivity ;
17
18
import javax .inject .Inject ;
@@ -46,7 +47,7 @@ public IBinder onBind(Intent intent) {
46
47
public void onCreate () {
47
48
super .onCreate ();
48
49
49
- BootstrapApplication . getInstance () .inject (this );
50
+ Injector .inject (this );
50
51
51
52
// Register the bus so we can send notifications.
52
53
BUS .register (this );
Original file line number Diff line number Diff line change 8
8
import com .actionbarsherlock .app .SherlockActivity ;
9
9
import com .actionbarsherlock .view .MenuItem ;
10
10
import com .donnfelker .android .bootstrap .BootstrapApplication ;
11
+ import com .donnfelker .android .bootstrap .Injector ;
11
12
12
13
import butterknife .Views ;
13
14
@@ -20,7 +21,7 @@ public abstract class BootstrapActivity extends SherlockActivity {
20
21
protected void onCreate (Bundle savedInstanceState ) {
21
22
super .onCreate (savedInstanceState );
22
23
23
- BootstrapApplication . getInstance () .inject (this );
24
+ Injector .inject (this );
24
25
}
25
26
26
27
@ Override
Original file line number Diff line number Diff line change 4
4
5
5
import com .actionbarsherlock .app .SherlockFragmentActivity ;
6
6
import com .donnfelker .android .bootstrap .BootstrapApplication ;
7
+ import com .donnfelker .android .bootstrap .Injector ;
7
8
8
9
import butterknife .Views ;
9
10
@@ -16,7 +17,7 @@ public class BootstrapFragmentActivity extends SherlockFragmentActivity {
16
17
protected void onCreate (Bundle savedInstanceState ) {
17
18
super .onCreate (savedInstanceState );
18
19
19
- BootstrapApplication . getInstance () .inject (this );
20
+ Injector .inject (this );
20
21
}
21
22
22
23
@ Override
Original file line number Diff line number Diff line change 11
11
12
12
import com .donnfelker .android .bootstrap .BootstrapApplication ;
13
13
import com .donnfelker .android .bootstrap .BootstrapServiceProvider ;
14
+ import com .donnfelker .android .bootstrap .Injector ;
14
15
import com .donnfelker .android .bootstrap .R ;
15
16
import com .donnfelker .android .bootstrap .authenticator .LogoutService ;
16
17
import com .donnfelker .android .bootstrap .core .CheckIn ;
@@ -29,7 +30,7 @@ public class CheckInsListFragment extends ItemListFragment<CheckIn> {
29
30
@ Override
30
31
public void onCreate (Bundle savedInstanceState ) {
31
32
super .onCreate (savedInstanceState );
32
- BootstrapApplication . getInstance () .inject (this );
33
+ Injector .inject (this );
33
34
}
34
35
35
36
@ Override
Original file line number Diff line number Diff line change 11
11
12
12
import com .donnfelker .android .bootstrap .BootstrapApplication ;
13
13
import com .donnfelker .android .bootstrap .BootstrapServiceProvider ;
14
+ import com .donnfelker .android .bootstrap .Injector ;
14
15
import com .donnfelker .android .bootstrap .R ;
15
16
import com .donnfelker .android .bootstrap .authenticator .LogoutService ;
16
17
import com .donnfelker .android .bootstrap .core .News ;
@@ -29,7 +30,7 @@ public class NewsListFragment extends ItemListFragment<News> {
29
30
@ Override
30
31
public void onCreate (Bundle savedInstanceState ) {
31
32
super .onCreate (savedInstanceState );
32
- BootstrapApplication . getInstance () .inject (this );
33
+ Injector .inject (this );
33
34
}
34
35
35
36
@ Override
Original file line number Diff line number Diff line change 12
12
13
13
import com .donnfelker .android .bootstrap .BootstrapApplication ;
14
14
import com .donnfelker .android .bootstrap .BootstrapServiceProvider ;
15
+ import com .donnfelker .android .bootstrap .Injector ;
15
16
import com .donnfelker .android .bootstrap .R ;
16
17
import com .donnfelker .android .bootstrap .authenticator .LogoutService ;
17
18
import com .donnfelker .android .bootstrap .core .AvatarLoader ;
@@ -33,7 +34,7 @@ public class UserListFragment extends ItemListFragment<User> {
33
34
@ Override
34
35
public void onCreate (Bundle savedInstanceState ) {
35
36
super .onCreate (savedInstanceState );
36
- BootstrapApplication . getInstance () .inject (this );
37
+ Injector .inject (this );
37
38
}
38
39
39
40
@ Override
You can’t perform that action at this time.
0 commit comments