|
|
@@ -2,6 +2,7 @@ package com.miekir.newmvp;
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.After;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
|
@@ -11,27 +12,30 @@ import org.aspectj.lang.annotation.Pointcut;
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
/**
|
|
|
+ * https://blog.csdn.net/zhengchao1991/article/details/53391244
|
|
|
* 加载框
|
|
|
*/
|
|
|
@Aspect
|
|
|
public class LoadingAspect {
|
|
|
private static final String TAG = "LoadingAspect";
|
|
|
- //https://blog.csdn.net/zhengchao1991/article/details/53391244
|
|
|
- @Pointcut("@annotation(com.miekir.mvp.base.NeedLoading)")
|
|
|
+ // 要注意加上execution(* *(..)) && 防止被执行两次
|
|
|
+ @Pointcut("execution(* *(..)) && @annotation(com.miekir.mvp.base.NeedLoading)")
|
|
|
public void timeTask() {}
|
|
|
|
|
|
- @After("timeTask()")
|
|
|
+ /*@Around("timeTask()")
|
|
|
public void onTimeTaskAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
- // 注入加载框
|
|
|
- Log.e("log", "do loading");
|
|
|
-// Object targetObject = joinPoint.getTarget();
|
|
|
-// try {
|
|
|
-// Method m = targetObject.getClass().getMethod("showLoading");
|
|
|
-// m.invoke(targetObject);
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-
|
|
|
joinPoint.proceed();
|
|
|
+ }*/
|
|
|
+
|
|
|
+ @After("timeTask()")
|
|
|
+ public void afterMethod(JoinPoint joinPoint){
|
|
|
+ // 注入加载框
|
|
|
+ Object targetObject = joinPoint.getTarget();
|
|
|
+ try {
|
|
|
+ Method m = targetObject.getClass().getMethod("showLoading");
|
|
|
+ m.invoke(targetObject);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|