|
@@ -1,17 +1,21 @@
|
|
|
-package com.miekir.newmvp.aspectj.click
|
|
|
|
|
|
|
+package com.miekir.newmvp.aspectj.click;
|
|
|
|
|
|
|
|
-import org.aspectj.lang.ProceedingJoinPoint
|
|
|
|
|
-import org.aspectj.lang.annotation.Around
|
|
|
|
|
-import org.aspectj.lang.annotation.Aspect
|
|
|
|
|
-import org.aspectj.lang.annotation.Pointcut
|
|
|
|
|
-import java.util.*
|
|
|
|
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
|
|
|
//使用@Aspect注解标示这是一个切面类
|
|
//使用@Aspect注解标示这是一个切面类
|
|
|
@Aspect
|
|
@Aspect
|
|
|
-class SingleClickAspect {
|
|
|
|
|
|
|
+public class SingleClickAspect {
|
|
|
|
|
+ private static final long MIN_CLICK_DELAY_TIME = 600L;
|
|
|
|
|
+ private static long lastClickTime = 0L;
|
|
|
|
|
+
|
|
|
//@Pointcut来标识所要寻找的切点,就是我们定义的@ SingleClick注解
|
|
//@Pointcut来标识所要寻找的切点,就是我们定义的@ SingleClick注解
|
|
|
@Pointcut("execution(@com.miekir.newmvp.aspectj.click.SingleClick * *(..))")//方法切入点
|
|
@Pointcut("execution(@com.miekir.newmvp.aspectj.click.SingleClick * *(..))")//方法切入点
|
|
|
- fun methodAnnotated() {
|
|
|
|
|
|
|
+ public void methodAnnotated() {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -22,24 +26,16 @@ class SingleClickAspect {
|
|
|
* @Around 可以在方法前后各插入代码
|
|
* @Around 可以在方法前后各插入代码
|
|
|
*/
|
|
*/
|
|
|
@Around("methodAnnotated()")
|
|
@Around("methodAnnotated()")
|
|
|
- //@Throws这个注解不必在意,这个是kotlin的注解,标识该方法可以抛出异常
|
|
|
|
|
- @Throws(Throwable::class)
|
|
|
|
|
- fun aroundJoinPoint(joinPoint: ProceedingJoinPoint) {
|
|
|
|
|
|
|
+ public void aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
//获取系统当前时间
|
|
//获取系统当前时间
|
|
|
- val currentTime = Calendar.getInstance().timeInMillis
|
|
|
|
|
|
|
+ long currentTime = Calendar.getInstance().getTimeInMillis();
|
|
|
//当前时间-上次记录时间>过滤的时间 过滤掉600毫秒内的连续点击
|
|
//当前时间-上次记录时间>过滤的时间 过滤掉600毫秒内的连续点击
|
|
|
//表示该方法可以执行
|
|
//表示该方法可以执行
|
|
|
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
|
|
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
|
|
|
//将刚进入方法的时间赋值给上次点击时间
|
|
//将刚进入方法的时间赋值给上次点击时间
|
|
|
- lastClickTime = currentTime
|
|
|
|
|
|
|
+ lastClickTime = currentTime;
|
|
|
//执行原方法
|
|
//执行原方法
|
|
|
- joinPoint.proceed()
|
|
|
|
|
|
|
+ joinPoint.proceed();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- companion object {
|
|
|
|
|
- const val TAG = "SingleClickAspect"
|
|
|
|
|
- const val MIN_CLICK_DELAY_TIME = 600
|
|
|
|
|
- var lastClickTime = 0L
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|