package com.bytedance.sdk.openadsdk.common;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import com.bytedance.sdk.component.utils.mq;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.utils.xgn;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class jnr implements mq.fm {
    private int dsz;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private int f6849ef;
    private long fhx;
    private final lse fm;
    private int gqi;
    private boolean irt;
    private yz jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private WebView f6850lb;
    private boolean onz;
    private final boolean ro;
    private long vt;
    private String wey;
    private float wu;
    private final com.bytedance.sdk.component.ef.wsy yz;
    private String ajl = "landingpage";
    private final Handler wsy = new mq(com.bytedance.sdk.openadsdk.core.fhx.ro().getLooper(), this);
    private final AtomicBoolean ku = new AtomicBoolean(false);
    private Pattern duv = null;
    private long gof = -1;
    private final List<Integer> qhl = new ArrayList();

    public jnr(lse lseVar, com.bytedance.sdk.component.ef.wsy wsyVar, String str, boolean z10) {
        this.fm = lseVar;
        this.yz = wsyVar;
        this.ro = z10;
        ro();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean ajl() {
        return wsy() > 0 && !this.ku.get();
    }

    /* JADX INFO: Access modifiers changed from: private */
    @SuppressLint({"ClickableViewAccessibility"})
    public void jnr() {
        this.onz = false;
        if (this.ku.getAndSet(true)) {
            return;
        }
        this.vt = SystemClock.elapsedRealtime();
        this.fhx = System.currentTimeMillis();
        wu();
        if (this.jnr == null) {
            return;
        }
        WebView webView = this.f6850lb;
        if (webView != null) {
            this.wey = webView.getUrl();
        }
        this.jnr.setVisibility(0);
        this.jnr.fm(this.fm);
        this.jnr.fm();
        this.jnr.setAlpha(this.wu);
        this.jnr.setOnTouchListener(new View.OnTouchListener() { // from class: com.bytedance.sdk.openadsdk.common.jnr.3
            @Override // android.view.View.OnTouchListener
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return true;
            }
        });
        yz();
        lb();
    }

    private void ro() {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.yz;
        if (wsyVar != null) {
            this.f6850lb = wsyVar.getWebView();
            View arbitrageLoadingView = this.yz.getArbitrageLoadingView();
            if (arbitrageLoadingView instanceof yz) {
                this.jnr = (yz) arbitrageLoadingView;
            }
        }
        this.f6849ef = com.bytedance.sdk.openadsdk.core.settings.ku.ro().hlt();
        this.wu = com.bytedance.sdk.openadsdk.core.settings.ku.ro().hi();
    }

    private int wsy() {
        try {
            return this.f6850lb.copyBackForwardList().getCurrentIndex() + 1;
        } catch (Throwable unused) {
            return 0;
        }
    }

    private void wu() {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("loading_show_interval", SystemClock.elapsedRealtime() - this.gof);
            jSONObject.put("loading_show_timestamp", this.fhx);
            WebView webView = this.f6850lb;
            jSONObject.put("arbi_current_url", webView != null ? webView.getUrl() : "");
        } catch (Throwable unused) {
        }
        com.bytedance.sdk.openadsdk.yz.lb.fm(this.fm, this.ajl, jSONObject);
    }

    private void yz() {
        Handler handler = this.wsy;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
    }

    public void lb(WebView webView, String str, boolean z10) {
        this.qhl.clear();
        this.irt = z10;
        if (z10) {
            this.onz = true;
        }
        this.gqi = wsy();
    }

    public void fm(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        this.ajl = str;
    }

    private void lb() {
        Handler handler = this.wsy;
        if (handler != null) {
            handler.sendEmptyMessageDelayed(1, this.f6849ef);
        }
    }

    public void fm(WebView webView, String str, boolean z10) {
        if (z10 && ajl()) {
            fm();
        }
    }

    public void fm(WebView webView, String str) {
        lse lseVar = this.fm;
        if (lseVar == null || !com.bytedance.sdk.component.ef.ro.fm(lseVar.hi().lb(), str)) {
            return;
        }
        this.dsz++;
        com.bytedance.sdk.component.utils.ef.ro().post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.common.jnr.1
            @Override // java.lang.Runnable
            public void run() {
                if (jnr.this.ajl()) {
                    jnr.this.fm();
                }
            }
        });
    }

    public void ro(WebView webView, String str, boolean z10) {
        if (!z10 || this.jnr == null) {
            return;
        }
        fm(1);
    }

    public void fm(WebView webView, int i10) {
        yz yzVar = this.jnr;
        if (yzVar != null) {
            yzVar.fm(i10);
        }
        if (this.irt) {
            if (fm(i10, 30)) {
                fm(30, webView);
            }
            if (fm(i10, 50)) {
                fm(50, webView);
            }
            if (fm(i10, 70)) {
                fm(70, webView);
            }
        }
        if (this.jnr == null || i10 != 100) {
            return;
        }
        fm(1);
    }

    @SuppressLint({"ClickableViewAccessibility"})
    public void fm() {
        if (xgn.ajl()) {
            jnr();
        } else {
            com.bytedance.sdk.component.utils.ef.ro().post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.common.jnr.2
                @Override // java.lang.Runnable
                public void run() {
                    jnr.this.jnr();
                }
            });
        }
    }

    private void fm(final int i10) {
        WebView webView = this.f6850lb;
        if (webView != null && i10 == 1) {
            String url = webView.getUrl();
            if (TextUtils.isEmpty(url) || url.equals(this.wey)) {
                return;
            }
        }
        com.bytedance.sdk.component.utils.ef.ro().post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.common.jnr.4
            @Override // java.lang.Runnable
            public void run() {
                if (jnr.this.jnr != null) {
                    jnr.this.ku.set(false);
                    jnr.this.jnr.fm(jnr.this.fm, jnr.this.ajl, i10, jnr.this.wey, jnr.this.vt, jnr.this.onz, jnr.this.dsz, jnr.this.fhx);
                    jnr.this.dsz = 0;
                }
            }
        });
        yz();
    }

    @Override // com.bytedance.sdk.component.utils.mq.fm
    public void fm(Message message) {
        if (message.what == 1) {
            fm(0);
        }
    }

    public void fm(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 1) {
            this.gof = SystemClock.elapsedRealtime();
        }
    }

    private boolean fm(int i10, int i11) {
        if (i10 < i11 || this.qhl.contains(Integer.valueOf(i11)) || this.gqi < 2) {
            return false;
        }
        this.qhl.add(Integer.valueOf(i11));
        return true;
    }

    private void fm(int i10, WebView webView) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("load_progress", i10);
            jSONObject.put("progress_timestamp", System.currentTimeMillis());
            jSONObject.put("arbi_current_url", webView.getUrl());
        } catch (Throwable unused) {
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.fm, this.ajl, jSONObject);
    }
}
