Permalink
Browse files

Smarter injection w/o FragmentsInjector.

  • Loading branch information...
yanchenko committed Oct 27, 2012
1 parent 6958c2e commit 2fb48d18837c6eb7a8ca7fccae036e40fcf8325a
@@ -17,6 +17,7 @@
import org.droidparts.inject.injector.DependencyInjector;
import org.droidparts.inject.injector.InjectorDelegate;
+import org.droidparts.util.L;
import android.app.Activity;
import android.app.Dialog;
@@ -34,7 +35,7 @@
private final InjectorDelegate delegate;
static class Holder {
- static final Injector INJECTOR = new Injector(new InjectorDelegate());
+ static final Injector INJECTOR = new Injector();
}
public static Injector get() {
@@ -95,8 +96,17 @@ public void inject(View view, Object target) {
delegate.inject(ctx, view, target);
}
- protected Injector(InjectorDelegate delegate) {
- this.delegate = delegate;
+ private Injector() {
+ InjectorDelegate fragmentsDelegate = null;
+ try {
+ fragmentsDelegate = (InjectorDelegate) Class.forName(
+ "org.droidparts.inject.injector.FragmentsInjectorDelegate")
+ .newInstance();
+ } catch (Exception e) {
+ L.v(e);
+ }
+ delegate = (fragmentsDelegate != null) ? fragmentsDelegate
+ : new InjectorDelegate();
}
private static void setContext(Context ctx) {
@@ -16,7 +16,7 @@
package org.droidparts.activity;
import org.droidparts.R;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import org.droidparts.inject.Injectable;
import android.app.Fragment;
@@ -39,7 +39,7 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onPreInject();
- FragmentsInjector.get().inject(this);
+ Injector.get().inject(this);
}
@Override
@@ -15,7 +15,7 @@
*/
package org.droidparts.fragment;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import android.app.Activity;
import android.app.Fragment;
@@ -33,10 +33,10 @@
@Override
public final View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
- FragmentsInjector.get().inject(getDialog(), this);
+ Injector.get().inject(getDialog(), this);
View view = onCreateView(savedInstanceState, inflater, container);
if (view != null) {
- FragmentsInjector.get().inject(view, this);
+ Injector.get().inject(view, this);
injected = true;
}
return view;
@@ -15,7 +15,7 @@
*/
package org.droidparts.fragment;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -30,7 +30,7 @@
public final View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = onCreateView(savedInstanceState, inflater, container);
- FragmentsInjector.get().inject(view, this);
+ Injector.get().inject(view, this);
injected = true;
return view;
}
@@ -15,7 +15,7 @@
*/
package org.droidparts.fragment;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -30,7 +30,7 @@
public final View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = onCreateView(savedInstanceState, inflater, container);
- FragmentsInjector.get().inject(view, this);
+ Injector.get().inject(view, this);
injected = true;
return view;
}
@@ -1,36 +0,0 @@
-/**
- * Copyright 2012 Alex Yanchenko
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.droidparts.inject;
-
-import org.droidparts.inject.injector.FragmentsInjectorDelegate;
-import org.droidparts.inject.injector.InjectorDelegate;
-
-public class FragmentsInjector extends Injector {
-
- static class Holder {
- static final FragmentsInjector INJECTOR = new FragmentsInjector(
- new FragmentsInjectorDelegate());
- }
-
- public static FragmentsInjector get() {
- return Holder.INJECTOR;
- }
-
- protected FragmentsInjector(InjectorDelegate delegate) {
- super(delegate);
- }
-
-}
@@ -16,7 +16,7 @@
package org.droidparts.activity;
import org.droidparts.R;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import org.droidparts.inject.Injectable;
import android.os.Bundle;
@@ -41,7 +41,7 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onPreInject();
- FragmentsInjector.get().inject(this);
+ Injector.get().inject(this);
}
@Override
@@ -15,7 +15,7 @@
*/
package org.droidparts.fragment;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@@ -35,10 +35,10 @@
@Override
public final View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
- FragmentsInjector.get().inject(getDialog(), this);
+ Injector.get().inject(getDialog(), this);
View view = onCreateView(savedInstanceState, inflater, container);
if (view != null) {
- FragmentsInjector.get().inject(view, this);
+ Injector.get().inject(view, this);
}
injected = true;
return view;
@@ -15,7 +15,7 @@
*/
package org.droidparts.fragment;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -32,7 +32,7 @@
public final View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = onCreateView(savedInstanceState, inflater, container);
- FragmentsInjector.get().inject(view, this);
+ Injector.get().inject(view, this);
injected = true;
return view;
}
@@ -15,7 +15,7 @@
*/
package org.droidparts.fragment;
-import org.droidparts.inject.FragmentsInjector;
+import org.droidparts.inject.Injector;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -32,7 +32,7 @@
public final View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = onCreateView(savedInstanceState, inflater, container);
- FragmentsInjector.get().inject(view, this);
+ Injector.get().inject(view, this);
injected = true;
return view;
}
@@ -1,36 +0,0 @@
-/**
- * Copyright 2012 Alex Yanchenko
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.droidparts.inject;
-
-import org.droidparts.inject.injector.FragmentsInjectorDelegate;
-import org.droidparts.inject.injector.InjectorDelegate;
-
-public class FragmentsInjector extends Injector {
-
- static class Holder {
- static final FragmentsInjector INJECTOR = new FragmentsInjector(
- new FragmentsInjectorDelegate());
- }
-
- public static FragmentsInjector get() {
- return Holder.INJECTOR;
- }
-
- protected FragmentsInjector(InjectorDelegate delegate) {
- super(delegate);
- }
-
-}

0 comments on commit 2fb48d1

Please sign in to comment.