Skip to content

Commit d02ff82

Browse files
committed
Add getter for view
1 parent 4d1a8db commit d02ff82

File tree

12 files changed

+505
-384
lines changed

12 files changed

+505
-384
lines changed

moxy-androidx-sample/src/main/kotlin/example/com/moxy_androidx_sample/MainActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package example.com.moxy_androidx_sample
22

33
import android.os.Bundle
44
import android.util.Log
5+
import android.widget.Toast
56
import com.omegar.mvp.ktx.providePresenter
67
import com.omegar.mvp.presenter.InjectPresenter
78
import example.com.moxy_androidx_sample.contract.Contract
@@ -31,6 +32,7 @@ class MainActivity : BaseActivity(R.layout.activity_main), Contract.MainView<Dou
3132
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
3233
// }
3334

35+
override var value: String = ""
3436

3537
private val presenter: MainPresenter by providePresenter {
3638
MainPresenter()
@@ -48,8 +50,11 @@ class MainActivity : BaseActivity(R.layout.activity_main), Contract.MainView<Dou
4850
override fun second() {
4951
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
5052
}
51-
53+
54+
55+
5256
companion object {
5357
const val TAG = "MoxyDebug"
5458
}
59+
5560
}

moxy-androidx-sample/src/main/kotlin/example/com/moxy_androidx_sample/MainPresenter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import example.com.moxy_androidx_sample.contract.Contract
77

88
class MainPresenter : BasePresenter<Contract.MainView<Double>>() {
99

10+
1011
init {
1112
viewState.printLog(10.0, "Kek")
13+
viewState.value = "test";
1214
}
1315

1416
override fun onFirstViewAttach() {
1517
super.onFirstViewAttach()
16-
Log.e(MainActivity.TAG, "presenter hash code : ${hashCode()}")
18+
Log.e(MainActivity.TAG, "presenter hash code : ${hashCode()}, value = ${viewState.value}")
1719
viewState.printLog(2.0, viewState.toString())
1820
}
1921

moxy-androidx-sample/src/main/kotlin/example/com/moxy_androidx_sample/contract/Contract.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface Contract {
88

99
interface MainView<D: Number> : BaseView {
1010

11+
var value: String
12+
1113
@StateStrategyType(ADD_TO_END_SINGLE)
1214
fun printLog(msg: D?, log: String?)
1315

moxy-compiler/src/main/java/com/omegar/mvp/compiler/MvpCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
128128
try {
129129
return throwableProcess(annotations, roundEnv);
130130
} catch (RuntimeException e) {
131-
mMessager.printMessage(Diagnostic.Kind.OTHER, "Moxy compilation failed. Could you copy stack trace above and write us (or make issue on Github)?");
131+
mMessager.printMessage(Diagnostic.Kind.ERROR, "Moxy compilation failed. Could you copy stack trace above and write us (or make issue on Github)?");
132132
e.printStackTrace();
133133
return true;
134134
}

moxy-compiler/src/main/java/com/omegar/mvp/compiler/Util.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Map;
3131
import java.util.Set;
3232

33+
import javax.annotation.Nonnull;
3334
import javax.annotation.Nullable;
3435
import javax.lang.model.element.AnnotationMirror;
3536
import javax.lang.model.element.AnnotationValue;
@@ -290,4 +291,8 @@ public static <E> HashSet<E> newHashSet(E... elements) {
290291
return set;
291292
}
292293

294+
public static boolean startWith(@Nonnull String string, @Nonnull String prefix) {
295+
return string.indexOf(prefix) == 0;
296+
}
297+
293298
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.omegar.mvp.compiler.entity;
2+
3+
import com.omegar.mvp.compiler.Util;
4+
5+
import java.util.Objects;
6+
7+
import javax.lang.model.element.ExecutableElement;
8+
import javax.lang.model.element.TypeElement;
9+
import javax.lang.model.type.DeclaredType;
10+
import javax.lang.model.util.Types;
11+
12+
/**
13+
* Date: 27-Jul-2017
14+
* Time: 12:58
15+
*
16+
* @author Evgeny Kursakov
17+
*/
18+
@SuppressWarnings("NewApi")
19+
public class CommandViewMethod extends ViewMethod {
20+
21+
private final String mUniqueSuffix;
22+
private final TypeElement mStrategy;
23+
private final String mTag;
24+
25+
public CommandViewMethod(Types types, DeclaredType targetInterfaceElement,
26+
ExecutableElement methodElement,
27+
TypeElement strategy,
28+
String tag,
29+
String uniqueSuffix) {
30+
super(types, targetInterfaceElement, methodElement);
31+
mStrategy = strategy;
32+
mTag = tag;
33+
mUniqueSuffix = uniqueSuffix;
34+
}
35+
36+
public TypeElement getStrategy() {
37+
return mStrategy;
38+
}
39+
40+
public String getTag() {
41+
return mTag;
42+
}
43+
44+
public String getUniqueSuffix() {
45+
return mUniqueSuffix;
46+
}
47+
48+
public String getCommandClassName() {
49+
return Util.capitalizeString(getName()) + mUniqueSuffix + "Command";
50+
}
51+
52+
@Override
53+
public boolean equals(Object o) {
54+
if (this == o) return true;
55+
if (o == null || getClass() != o.getClass()) return false;
56+
if (!super.equals(o)) return false;
57+
CommandViewMethod that = (CommandViewMethod) o;
58+
return Objects.equals(mUniqueSuffix, that.mUniqueSuffix) &&
59+
Objects.equals(mStrategy, that.mStrategy) &&
60+
Objects.equals(mTag, that.mTag);
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return Objects.hash(super.hashCode(), mUniqueSuffix, mStrategy, mTag);
66+
}
67+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.omegar.mvp.compiler.entity;
2+
3+
import javax.lang.model.element.ExecutableElement;
4+
import javax.lang.model.type.DeclaredType;
5+
import javax.lang.model.type.TypeMirror;
6+
import javax.lang.model.util.Types;
7+
8+
public class ReturnViewMethod extends ViewMethod {
9+
10+
private TypeMirror mReturnType;
11+
private final ExecutableElement mSetterElement;
12+
13+
public ReturnViewMethod(Types types,
14+
DeclaredType targetInterfaceElement,
15+
ExecutableElement getterElement,
16+
ExecutableElement setterElement) {
17+
super(types, targetInterfaceElement, getterElement);
18+
mReturnType = getterElement.getReturnType();
19+
mSetterElement = setterElement;
20+
}
21+
22+
public TypeMirror getReturnType() {
23+
return mReturnType;
24+
}
25+
26+
public ExecutableElement getSetterElement() {
27+
return mSetterElement;
28+
}
29+
}

moxy-compiler/src/main/java/com/omegar/mvp/compiler/entity/ViewInterfaceInfo.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ public class ViewInterfaceInfo implements TypeElementHolder {
2929
private final List<TypeVariableName> mTypeVariables;
3030
private final List<ViewMethod> mMethods;
3131

32-
public ViewInterfaceInfo(TypeElement element, List<ViewMethod> methods) {
33-
this(null, element, methods);
34-
}
35-
3632
public ViewInterfaceInfo(@Nullable TypeElement superInterfaceType, TypeElement element, List<ViewMethod> methods) {
3733
mSuperInterfaceType = superInterfaceType;
3834
mElement = element;

0 commit comments

Comments
 (0)