Skip to content

Commit 883a333

Browse files
committed
Attempting to perform injections on bootstrap entry points
1 parent 38714c5 commit 883a333

File tree

9 files changed

+56
-7
lines changed

9 files changed

+56
-7
lines changed

app/src/main/java/com/donnfelker/android/bootstrap/BootstrapApplication.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010

1111
import com.github.kevinsawicki.http.HttpRequest;
1212

13+
import dagger.ObjectGraph;
14+
1315
/**
1416
* Android Bootstrap application
1517
*/
1618
public class BootstrapApplication extends Application {
1719

1820
private static BootstrapApplication instance;
21+
ObjectGraph objectGraph;
1922

2023
/**
2124
* Create main application
2225
*/
2326
public BootstrapApplication() {
2427

25-
instance = this;
26-
2728
// Disable http.keepAlive on Froyo and below
2829
if (SDK_INT <= FROYO)
2930
HttpRequest.keepAlive(false);
@@ -37,8 +38,24 @@ public BootstrapApplication() {
3738
public BootstrapApplication(final Context context) {
3839
this();
3940
attachBaseContext(context);
41+
4042
}
4143

44+
@Override
45+
public void onCreate() {
46+
super.onCreate();
47+
48+
instance = this;
49+
// Perform Injection
50+
objectGraph = ObjectGraph.create(getRootModule());
51+
objectGraph.inject(this);
52+
objectGraph.injectStatics();
53+
54+
}
55+
56+
private Object getRootModule() {
57+
return new RootModule();
58+
}
4259

4360

4461
/**
@@ -51,6 +68,12 @@ public BootstrapApplication(final Instrumentation instrumentation) {
5168
attachBaseContext(instrumentation.getTargetContext());
5269
}
5370

71+
public void inject(Object object)
72+
{
73+
objectGraph.inject(object);
74+
}
75+
76+
5477

5578
public static BootstrapApplication getInstance() {
5679
return instance;

app/src/main/java/com/donnfelker/android/bootstrap/BootstrapModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.accounts.AccountManager;
44
import android.content.Context;
55

6+
import com.donnfelker.android.bootstrap.authenticator.BootstrapAuthenticatorActivity;
67
import com.donnfelker.android.bootstrap.authenticator.LogoutService;
78
import com.donnfelker.android.bootstrap.core.CheckIn;
89
import com.donnfelker.android.bootstrap.ui.BootstrapTimerActivity;
@@ -30,6 +31,7 @@
3031

3132
entryPoints = {
3233
BootstrapApplication.class,
34+
BootstrapAuthenticatorActivity.class,
3335
CarouselActivity.class,
3436
BootstrapTimerActivity.class,
3537
CheckInsListFragment.class,
@@ -45,9 +47,7 @@ public class BootstrapModule {
4547
@Singleton
4648
@Provides
4749
Bus provideOttoBus() {
48-
4950
return new Bus();
50-
5151
}
5252

5353
@Provides

app/src/main/java/com/donnfelker/android/bootstrap/core/TimerService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.os.SystemClock;
1212
import android.support.v4.app.NotificationCompat;
1313

14+
import com.donnfelker.android.bootstrap.BootstrapApplication;
1415
import com.donnfelker.android.bootstrap.R;
1516
import com.donnfelker.android.bootstrap.ui.BootstrapTimerActivity;
1617
import javax.inject.Inject;
@@ -45,6 +46,8 @@ public IBinder onBind(Intent intent) {
4546
public void onCreate() {
4647
super.onCreate();
4748

49+
BootstrapApplication.getInstance().inject(this);
50+
4851
// Register the bus so we can send notifications.
4952
BUS.register(this);
5053

app/src/main/java/com/donnfelker/android/bootstrap/ui/BootstrapFragmentActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.donnfelker.android.bootstrap.ui;
22

33
import com.actionbarsherlock.app.SherlockFragmentActivity;
4+
import com.donnfelker.android.bootstrap.BootstrapApplication;
45

56
import butterknife.Views;
67

@@ -14,6 +15,8 @@ public void setContentView(int layoutResId) {
1415
super.setContentView(layoutResId);
1516

1617
// Perform view injection via butter knife
17-
Views.inject(this);
18+
// Doesnt seem like you can inject via a super class. Throws method not found.
19+
//Views.inject(this);
20+
BootstrapApplication.getInstance().inject(this);
1821
}
1922
}

app/src/main/java/com/donnfelker/android/bootstrap/ui/BootstrapTimerActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
import com.squareup.otto.Subscribe;
2121

2222
import butterknife.InjectView;
23+
import butterknife.Views;
2324

2425
public class BootstrapTimerActivity extends BootstrapFragmentActivity implements View.OnClickListener {
2526

26-
@Inject protected Bus BUS;
27+
@Inject Bus BUS;
2728

2829
@InjectView(R.id.chronometer) protected TextView chronometer;
2930
@InjectView(R.id.start) protected Button start;
@@ -37,6 +38,8 @@ protected void onCreate(Bundle savedInstanceState) {
3738

3839
setContentView(R.layout.bootstrap_timer);
3940

41+
Views.inject(this);
42+
4043
setTitle(R.string.timer);
4144

4245
start.setOnClickListener(this);

app/src/main/java/com/donnfelker/android/bootstrap/ui/CarouselActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.viewpagerindicator.TitlePageIndicator;
1818

1919
import butterknife.InjectView;
20+
import butterknife.Views;
2021

2122
/**
2223
* Activity to view the carousel and view pager indicator with fragments.
@@ -34,6 +35,8 @@ protected void onCreate(Bundle savedInstanceState) {
3435
super.onCreate(savedInstanceState);
3536
setContentView(R.layout.carousel_view);
3637

38+
Views.inject(this);
39+
3740
pager.setAdapter(new BootstrapPagerAdapter(getResources(), getSupportFragmentManager()));
3841

3942
indicator.setViewPager(pager);

app/src/main/java/com/donnfelker/android/bootstrap/ui/CheckInsListFragment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.view.View;
1010
import android.widget.ListView;
1111

12+
import com.donnfelker.android.bootstrap.BootstrapApplication;
1213
import com.donnfelker.android.bootstrap.BootstrapServiceProvider;
1314
import com.donnfelker.android.bootstrap.R;
1415
import com.donnfelker.android.bootstrap.authenticator.LogoutService;
@@ -25,6 +26,13 @@ public class CheckInsListFragment extends ItemListFragment<CheckIn> {
2526
@Inject protected BootstrapServiceProvider serviceProvider;
2627
@Inject protected LogoutService logoutService;
2728

29+
@Override
30+
public void onActivityCreated(Bundle savedInstanceState) {
31+
super.onActivityCreated(savedInstanceState);
32+
33+
BootstrapApplication.getInstance().inject(this);
34+
}
35+
2836
@Override
2937
protected void configureList(Activity activity, ListView listView) {
3038
super.configureList(activity, listView);

app/src/main/java/com/donnfelker/android/bootstrap/ui/NewsListFragment.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.view.View;
1010
import android.widget.ListView;
1111

12+
import com.donnfelker.android.bootstrap.BootstrapApplication;
1213
import com.donnfelker.android.bootstrap.BootstrapServiceProvider;
1314
import com.donnfelker.android.bootstrap.R;
1415
import com.donnfelker.android.bootstrap.authenticator.LogoutService;
@@ -29,6 +30,8 @@ public void onActivityCreated(Bundle savedInstanceState) {
2930
super.onActivityCreated(savedInstanceState);
3031

3132
setEmptyText(R.string.no_news);
33+
34+
BootstrapApplication.getInstance().inject(this);
3235
}
3336

3437
@Override

app/src/main/java/com/donnfelker/android/bootstrap/ui/UserListFragment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.view.View;
1111
import android.widget.ListView;
1212

13+
import com.donnfelker.android.bootstrap.BootstrapApplication;
1314
import com.donnfelker.android.bootstrap.BootstrapServiceProvider;
1415
import com.donnfelker.android.bootstrap.R;
1516
import com.donnfelker.android.bootstrap.authenticator.LogoutService;
@@ -26,13 +27,15 @@ public class UserListFragment extends ItemListFragment<User> {
2627

2728
@Inject BootstrapServiceProvider serviceProvider;
2829
@Inject AvatarLoader avatars;
29-
@Inject protected LogoutService logoutService;
30+
@Inject LogoutService logoutService;
3031

3132
@Override
3233
public void onActivityCreated(Bundle savedInstanceState) {
3334
super.onActivityCreated(savedInstanceState);
3435

3536
setEmptyText(R.string.no_users);
37+
38+
BootstrapApplication.getInstance().inject(this);
3639
}
3740

3841
@Override

0 commit comments

Comments
 (0)