package com.bytedance.sdk.openadsdk.component.reward.lb.fm;

import android.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.widget.FrameLayout;
import androidx.media3.common.MimeTypes;
import com.bykv.vk.openvk.preload.falconx.loader.ILoader;
import com.bykv.vk.openvk.preload.geckox.model.WebResourceResponseModel;
import com.bytedance.sdk.component.ef.wsy;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.BuildConfig;
import com.bytedance.sdk.openadsdk.core.fhx;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.hxv;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.widget.fm.ajl;
import com.bytedance.sdk.openadsdk.utils.bx;
import com.bytedance.sdk.openadsdk.yz.dsz;
import com.bytedance.sdk.openadsdk.yz.duv;
import com.bytedance.sdk.openadsdk.yz.lb;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class ro extends com.bytedance.sdk.openadsdk.core.ajl.lb {
    private long ajl;
    private boolean dsz;
    private dsz duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private String f6950ef;
    private ajl fhx;
    final lse fm;
    private volatile int gof;
    private volatile int gqi;
    private AtomicBoolean gzf;
    private jnr hi;
    private fm hlt;
    private String irt;
    private yz jnr;
    private com.bytedance.sdk.openadsdk.sds.fm.fm.lb ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private hxv f6951lb;
    private com.bytedance.sdk.openadsdk.common.jnr lse;
    private int maa;
    private AtomicBoolean mq;
    private AtomicBoolean nt;
    private boolean onz;
    private ILoader qhl;
    com.bytedance.sdk.openadsdk.core.lb.ro ro;
    private int sds;
    private int vt;
    private volatile int wey;
    private final AtomicBoolean wsy;
    private final Activity wu;
    private wsy yz;

    public static class fm implements duv {
        private final int fm;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private final String f6952lb;
        private final lse ro;
        private final WeakReference<ro> yz;

        public fm(int i10, lse lseVar, String str, ro roVar) {
            this.fm = i10;
            this.ro = lseVar;
            this.f6952lb = str;
            this.yz = new WeakReference<>(roVar);
        }

        @Override // com.bytedance.sdk.openadsdk.yz.duv
        public void fm(int i10) {
            ro roVar = this.yz.get();
            if (roVar != null) {
                lb.fm.fm(this.fm, roVar.wey, roVar.gqi, roVar.gof - roVar.gqi, this.ro, this.f6952lb, i10);
            }
        }
    }

    public ro(Activity activity, lse lseVar) {
        super(activity);
        this.wsy = new AtomicBoolean(false);
        this.gof = 0;
        this.gqi = 0;
        this.wey = 0;
        this.nt = new AtomicBoolean(false);
        this.mq = new AtomicBoolean(false);
        this.gzf = new AtomicBoolean(false);
        this.wu = activity;
        this.fm = lseVar;
    }

    public static /* synthetic */ int dsz(ro roVar) {
        int i10 = roVar.wey;
        roVar.wey = i10 + 1;
        return i10;
    }

    public static /* synthetic */ int duv(ro roVar) {
        int i10 = roVar.gqi;
        roVar.gqi = i10 + 1;
        return i10;
    }

    public static /* synthetic */ int vt(ro roVar) {
        int i10 = roVar.gof;
        roVar.gof = i10 + 1;
        return i10;
    }

    public void setLoadStatusListener(jnr jnrVar) {
        this.hi = jnrVar;
    }

    public boolean yz() {
        return this.dsz;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void duv() {
        this.wsy.get();
        if (this.wsy.get()) {
            return;
        }
        this.wsy.set(true);
        if (this.hi != null && !this.mq.get()) {
            this.mq.set(true);
            jnr jnrVar = this.hi;
            yz yzVar = this.jnr;
            jnrVar.fm(yzVar != null ? yzVar.fm() : "", 2, 0);
        }
        com.bytedance.sdk.openadsdk.yz.lb.fm(this.fm, this.f6950ef, System.currentTimeMillis() - this.ajl, true);
    }

    private void ku() {
        hxv hxvVar = new hxv(this.wu);
        this.f6951lb = hxvVar;
        hxvVar.ro(this.yz).fm(com.bytedance.sdk.openadsdk.core.vt.ro.lb.fm(this.fm)).lb(this.fm.eo()).yz(this.fm.gt()).fm(this.fm).ro(-1).fm(this.fm.zh()).ro(this.f6950ef).jnr(this.fm.uuz()).fm(this.yz).fm(new com.bytedance.sdk.openadsdk.core.widget.jnr() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.fm.ro.7
            @Override // com.bytedance.sdk.openadsdk.core.widget.jnr
            public void fm() {
                if (ro.this.fhx != null) {
                    ro.this.fhx.lb();
                }
            }
        });
    }

    @SuppressLint({"ClickableViewAccessibility"})
    private void vt() {
        wsy wsyVar = this.yz;
        if (wsyVar == null || wsyVar.getWebView() == null) {
            return;
        }
        com.bytedance.sdk.openadsdk.core.widget.fm.yz.fm(gof.fm()).fm(false).ro(false).fm(this.yz.getWebView());
        wsy wsyVar2 = this.yz;
        if (wsyVar2 != null && wsyVar2.getWebView() != null) {
            this.hlt = new fm(this.sds, this.fm, this.f6950ef, this);
            dsz dszVarRo = new dsz(this.fm, this.yz.getWebView(), this.hlt, this.maa).ro(true);
            this.duv = dszVarRo;
            dszVarRo.fm(this.f6950ef);
            com.bytedance.sdk.openadsdk.common.jnr jnrVarFm = bx.fm(this.fm, this.yz, this.wu, this.f6950ef);
            this.lse = jnrVarFm;
            if (jnrVarFm != null) {
                jnrVarFm.fm(this.f6950ef);
            }
            bx.fm(this.fm, this.yz);
        }
        ku();
        this.yz.setLandingPage(true);
        this.yz.setTag(this.f6950ef);
        this.yz.setMaterialMeta(this.fm.ooo());
        ajl ajlVar = new ajl(gof.fm(), this.f6951lb, this.fm.eo(), this.lse, this.duv, true) { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.fm.ro.2
            @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
            public void onPageFinished(WebView webView, String str) {
                super.onPageFinished(webView, str);
                ro.this.duv();
            }

            @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
            public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
                super.onPageStarted(webView, str, bitmap);
                if (ro.this.hi != null && !ro.this.nt.get()) {
                    ro.this.nt.set(true);
                    ro.this.hi.fm(ro.this.jnr != null ? ro.this.jnr.fm() : "", 1, 0);
                }
                ro.this.ajl = System.currentTimeMillis();
            }

            @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
            public void onReceivedError(WebView webView, int i10, String str, String str2) {
                super.onReceivedError(webView, i10, str, str2);
                String strYz = ajl.yz(str2);
                boolean z10 = false;
                if (this.ajl != null) {
                    this.ajl.fm(webView, i10, str, str2, ajl.yz(str2), (webView == null || str2 == null || !str2.equals(webView.getUrl())) ? false : true);
                }
                boolean z11 = strYz != null && strYz.startsWith(MimeTypes.BASE_TYPE_IMAGE);
                if (strYz != null && strYz.startsWith("mp4")) {
                    z10 = true;
                }
                if (z11 || z10 || ro.this.wsy.get() || ro.this.hi == null || ro.this.mq.get()) {
                    return;
                }
                ro.this.mq.set(true);
                ro.this.hi.fm(ro.this.jnr != null ? ro.this.jnr.fm() : "", 3, i10);
            }

            @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
            public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
                if (sslErrorHandler != null && ro.this.hi != null && !ro.this.mq.get()) {
                    ro.this.mq.set(true);
                    ro.this.hi.fm(ro.this.jnr != null ? ro.this.jnr.fm() : "", 3, sslError != null ? sslError.getPrimaryError() : 0);
                }
                super.onReceivedSslError(webView, sslErrorHandler, sslError);
            }

            @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
            public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
                try {
                    if (TextUtils.isEmpty(ro.this.irt)) {
                        return super.shouldInterceptRequest(webView, str);
                    }
                    ro.vt(ro.this);
                    WebResourceResponseModel webResourceResponseModelFm = com.bytedance.sdk.openadsdk.wsy.ro.fm().fm(ro.this.qhl, ro.this.irt, str);
                    if (webResourceResponseModelFm != null && webResourceResponseModelFm.getWebResourceResponse() != null) {
                        ro.duv(ro.this);
                        return webResourceResponseModelFm.getWebResourceResponse();
                    }
                    if (webResourceResponseModelFm != null && webResourceResponseModelFm.getMsg() == 2) {
                        ro.dsz(ro.this);
                    }
                    return super.shouldInterceptRequest(webView, str);
                } catch (Throwable th) {
                    wey.fm("LandingPageModel", "shouldInterceptRequest url error", th);
                    return super.shouldInterceptRequest(webView, str);
                }
            }
        };
        this.fhx = ajlVar;
        this.yz.setWebViewClient(ajlVar);
        this.fhx.fm(this.fm);
        this.fhx.fm(this.f6950ef);
        this.yz.setWebChromeClient(new com.bytedance.sdk.openadsdk.core.widget.fm.jnr(this.f6951lb, this.duv, this.lse) { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.fm.ro.3
            @Override // com.bytedance.sdk.openadsdk.core.widget.fm.jnr, android.webkit.WebChromeClient
            public void onProgressChanged(WebView webView, int i10) {
                super.onProgressChanged(webView, i10);
                if (ro.this.wu == null || ro.this.wu.isFinishing() || i10 != 100) {
                    return;
                }
                ro.this.duv();
            }
        });
        if (this.ku == null) {
            this.ku = com.bytedance.sdk.openadsdk.sds.fm.fm.yz.fm(gof.fm(), this.f6950ef);
        }
        this.yz.setDownloadListener(new DownloadListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.fm.ro.4
            @Override // android.webkit.DownloadListener
            public void onDownloadStart(String str, String str2, String str3, String str4, long j10) {
                if (ro.this.ku != null) {
                    ro.this.ku.fm(ro.this.fm);
                }
            }
        });
        wsy wsyVar3 = this.yz;
        wsyVar3.setUserAgentString(com.bytedance.sdk.openadsdk.utils.wey.fm(wsyVar3.getWebView(), BuildConfig.VERSION_CODE));
        this.yz.setMixedContentMode(0);
        this.yz.getWebView().setOnScrollChangeListener(new View.OnScrollChangeListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.fm.ro.5
            @Override // android.view.View.OnScrollChangeListener
            public void onScrollChange(View view, int i10, int i11, int i12, int i13) {
                if (ro.this.duv != null) {
                    ro.this.duv.ro(i11);
                }
            }
        });
        this.yz.getWebView().setOnTouchListener(new View.OnTouchListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.fm.ro.6
            @Override // android.view.View.OnTouchListener
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (!ro.this.onz) {
                    ro.this.ro.onTouch(view, motionEvent);
                }
                if (!ro.this.onz && motionEvent.getAction() == 1 && ro.this.ro.ajl()) {
                    ro.this.yz.getWebView().performClick();
                    ro.this.onz = true;
                }
                if (ro.this.duv != null) {
                    ro.this.duv.fm(motionEvent);
                }
                if (ro.this.lse == null) {
                    return false;
                }
                ro.this.lse.fm(motionEvent);
                return false;
            }
        });
        this.yz.getWebView().setOnClickListener(this.ro);
        com.bytedance.sdk.openadsdk.yz.lb.fm(this.fm, this.f6950ef, this.maa);
    }

    public boolean ajl() {
        return this.wsy.get();
    }

    public void ef() {
        dsz dszVar = this.duv;
        if (dszVar != null) {
            dszVar.wu();
        }
    }

    public void jnr() {
        yz yzVar = this.jnr;
        if (yzVar == null || this.yz == null) {
            return;
        }
        float fJnr = yzVar.jnr();
        float fAjl = this.jnr.ajl();
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int) this.jnr.wsy(), (int) this.jnr.wu());
        layoutParams.leftMargin = (int) fJnr;
        layoutParams.topMargin = (int) fAjl;
        this.yz.setLayoutParams(layoutParams);
        addView(this.yz);
    }

    public void lb() {
        if (this.jnr == null) {
            return;
        }
        fm();
        String strYz = this.jnr.yz();
        if (!TextUtils.isEmpty(strYz)) {
            com.bytedance.sdk.openadsdk.utils.lse.fm(this.yz, strYz);
            this.dsz = true;
        } else {
            jnr jnrVar = this.hi;
            if (jnrVar != null) {
                jnrVar.fm(this.jnr.fm(), 3, -2);
            }
        }
    }

    public void ro() {
        lse lseVar = this.fm;
        if (lseVar == null || lseVar.hlt() == null) {
            return;
        }
        fhx.lb().postDelayed(new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.fm.ro.1
            @Override // java.lang.Runnable
            public void run() {
                if (ro.this.wsy.get()) {
                    return;
                }
                ro roVar = ro.this;
                com.bytedance.sdk.openadsdk.yz.lb.fm(roVar.fm, roVar.f6950ef, System.currentTimeMillis() - ro.this.ajl, false);
                if (ro.this.hi == null || ro.this.mq.get()) {
                    return;
                }
                ro.this.mq.set(true);
                ro.this.hi.fm(ro.this.jnr != null ? ro.this.jnr.fm() : "", 3, -1);
            }
        }, this.fm.hlt().fm() * 1000);
    }

    public void wsy() {
        if (this.yz != null) {
            this.gzf.set(true);
            this.yz.setVisibility(8);
            com.bytedance.sdk.openadsdk.core.bx.fm(this.yz.getWebView());
        }
    }

    public void wu() {
        hxv hxvVar = this.f6951lb;
        if (hxvVar != null) {
            hxvVar.ku();
        }
        dsz dszVar = this.duv;
        if (dszVar != null) {
            dszVar.wsy();
        }
    }

    public void fm(yz yzVar) {
        this.jnr = yzVar;
        String strEf = yzVar.ef();
        this.f6950ef = strEf;
        this.vt = bx.fm(strEf);
        lse lseVar = this.fm;
        if (lseVar != null) {
            this.irt = lseVar.kec();
        }
        if (!TextUtils.isEmpty(this.irt)) {
            this.qhl = com.bytedance.sdk.openadsdk.wsy.ro.fm().ro();
            int iFm = com.bytedance.sdk.openadsdk.wsy.ro.fm().fm(this.qhl, this.irt);
            this.sds = iFm;
            this.maa = iFm > 0 ? 2 : 0;
        }
        HashMap map = new HashMap();
        map.put("click_scence", 1);
        map.put("dynamic_show_type", 11);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("render_sequence", 11);
        } catch (JSONException unused) {
        }
        map.put("pag_json_data", jSONObject);
        View viewFindViewById = this.wu.findViewById(R.id.content);
        Activity activity = this.wu;
        lse lseVar2 = this.fm;
        String str = this.f6950ef;
        com.bytedance.sdk.openadsdk.core.lb.ro roVar = new com.bytedance.sdk.openadsdk.core.lb.ro(activity, lseVar2, str, bx.fm(str), true);
        this.ro = roVar;
        roVar.fm(map);
        this.ro.ro(viewFindViewById);
    }

    public void fm() {
        Long lValueOf = Long.valueOf(SystemClock.elapsedRealtime());
        this.yz = new wsy(this.wu, wsy.lb.LANDING_PAGE);
        vt();
        if (com.bytedance.sdk.openadsdk.core.model.wey.jnr(this.fm)) {
            ro();
        }
        lb.fm.fm(SystemClock.elapsedRealtime() - lValueOf.longValue(), this.fm, this.f6950ef, this.qhl, this.irt);
    }
}
