詹子聪 5 år sedan
förälder
incheckning
f2ba153688

+ 17 - 8
mvp/src/main/java/com/miekir/mvp/view/BaseMVPActivity.java

@@ -53,20 +53,29 @@ public abstract class BaseMVPActivity extends BaseActivity implements IView {
                     DataMethod dataMethod = method.getAnnotation(DataMethod.class);
                     if (dataMethod != null) {
                         int length = method.getParameterTypes().length;
-                        if (length != 3) {
-                            throw new AssertionError("DataMethod参数数量必须为3个");
+                        if (length != 4) {
+                            throw new AssertionError("DataMethod参数数量必须为4个");
                         }
 
+                        // 响应结果code
                         String firstType = method.getParameterTypes()[0].getSimpleName();
-                        String firstCorrectType = int.class.getSimpleName();
-                        if (!TextUtils.equals(firstCorrectType, firstType)) {
-                            throw new AssertionError("DataMethod第1个参数必须为" + firstCorrectType);
+                        String resultCodeType = int.class.getSimpleName();
+                        if (!TextUtils.equals(resultCodeType, firstType)) {
+                            throw new AssertionError("DataMethod第1个参数必须为" + resultCodeType);
                         }
 
+                        // 响应消息
                         String secondType = method.getParameterTypes()[1].getSimpleName();
-                        String secondCorrectType = String.class.getSimpleName();
-                        if (!TextUtils.equals(secondCorrectType, secondType)) {
-                            throw new AssertionError("DataMethod第2个参数必须为" + secondCorrectType);
+                        String messageType = String.class.getSimpleName();
+                        if (!TextUtils.equals(messageType, secondType)) {
+                            throw new AssertionError("DataMethod第2个参数必须为" + messageType);
+                        }
+
+                        // 数据来源
+                        String fourthType = method.getParameterTypes()[3].getSimpleName();
+                        String sourceCodeType = int.class.getSimpleName();
+                        if (!TextUtils.equals(fourthType, sourceCodeType)) {
+                            throw new AssertionError("DataMethod第4个参数必须为" + sourceCodeType);
                         }
 
                         method.setAccessible(true);

+ 17 - 8
mvp/src/main/java/com/miekir/mvp/view/BaseMVPFragment.java

@@ -69,20 +69,29 @@ public abstract class BaseMVPFragment extends BaseFragment implements IView {
                     DataMethod dataMethod = method.getAnnotation(DataMethod.class);
                     if (dataMethod != null) {
                         int length = method.getParameterTypes().length;
-                        if (length != 3) {
-                            throw new AssertionError("DataMethod参数数量必须为3个");
+                        if (length != 4) {
+                            throw new AssertionError("DataMethod参数数量必须为4个");
                         }
 
+                        // 响应结果code
                         String firstType = method.getParameterTypes()[0].getSimpleName();
-                        String firstCorrectType = int.class.getSimpleName();
-                        if (!TextUtils.equals(firstCorrectType, firstType)) {
-                            throw new AssertionError("DataMethod第1个参数必须为" + firstCorrectType);
+                        String resultCodeType = int.class.getSimpleName();
+                        if (!TextUtils.equals(resultCodeType, firstType)) {
+                            throw new AssertionError("DataMethod第1个参数必须为" + resultCodeType);
                         }
 
+                        // 响应消息
                         String secondType = method.getParameterTypes()[1].getSimpleName();
-                        String secondCorrectType = String.class.getSimpleName();
-                        if (!TextUtils.equals(secondCorrectType, secondType)) {
-                            throw new AssertionError("DataMethod第2个参数必须为" + secondCorrectType);
+                        String messageType = String.class.getSimpleName();
+                        if (!TextUtils.equals(messageType, secondType)) {
+                            throw new AssertionError("DataMethod第2个参数必须为" + messageType);
+                        }
+
+                        // 数据来源
+                        String fourthType = method.getParameterTypes()[3].getSimpleName();
+                        String sourceCodeType = int.class.getSimpleName();
+                        if (!TextUtils.equals(fourthType, sourceCodeType)) {
+                            throw new AssertionError("DataMethod第4个参数必须为" + sourceCodeType);
                         }
 
                         method.setAccessible(true);

+ 11 - 0
mvp/src/main/java/com/miekir/mvp/view/model/BaseMVPActivity.java

@@ -56,6 +56,17 @@ public abstract class BaseMVPActivity extends BaseActivity implements IView {
                 for (Method method : methods) {
                     DataMethod dataMethod = method.getAnnotation(DataMethod.class);
                     if (dataMethod != null) {
+
+                        Field signatureField = null;
+                        try {
+                            signatureField = Method.class.getDeclaredField("signature");
+                            signatureField.setAccessible(true);
+                            String signature = signatureField.get(method).toString();
+                            //System.out.println("method signature: " + signature);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+
                         int length = method.getParameterTypes().length;
                         if (length != 4) {
                             throw new AssertionError("DataMethod参数数量必须为4个");

+ 11 - 0
mvp/src/main/java/com/miekir/mvp/view/model/BaseMVPFragment.java

@@ -57,6 +57,17 @@ public abstract class BaseMVPFragment extends BaseFragment implements IView {
                 for (Method method : methods) {
                     DataMethod dataMethod = method.getAnnotation(DataMethod.class);
                     if (dataMethod != null) {
+
+                        Field signatureField = null;
+                        try {
+                            signatureField = Method.class.getDeclaredField("signature");
+                            signatureField.setAccessible(true);
+                            String signature = signatureField.get(method).toString();
+                            //System.out.println("method signature: " + signature);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+
                         int length = method.getParameterTypes().length;
                         if (length != 4) {
                             throw new AssertionError("DataMethod参数数量必须为4个");