diff --git a/README.md b/README.md
index c1eeee44..ccba5115 100644
--- a/README.md
+++ b/README.md
@@ -76,36 +76,36 @@ Base modules integration:
```groovy
dependencies {
...
- compile 'com.arello-mobile:moxy:1.4.3'
- provided 'com.arello-mobile:moxy-compiler:1.4.3'
+ compile 'com.arello-mobile:moxy:1.4.4'
+ provided 'com.arello-mobile:moxy-compiler:1.4.4'
}
```
If you want to see generated code, use `apt` instead of `provided` dependency type:
```groovy
dependencies {
...
- apt 'com.arello-mobile:moxy-compiler:1.4.3'
+ apt 'com.arello-mobile:moxy-compiler:1.4.4'
}
```
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.3'
+ annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.4'
}
```
For additional base view classes `MvpActivity` and `MvpFragment` add this:
```groovy
dependencies {
...
- compile 'com.arello-mobile:moxy-android:1.4.3'
+ compile 'com.arello-mobile:moxy-android:1.4.4'
}
```
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.3'
+ compile 'com.arello-mobile:moxy-app-compat:1.4.4'
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.3'
+ kapt 'com.arello-mobile:moxy-compiler:1.4.4'
}
kapt {
generateStubs = true
diff --git a/build.gradle b/build.gradle
index 1470a485..23c94a7e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,8 +19,8 @@ allprojects {
}
ext {
- targetVersionCode = 36
- targetVersionName = "1.4.3"
+ targetVersionCode = 37
+ targetVersionName = "1.4.4"
}
task clean(type: Delete) {
diff --git a/moxy-android/build.gradle b/moxy-android/build.gradle
index ad1089f7..6783f376 100644
--- a/moxy-android/build.gradle
+++ b/moxy-android/build.gradle
@@ -111,15 +111,11 @@ def getBasePom(String libName) {
}
return basePom.withXml {
- asNode().dependencies.'*'.findAll() {
- it.version.text() == 'unspecified' && project.configurations.compile.allDependencies.find { dep ->
- dep.name == it.artifactId.text()
- }
- }.each() {
- it.scope*.value = 'compile'
- it.groupId*.value = 'com.arello-mobile'
- it.artifactId*.value = libName
- it.version*.value = '${project.version}'
+ asNode().dependencies.'*'.findAll {
+ it.artifactId.text().contains('moxy')
+ }.each {
+ it.groupId*.value = targetGroupId
+ it.version*.value = targetVersionName
}
}
diff --git a/moxy-app-compat/build.gradle b/moxy-app-compat/build.gradle
index 4c858edc..addef662 100644
--- a/moxy-app-compat/build.gradle
+++ b/moxy-app-compat/build.gradle
@@ -111,19 +111,13 @@ def getBasePom(String libName) {
}
return basePom.withXml {
- asNode().dependencies.'*'.findAll() {
- it.version.text() == 'unspecified' && project.configurations.compile.allDependencies.find { dep ->
- dep.name == it.artifactId.text()
- }
- }.each() {
- it.scope*.value = 'compile'
- it.groupId*.value = 'com.arello-mobile'
- it.artifactId*.value = libName
- it.version*.value = '${project.version}'
+ asNode().dependencies.'*'.findAll {
+ it.artifactId.text().contains('moxy')
+ }.each {
+ it.groupId*.value = targetGroupId
+ it.version*.value = targetVersionName
}
}
-
-
}
task copyJars << {
diff --git a/moxy-compiler/build.gradle b/moxy-compiler/build.gradle
index ab18f1f9..bb8800e4 100644
--- a/moxy-compiler/build.gradle
+++ b/moxy-compiler/build.gradle
@@ -103,20 +103,13 @@ def getBasePom(String libName) {
}
return basePom.withXml {
-
- asNode().dependencies.'*'.findAll() {
- it.version.text() == 'unspecified' && project.configurations.compile.allDependencies.find { dep ->
- dep.name == it.artifactId.text()
- }
- }.each() {
- it.scope*.value = 'compile'
- it.groupId*.value = 'com.arello-mobile'
- it.artifactId*.value = libName
- it.version*.value = '${project.version}'
+ asNode().dependencies.'*'.findAll {
+ it.artifactId.text().contains('moxy')
+ }.each {
+ it.groupId*.value = targetGroupId
+ it.version*.value = targetVersionName
}
}
-
-
}
task copyJars << {
diff --git a/moxy/build.gradle b/moxy/build.gradle
index 1e14f4a1..0d964eff 100644
--- a/moxy/build.gradle
+++ b/moxy/build.gradle
@@ -113,12 +113,11 @@ def getBasePom() {
}
return basePom.withXml {
- asNode().dependencies.'*'.findAll() {
- it.version.text() == '4.0.+' && project.configurations.compile.allDependencies.find { dep ->
- dep.name == it.artifactId.text()
- }
- }.each() {
- it.version*.value = '[4.0,)'
+ asNode().dependencies.'*'.findAll {
+ it.artifactId.text().contains('moxy')
+ }.each {
+ it.groupId*.value = targetGroupId
+ it.version*.value = targetVersionName
}
}
}
diff --git a/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java b/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java
index ab391965..ed2f417f 100644
--- a/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java
+++ b/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java
@@ -21,11 +21,9 @@ public class MvpProcessor {
public static final String VIEW_STATE_PROVIDER_SUFFIX = "$$ViewStateProvider";
/**
- * 1) Generates tag for identification MvpPresenter
- *
- * 2) Checks if presenter with tag is already exist in {@link com.arellomobile.mvp.PresenterStore}, and returns it.
- *
- * 3)If {@link com.arellomobile.mvp.PresenterStore} doesn't contain MvpPresenter with current tag, {@link PresenterField} will create it
+ *
1) Generates tag for identification MvpPresenter
+ * 2) Checks if presenter with tag is already exist in {@link com.arellomobile.mvp.PresenterStore}, and returns it
+ * 3) If {@link com.arellomobile.mvp.PresenterStore} doesn't contain MvpPresenter with current tag, {@link PresenterField} will create it
*
* @param type of delegated
* @param target object that want injection
@@ -37,9 +35,12 @@ private MvpPresenter super Delegated> getMvpPresenter(Delegated ta
PresenterStore presenterStore = MvpFacade.getInstance().getPresenterStore();
PresenterType type = presenterField.getPresenterType();
- //noinspection unchecked
- String tag = type == PresenterType.LOCAL ? delegateTag + "$" : "";
- tag += presenterField.getTag(target);
+ String tag;
+ if (type == PresenterType.LOCAL) {
+ tag = delegateTag + "$" + presenterField.getTag(target);
+ } else {
+ tag = presenterField.getTag(target);
+ }
//noinspection unchecked
MvpPresenter super Delegated> presenter = presenterStore.get(type, tag, presenterClass);
@@ -64,9 +65,8 @@ private MvpPresenter super Delegated> getMvpPresenter(Delegated ta
/**
- * Gets presenters {@link java.util.List} annotated with {@link com.arellomobile.mvp.presenter.InjectPresenter} for view.
- *
- * See full info about getting presenter instance in {@link #getMvpPresenter}
+ *
Gets presenters {@link java.util.List} annotated with {@link com.arellomobile.mvp.presenter.InjectPresenter} for view.
+ * See full info about getting presenter instance in {@link #getMvpPresenter}
*
* @param delegated class contains presenter
* @param delegateTag unique tag generated by {@link MvpDelegate#generateTag()}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/ProvideMethodsTest.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/ProvideMethodsTest.java
new file mode 100644
index 00000000..84f388af
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/ProvideMethodsTest.java
@@ -0,0 +1,71 @@
+package com.arellomobile.mvp.provide_methods_test;
+
+import android.os.Bundle;
+
+import com.arellomobile.mvp.MvpDelegate;
+import com.arellomobile.mvp.provide_methods_test.resources.LocalProvidedView;
+import com.arellomobile.mvp.provide_methods_test.resources.TwoLocalProvidedView;
+import com.arellomobile.mvp.provide_methods_test.resources.TwoWeakWithSamePresenterIdView;
+import com.arellomobile.mvp.provide_methods_test.resources.WeakProvidedView;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+/**
+ * Date: 30.12.2016
+ * Time: 11:18
+ *
+ * @author Yuri Shmakov
+ */
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class ProvideMethodsTest {
+
+ @Test
+ public void testLocalIsProvided() {
+ LocalProvidedView view = new LocalProvidedView();
+
+ view.delegate = new MvpDelegate<>(view);
+ view.delegate.onCreate(new Bundle());
+
+ Assert.assertNotNull(view.oneLocalPresenter);
+ Assert.assertSame(view.oneLocalPresenter, view.oneLocalProvidedPresenter);
+ }
+
+ @Test
+ public void testTwoLocalUseDifferentProvided() {
+ TwoLocalProvidedView view = new TwoLocalProvidedView();
+
+ view.delegate = new MvpDelegate<>(view);
+ view.delegate.onCreate(new Bundle());
+
+ Assert.assertNotSame(view.oneLocalPresenter, view.secondLocalPresenter);
+ }
+
+ @Test
+ public void testWeakPresenterWithHardcodedTag() {
+ WeakProvidedView view = new WeakProvidedView();
+
+ view.delegate = new MvpDelegate<>(view);
+ view.delegate.onCreate(new Bundle());
+
+ Assert.assertNotNull(view.weakPresenter);
+ Assert.assertSame(view.weakPresenter, view.weakProvidedPresenter);
+ }
+
+ @Test
+ public void testTwoWeakPresenterWithSamePresenterIdTest() {
+ TwoWeakWithSamePresenterIdView view = new TwoWeakWithSamePresenterIdView();
+
+ view.delegate = new MvpDelegate<>(view);
+ view.delegate.onCreate(new Bundle());
+
+ Assert.assertNotNull(view.oneWeakPresenter);
+ Assert.assertNotNull(view.secondWeakPresenter);
+
+ Assert.assertSame(view.oneWeakPresenter, view.secondWeakPresenter);
+ }
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/LocalProvidedView.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/LocalProvidedView.java
new file mode 100644
index 00000000..d1c441b1
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/LocalProvidedView.java
@@ -0,0 +1,26 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpDelegate;
+import com.arellomobile.mvp.presenter.InjectPresenter;
+import com.arellomobile.mvp.presenter.ProvidePresenter;
+
+/**
+ * Date: 30.12.2016
+ * Time: 12:05
+ *
+ * @author Yuri Shmakov
+ */
+
+public class LocalProvidedView implements TestView {
+ @InjectPresenter
+ public TestPresenter oneLocalPresenter;
+ public TestPresenter oneLocalProvidedPresenter;
+
+ public MvpDelegate delegate;
+
+ @ProvidePresenter
+ TestPresenter provideLocalPresenter() {
+ oneLocalProvidedPresenter = new TestPresenter();
+ return oneLocalProvidedPresenter;
+ }
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/SuperView.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/SuperView.java
new file mode 100644
index 00000000..d25d54d6
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/SuperView.java
@@ -0,0 +1,35 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpDelegate;
+import com.arellomobile.mvp.presenter.InjectPresenter;
+import com.arellomobile.mvp.presenter.ProvidePresenter;
+
+/**
+ * Date: 30.12.2016
+ * Time: 10:12
+ *
+ * @author Yuri Shmakov
+ */
+
+public class SuperView implements TestView {
+ @InjectPresenter
+ public TestPresenter oneLocalPresenter;
+ public TestPresenter oneLocalProvidedPresenter;
+
+ @InjectPresenter
+ public TestPresenter secondLocalPresenter;
+
+ @InjectPresenter(presenterId = "one_global")
+ public TestPresenter oneGlobalPresenter;
+
+ @InjectPresenter(presenterId = "second_global")
+ public TestPresenter secondGlobalPresenter;
+
+ public MvpDelegate delegate;
+
+ @ProvidePresenter
+ public TestPresenter provideLocalPresenter() {
+ oneLocalProvidedPresenter = new TestPresenter();
+ return oneLocalProvidedPresenter;
+ }
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TestPresenter.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TestPresenter.java
new file mode 100644
index 00000000..3ff2f8a9
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TestPresenter.java
@@ -0,0 +1,13 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpPresenter;
+
+/**
+ * Date: 30.12.2016
+ * Time: 10:10
+ *
+ * @author Yuri Shmakov
+ */
+
+public class TestPresenter extends MvpPresenter {
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TestView.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TestView.java
new file mode 100644
index 00000000..cea7a155
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TestView.java
@@ -0,0 +1,13 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpView;
+
+/**
+ * Date: 30.12.2016
+ * Time: 10:11
+ *
+ * @author Yuri Shmakov
+ */
+
+public interface TestView extends MvpView {
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoLocalProvidedView.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoLocalProvidedView.java
new file mode 100644
index 00000000..8550ff08
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoLocalProvidedView.java
@@ -0,0 +1,28 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpDelegate;
+import com.arellomobile.mvp.presenter.InjectPresenter;
+import com.arellomobile.mvp.presenter.ProvidePresenter;
+
+/**
+ * Date: 30.12.2016
+ * Time: 12:39
+ *
+ * @author Yuri Shmakov
+ */
+
+public class TwoLocalProvidedView implements TestView {
+
+ @InjectPresenter
+ public TestPresenter oneLocalPresenter;
+
+ @InjectPresenter
+ public TestPresenter secondLocalPresenter;
+
+ public MvpDelegate delegate;
+
+ @ProvidePresenter
+ TestPresenter provideLocalPresenter() {
+ return new TestPresenter();
+ }
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoWeakWithDiffPresenterIdView.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoWeakWithDiffPresenterIdView.java
new file mode 100644
index 00000000..354a59eb
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoWeakWithDiffPresenterIdView.java
@@ -0,0 +1,44 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpDelegate;
+import com.arellomobile.mvp.presenter.InjectPresenter;
+import com.arellomobile.mvp.presenter.PresenterType;
+import com.arellomobile.mvp.presenter.ProvidePresenter;
+import com.arellomobile.mvp.presenter.ProvidePresenterTag;
+
+/**
+ * Date: 30.12.2016
+ * Time: 12:05
+ *
+ * @author Yuri Shmakov
+ */
+
+public class TwoWeakWithDiffPresenterIdView implements TestView {
+ @InjectPresenter(type = PresenterType.WEAK, presenterId = "oneWeakPresenter")
+ public TestPresenter oneWeakPresenter;
+
+ @InjectPresenter(type = PresenterType.WEAK, presenterId = "secondWeakPresenter")
+ public TestPresenter secondWeakPresenter;
+
+ public MvpDelegate delegate;
+
+ @ProvidePresenterTag(presenterClass = TestPresenter.class, type = PresenterType.WEAK, presenterId = "oneWeakPresenter")
+ public String provideOnePresenterTag() {
+ return "oneWeakPresenterTag";
+ }
+
+ @ProvidePresenterTag(presenterClass = TestPresenter.class, type = PresenterType.WEAK, presenterId = "secondWeakPresenter")
+ public String provideSecondPresenterTag() {
+ return "secondWeakPresenterTag";
+ }
+
+ @ProvidePresenter(type = PresenterType.WEAK, presenterId = "oneWeakPresenter")
+ public TestPresenter provideOneTestPresenter() {
+ return new TestPresenter();
+ }
+
+ @ProvidePresenter(type = PresenterType.WEAK, presenterId = "secondWeakPresenter")
+ public TestPresenter provideSecondTestPresenter() {
+ return new TestPresenter();
+ }
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoWeakWithSamePresenterIdView.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoWeakWithSamePresenterIdView.java
new file mode 100644
index 00000000..db1d8682
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/TwoWeakWithSamePresenterIdView.java
@@ -0,0 +1,34 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpDelegate;
+import com.arellomobile.mvp.presenter.InjectPresenter;
+import com.arellomobile.mvp.presenter.PresenterType;
+import com.arellomobile.mvp.presenter.ProvidePresenter;
+import com.arellomobile.mvp.presenter.ProvidePresenterTag;
+
+/**
+ * Date: 30.12.2016
+ * Time: 12:05
+ *
+ * @author Yuri Shmakov
+ */
+
+public class TwoWeakWithSamePresenterIdView implements TestView {
+ @InjectPresenter(type = PresenterType.WEAK, presenterId = "weakPresenter")
+ public TestPresenter oneWeakPresenter;
+
+ @InjectPresenter(type = PresenterType.WEAK, presenterId = "weakPresenter")
+ public TestPresenter secondWeakPresenter;
+
+ public MvpDelegate delegate;
+
+ @ProvidePresenterTag(presenterClass = TestPresenter.class, type = PresenterType.WEAK, presenterId = "weakPresenter")
+ public String providePresenterTag() {
+ return "weakPresenterTag";
+ }
+
+ @ProvidePresenter(type = PresenterType.WEAK, presenterId = "weakPresenter")
+ public TestPresenter provideTestPresenter() {
+ return new TestPresenter();
+ }
+}
diff --git a/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/WeakProvidedView.java b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/WeakProvidedView.java
new file mode 100644
index 00000000..d4877256
--- /dev/null
+++ b/moxy/src/test/java/com/arellomobile/mvp/provide_methods_test/resources/WeakProvidedView.java
@@ -0,0 +1,27 @@
+package com.arellomobile.mvp.provide_methods_test.resources;
+
+import com.arellomobile.mvp.MvpDelegate;
+import com.arellomobile.mvp.presenter.InjectPresenter;
+import com.arellomobile.mvp.presenter.PresenterType;
+import com.arellomobile.mvp.presenter.ProvidePresenter;
+
+/**
+ * Date: 30.12.2016
+ * Time: 12:05
+ *
+ * @author Yuri Shmakov
+ */
+
+public class WeakProvidedView implements TestView {
+ @InjectPresenter(type = PresenterType.WEAK, tag = "weakPresenter")
+ public TestPresenter weakPresenter;
+ public TestPresenter weakProvidedPresenter;
+
+ public MvpDelegate delegate;
+
+ @ProvidePresenter(type = PresenterType.WEAK, tag = "weakPresenter")
+ public TestPresenter provideWeakPresenter() {
+ weakProvidedPresenter = new TestPresenter();
+ return weakProvidedPresenter;
+ }
+}
diff --git a/sample-github/build.gradle b/sample-github/build.gradle
index c5b63688..7869f08a 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.3'
- compile 'com.arello-mobile:moxy-app-compat:1.4.3'
- annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.3'
+ compile 'com.arello-mobile:moxy:1.4.4'
+ compile 'com.arello-mobile:moxy-app-compat:1.4.4'
+ annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.4'
}
\ No newline at end of file
diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle
index 74e859ad..de938442 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.3'
- compile 'com.arello-mobile:moxy-app-compat:1.4.3'
- kapt 'com.arello-mobile:moxy-compiler:1.4.3'
+ compile 'com.arello-mobile:moxy:1.4.4'
+ compile 'com.arello-mobile:moxy-app-compat:1.4.4'
+ kapt 'com.arello-mobile:moxy-compiler:1.4.4'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}