|
|
@@ -1,79 +1,80 @@
|
|
|
package com.miekir.newmvp;
|
|
|
|
|
|
-import android.util.Log;
|
|
|
-
|
|
|
-import com.miekir.mvp.base.NeedLoading;
|
|
|
-
|
|
|
-import org.aspectj.lang.JoinPoint;
|
|
|
-import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
-import org.aspectj.lang.annotation.After;
|
|
|
-import org.aspectj.lang.annotation.Around;
|
|
|
-import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.aspectj.lang.annotation.Before;
|
|
|
-import org.aspectj.lang.annotation.Pointcut;
|
|
|
-import org.aspectj.lang.reflect.MethodSignature;
|
|
|
-
|
|
|
-import java.lang.reflect.Field;
|
|
|
-import java.lang.reflect.Method;
|
|
|
-
|
|
|
-/**
|
|
|
- * https://blog.csdn.net/zhengchao1991/article/details/53391244
|
|
|
- * 加载框
|
|
|
- */
|
|
|
-@Aspect
|
|
|
-public class LoadingAspect {
|
|
|
- private static final String TAG = "LoadingAspect";
|
|
|
- // 要注意加上execution(* *(..)) && 防止被执行两次
|
|
|
- @Pointcut("execution(* *(..)) && @annotation(com.miekir.mvp.base.NeedLoading)")
|
|
|
- public void timeTask() {}
|
|
|
-
|
|
|
- @Around("timeTask()")
|
|
|
- public void onTimeTaskAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
- Object targetObject = joinPoint.getTarget();
|
|
|
- Field liveDataField = null;
|
|
|
- try {
|
|
|
- liveDataField = targetObject.getClass().getField("dialogLiveData");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- joinPoint.proceed();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (liveDataField != null) {
|
|
|
- // 得到此属性的值
|
|
|
- Object liveData = liveDataField.get(targetObject);
|
|
|
- if (liveData == null) {
|
|
|
- Log.e(TAG, "live data value null....");
|
|
|
- return;
|
|
|
- }
|
|
|
- //如果在Around中不调用joinPoint.proceed(),则@Before注解的方法不会调用,但是@After还是会调用。
|
|
|
- joinPoint.proceed();
|
|
|
- Log.e(TAG, "proceed....");
|
|
|
- } else {
|
|
|
- Log.e(TAG, "live data null....");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Before("timeTask()")
|
|
|
- public void beforeMethod(JoinPoint joinPoint){
|
|
|
- // 注入加载框
|
|
|
- Object targetObject = joinPoint.getTarget();
|
|
|
- try {
|
|
|
- Method showDialogMethod = targetObject.getClass().getMethod("showLoading");
|
|
|
- /*Method showDialogMethod = targetObject.getClass().getMethod("showLoading", String.class);
|
|
|
- String message = "";
|
|
|
- Method taskMethod = ((MethodSignature)joinPoint.getSignature()).getMethod();
|
|
|
- if (taskMethod.isAnnotationPresent(NeedLoading.class)) {
|
|
|
- NeedLoading loading = taskMethod.getAnnotation(NeedLoading.class);
|
|
|
- if (loading != null) {
|
|
|
- message = loading.message();
|
|
|
- }
|
|
|
- }
|
|
|
- showDialogMethod.invoke(targetObject, message);*/
|
|
|
-
|
|
|
- showDialogMethod.invoke(targetObject);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+//import android.util.Log;
|
|
|
+//
|
|
|
+//import com.miekir.mvp.base.NeedLoading;
|
|
|
+//
|
|
|
+//import org.aspectj.lang.JoinPoint;
|
|
|
+//import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+//import org.aspectj.lang.annotation.After;
|
|
|
+//import org.aspectj.lang.annotation.Around;
|
|
|
+//import org.aspectj.lang.annotation.Aspect;
|
|
|
+//import org.aspectj.lang.annotation.Before;
|
|
|
+//import org.aspectj.lang.annotation.Pointcut;
|
|
|
+//import org.aspectj.lang.reflect.MethodSignature;
|
|
|
+//
|
|
|
+//import java.lang.reflect.Field;
|
|
|
+//import java.lang.reflect.Method;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * https://blog.csdn.net/zhengchao1991/article/details/53391244
|
|
|
+// * 加载框
|
|
|
+// */
|
|
|
+//@Aspect
|
|
|
+//public class LoadingAspect {
|
|
|
+// private static final String TAG = "LoadingAspect";
|
|
|
+// // 要注意加上execution(* *(..)) && 防止被执行两次
|
|
|
+// @Pointcut("execution(* *(..)) && @annotation(com.miekir.mvp.base.NeedLoading)")
|
|
|
+// public void timeTask() {}
|
|
|
+//
|
|
|
+// @Around("timeTask()")
|
|
|
+// public void onTimeTaskAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+// Object targetObject = joinPoint.getTarget();
|
|
|
+// Field liveDataField = null;
|
|
|
+// try {
|
|
|
+// dialogLiveData这个属性必须必须是public的,否则在此时是在子类,非public的话getField会拿不到而报错
|
|
|
+// liveDataField = targetObject.getClass().getField("dialogLiveData");
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// joinPoint.proceed();
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (liveDataField != null) {
|
|
|
+// // 得到此属性的值
|
|
|
+// Object liveData = liveDataField.get(targetObject);
|
|
|
+// if (liveData == null) {
|
|
|
+// Log.e(TAG, "live data value null....");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //如果在Around中不调用joinPoint.proceed(),则@Before注解的方法不会调用,但是@After还是会调用。
|
|
|
+// joinPoint.proceed();
|
|
|
+// Log.e(TAG, "proceed....");
|
|
|
+// } else {
|
|
|
+// Log.e(TAG, "live data null....");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Before("timeTask()")
|
|
|
+// public void beforeMethod(JoinPoint joinPoint){
|
|
|
+// // 注入加载框
|
|
|
+// Object targetObject = joinPoint.getTarget();
|
|
|
+// try {
|
|
|
+// Method showDialogMethod = targetObject.getClass().getMethod("showLoading");
|
|
|
+// /*Method showDialogMethod = targetObject.getClass().getMethod("showLoading", String.class);
|
|
|
+// String message = "";
|
|
|
+// Method taskMethod = ((MethodSignature)joinPoint.getSignature()).getMethod();
|
|
|
+// if (taskMethod.isAnnotationPresent(NeedLoading.class)) {
|
|
|
+// NeedLoading loading = taskMethod.getAnnotation(NeedLoading.class);
|
|
|
+// if (loading != null) {
|
|
|
+// message = loading.message();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// showDialogMethod.invoke(targetObject, message);*/
|
|
|
+//
|
|
|
+// showDialogMethod.invoke(targetObject);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|