package com.seewo.vcommons.hook.hookclick.aspect;

import android.view.View;
import com.seewo.vcommons.hook.listener.IOnClickListener;
import com.seewo.vcommons.utils.RLog;
import java.util.Map;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/* JADX INFO: loaded from: classes.dex */
@Aspect
public class AspectClickHooker {
    private long lastTime;
    private View lastView;
    private IOnClickListener iOnClickListener = null;
    private String TAG = "AspectClickHooker";

    @Around("execution(* android.view.View.OnClickListener.onClick(..))")
    public void onClickListener(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        if (!AOPAttrs.isOpen) {
            proceedingJoinPoint.proceed();
            return;
        }
        View view = (View) proceedingJoinPoint.getArgs()[0];
        if (view != this.lastView) {
            this.iOnClickListener = setListenerAnnotation(view);
            execution(proceedingJoinPoint, view);
            AOPAttrs.annotationDelayTime = -1L;
            setViewAnnotation(view);
            this.lastView = view;
            this.lastTime = System.currentTimeMillis();
            return;
        }
        long j = AOPAttrs.defaultDelayTime;
        if (AOPAttrs.annotationDelayTime != -1) {
            j = AOPAttrs.annotationDelayTime;
        }
        if (System.currentTimeMillis() - this.lastTime >= j) {
            RLog.i(this.TAG, "onClick delay:" + j);
            execution(proceedingJoinPoint, view);
            this.lastTime = System.currentTimeMillis();
            this.lastView = view;
            return;
        }
        RLog.i(this.TAG, "onClick filter!", new Exception("onClick filter!"));
    }

    private void execution(ProceedingJoinPoint proceedingJoinPoint, View view) {
        try {
            IOnClickListener iOnClickListener = this.iOnClickListener;
            if (iOnClickListener == null) {
                proceedingJoinPoint.proceed();
            } else if (!iOnClickListener.isFilter(view)) {
                this.iOnClickListener.befroeClick(view);
                proceedingJoinPoint.proceed();
                this.iOnClickListener.afterClick(view);
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    private void setViewAnnotation(View view) {
        Class<?> cls = view.getContext().getClass();
        if (AOPAttrs.isGlobalHook) {
            AOPAttrs.annotationDelayTime = AOPAttrs.defaultDelayTime;
        }
        if (AOPAttrs.cancelActivityClassMap.containsKey(cls)) {
            AOPAttrs.annotationDelayTime = 0L;
        }
        if (AOPAttrs.addSingleViewMap.containsKey(cls)) {
            Map<Integer, Long> map = AOPAttrs.addSingleViewMap.get(cls);
            if (map.containsKey(Integer.valueOf(view.getId()))) {
                AOPAttrs.annotationDelayTime = map.get(Integer.valueOf(view.getId())).longValue();
            }
        }
    }

    private IOnClickListener setListenerAnnotation(View view) {
        Class<?> cls = view.getContext().getClass();
        if (!AOPAttrs.viewListenerMap.containsKey(cls)) {
            return null;
        }
        Map<Integer, Class> map = AOPAttrs.viewListenerMap.get(cls);
        if (!map.containsKey(Integer.valueOf(view.getId()))) {
            return null;
        }
        try {
            Object objNewInstance = map.get(Integer.valueOf(view.getId())).newInstance();
            if (objNewInstance instanceof IOnClickListener) {
                return (IOnClickListener) objNewInstance;
            }
            return null;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return null;
        } catch (InstantiationException e2) {
            e2.printStackTrace();
            return null;
        }
    }
}
