diff --git a/README.md b/README.md index 2624a984..2013d9bc 100644 --- a/README.md +++ b/README.md @@ -76,36 +76,36 @@ Base modules integration: ```groovy dependencies { ... - compile 'com.arello-mobile:moxy:1.4.1' - provided 'com.arello-mobile:moxy-compiler:1.4.1' + compile 'com.arello-mobile:moxy:1.4.2' + provided 'com.arello-mobile:moxy-compiler:1.4.2' } ``` If you want to see generated code, use `apt` instead of `provided` dependency type: ```groovy dependencies { ... - apt 'com.arello-mobile:moxy-compiler:1.4.1' + apt 'com.arello-mobile:moxy-compiler:1.4.2' } ``` Note: if you use gradle plugin verion 2.2.2 and above, so you can use `annotationProcessor` instead of `apt`: ```groovy dependencies { ... - annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.1' + annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.2' } ``` For additional base view classes `MvpActivity` and `MvpFragment` add this: ```groovy dependencies { ... - compile 'com.arello-mobile:moxy-android:1.4.1' + compile 'com.arello-mobile:moxy-android:1.4.2' } ``` If you are planing to use AppCompat, then you can use `MvpAppCompatActivity` and `MvpAppCompatFragment`. Then add this: ```groovy dependencies { ... - compile 'com.arello-mobile:moxy-app-compat:1.4.1' + compile 'com.arello-mobile:moxy-app-compat:1.4.2' compile 'com.android.support:appcompat-v7:$support_version' } ``` @@ -114,7 +114,7 @@ If you are using kotlin, use `kapt` instead of `provided`/`apt` dependency type ```groovy dependencies { ... - kapt 'com.arello-mobile:moxy-compiler:1.4.1' + kapt 'com.arello-mobile:moxy-compiler:1.4.2' } kapt { generateStubs = true diff --git a/build.gradle b/build.gradle index becfeb5f..0702bf24 100644 --- a/build.gradle +++ b/build.gradle @@ -19,8 +19,8 @@ allprojects { } ext { - targetVersionCode = 34 - targetVersionName = "1.4.1" + targetVersionCode = 35 + targetVersionName = "1.4.2" } task clean(type: Delete) { diff --git a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/PresenterBinderClassGenerator.java b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/PresenterBinderClassGenerator.java index 3ba5f9f9..92d79752 100644 --- a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/PresenterBinderClassGenerator.java +++ b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/PresenterBinderClassGenerator.java @@ -107,7 +107,7 @@ public boolean generate(VariableElement variableElement, List providePresenter() {\n"; + "\t\tpublic MvpPresenter providePresenter(Object delegated) {\n"; if (field.getPresenterProviderMethodName() != null) { - s+= "\t\t\treturn mTarget." + field.getPresenterProviderMethodName() + "();\n"; + s+= "\t\t\treturn ((" + targetClass + ") delegated)." + field.getPresenterProviderMethodName() + "();\n"; } else { boolean hasEmptyConstructor = false; List enclosedElements = clazz.getEnclosedElements(); @@ -383,8 +383,8 @@ private static String generatePresenterBinderClass(final String builder, final F if (field.getPresenterTagProviderMethodName() != null) { s += "\n" + "\t\t@Override\n" + - "\t\tpublic String getTag() {\n" + - "\t\t\treturn String.valueOf(mTarget." + field.getPresenterTagProviderMethodName() + "());\n" + + "\t\tpublic String getTag(Object delegated) {\n" + + "\t\t\treturn String.valueOf(((" + targetClass + ") delegated)." + field.getPresenterTagProviderMethodName() + "());\n" + "\t\t}\n"; } diff --git a/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java b/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java index ec8193a2..2236f2da 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java +++ b/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java @@ -27,19 +27,19 @@ public class MvpProcessor { *

* 3)If {@link com.arellomobile.mvp.PresenterStore} doesn't contain MvpPresenter with current tag, {@link PresenterField} will create it * - * @param presenterField info about presenter from {@link com.arellomobile.mvp.presenter.InjectPresenter} - * @param delegateTag unique tag generated by {@link MvpDelegate#generateTag()} * @param type of delegated - * @return MvpPresenter instance + * @param target object that want injection + * @param presenterField info about presenter from {@link com.arellomobile.mvp.presenter.InjectPresenter} + * @param delegateTag unique tag generated by {@link MvpDelegate#generateTag()} @return MvpPresenter instance */ - private MvpPresenter getMvpPresenter(PresenterField presenterField, String delegateTag) { + private MvpPresenter getMvpPresenter(Delegated target, PresenterField presenterField, String delegateTag) { Class> presenterClass = presenterField.getPresenterClass(); PresenterStore presenterStore = MvpFacade.getInstance().getPresenterStore(); PresenterType type = presenterField.getPresenterType(); //noinspection unchecked String tag = type == PresenterType.LOCAL ? delegateTag + "$" : ""; - tag += presenterField.getTag(); + tag += presenterField.getTag(target); //noinspection unchecked MvpPresenter presenter = presenterStore.get(type, tag, presenterClass); @@ -48,7 +48,7 @@ private MvpPresenter getMvpPresenter(PresenterFie } //noinspection unchecked - presenter = (MvpPresenter) presenterField.providePresenter(); + presenter = (MvpPresenter) presenterField.providePresenter(target); if (presenter == null) { return null; @@ -87,16 +87,15 @@ List> getMvpPresenters(Delegated del for (Object presenterBinderObject : presenterBinders) { //noinspection unchecked PresenterBinder presenterBinder = (PresenterBinder) presenterBinderObject; - presenterBinder.setTarget(delegated); List> presenterFields = presenterBinder.getPresenterFields(); for (PresenterField presenterField : presenterFields) { - MvpPresenter presenter = getMvpPresenter(presenterField, delegateTag); + MvpPresenter presenter = getMvpPresenter(delegated, presenterField, delegateTag); if (presenter != null) { presentersCounter.injectPresenter(presenter, delegateTag); presenters.add(presenter); - presenterField.setValue(presenter); + presenterField.bind(delegated, presenter); } } } diff --git a/moxy/src/main/java/com/arellomobile/mvp/PresenterBinder.java b/moxy/src/main/java/com/arellomobile/mvp/PresenterBinder.java index 6f1a2765..6486757d 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/PresenterBinder.java +++ b/moxy/src/main/java/com/arellomobile/mvp/PresenterBinder.java @@ -11,11 +11,5 @@ * @author Alexander Blinov */ public abstract class PresenterBinder { - protected PresentersContainer mTarget; - - public void setTarget(PresentersContainer presenterAggregator) { - mTarget = presenterAggregator; - } - public abstract List> getPresenterFields(); } diff --git a/moxy/src/main/java/com/arellomobile/mvp/presenter/PresenterField.java b/moxy/src/main/java/com/arellomobile/mvp/presenter/PresenterField.java index c1b9f1e2..7b1ebb53 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/presenter/PresenterField.java +++ b/moxy/src/main/java/com/arellomobile/mvp/presenter/PresenterField.java @@ -22,9 +22,9 @@ protected PresenterField(String tag, PresenterType presenterType, String present this.presenterClass = presenterClass; } - public abstract void setValue(MvpPresenter presenter); + public abstract void bind(Object target, MvpPresenter presenter); - public String getTag() { + public String getTag(Object delegated) { return tag != null ? tag : getClass().getSimpleName(); } @@ -40,5 +40,5 @@ public Class> getPresenterClass() { return presenterClass; } - public abstract MvpPresenter providePresenter(); + public abstract MvpPresenter providePresenter(Object delegated); } diff --git a/sample-github/build.gradle b/sample-github/build.gradle index f41b9c86..59411a21 100644 --- a/sample-github/build.gradle +++ b/sample-github/build.gradle @@ -68,7 +68,7 @@ dependencies { testCompile "org.hamcrest:hamcrest-all:1.3" testCompile "org.robolectric:robolectric:3.1-rc1" - compile 'com.arello-mobile:moxy:1.4.1' - compile 'com.arello-mobile:moxy-app-compat:1.4.1' - annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.1' + compile 'com.arello-mobile:moxy:1.4.2' + compile 'com.arello-mobile:moxy-app-compat:1.4.2' + annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.2' } \ No newline at end of file diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle index d8a134b5..2f1ff2f9 100644 --- a/sample-kotlin/build.gradle +++ b/sample-kotlin/build.gradle @@ -40,9 +40,9 @@ android { dependencies { compile 'com.android.support:appcompat-v7:25.0.0' - compile 'com.arello-mobile:moxy:1.4.1' - compile 'com.arello-mobile:moxy-app-compat:1.4.1' - kapt 'com.arello-mobile:moxy-compiler:1.4.1' + compile 'com.arello-mobile:moxy:1.4.2' + compile 'com.arello-mobile:moxy-app-compat:1.4.2' + kapt 'com.arello-mobile:moxy-compiler:1.4.2' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }