Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Injector cleanup.

  • Loading branch information...
commit 65ba36fcc91afce73d25f8f2752ba128b812078a 1 parent ca6417e
@yanchenko authored
Showing with 22 additions and 28 deletions.
  1. +22 −28 base/src/org/droidparts/inject/Injector.java
View
50 base/src/org/droidparts/inject/Injector.java
@@ -31,29 +31,22 @@
*/
public class Injector {
- private static Context ctx;
- private final InjectorDelegate delegate;
-
- static class Holder {
- static final Injector INJECTOR = new Injector();
+ public static Context getApplicationContext() {
+ return appCtx;
}
public static Injector get() {
return Holder.INJECTOR;
}
- public static Context getApplicationContext() {
- return ctx;
- }
-
public void setUp(Context ctx) {
setContext(ctx);
- InjectorDelegate.setUp(Injector.ctx);
+ InjectorDelegate.setUp(appCtx);
}
public void tearDown() {
InjectorDelegate.tearDown();
- ctx = null;
+ appCtx = null;
}
public <T> T getDependency(Context ctx, Class<T> cls) {
@@ -61,17 +54,10 @@ public void tearDown() {
return DependencyInjector.getDependency(ctx, cls);
}
- public void inject(Object target) {
- if (ctx != null) {
- delegate.inject(ctx, null, target);
- } else {
- throw new IllegalStateException("No context provided.");
- }
- }
-
- public void inject(Context ctx, Object target) {
- setContext(ctx);
- delegate.inject(ctx, null, target);
+ public void inject(Activity act) {
+ setContext(act);
+ View root = act.findViewById(android.R.id.content).getRootView();
+ delegate.inject(act, root, act);
}
public void inject(Service serv) {
@@ -79,10 +65,9 @@ public void inject(Service serv) {
delegate.inject(serv, null, serv);
}
- public void inject(Activity act) {
- setContext(act);
- View root = act.findViewById(android.R.id.content).getRootView();
- delegate.inject(act, root, act);
+ public void inject(Context ctx, Object target) {
+ setContext(ctx);
+ delegate.inject(ctx, null, target);
}
public void inject(Dialog dialog, Object target) {
@@ -96,6 +81,15 @@ public void inject(View view, Object target) {
delegate.inject(ctx, view, target);
}
+ //
+
+ private static volatile Context appCtx;
+ private final InjectorDelegate delegate;
+
+ static class Holder {
+ static final Injector INJECTOR = new Injector();
+ }
+
private Injector() {
InjectorDelegate fragmentsDelegate = null;
try {
@@ -110,8 +104,8 @@ private Injector() {
}
private static void setContext(Context ctx) {
- if (Injector.ctx == null) {
- Injector.ctx = ctx.getApplicationContext();
+ if (appCtx == null) {
+ appCtx = ctx.getApplicationContext();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.