package com.bytedance.sdk.openadsdk.core.vt;

import android.R;
import android.content.Context;
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.media3.exoplayer.ExoPlayer;
import com.bytedance.sdk.openadsdk.BuildConfig;
import com.bytedance.sdk.openadsdk.core.hxv;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.utils.bx;
import com.bytedance.sdk.openadsdk.utils.gc;
import com.bytedance.sdk.openadsdk.utils.xgn;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class mq extends com.bytedance.sdk.component.adexpress.jnr.fm {
    protected JSONObject dsz;
    protected com.bytedance.sdk.openadsdk.core.model.lse duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private com.bytedance.sdk.openadsdk.yz.dsz f7312ef;
    protected hxv fhx;
    com.bytedance.sdk.openadsdk.utils.fm gof;
    private final Map<String, com.bytedance.sdk.openadsdk.sds.fm.fm.lb> gqi;
    private final Runnable hlt;
    protected ku irt;
    protected String ku;
    private final com.bytedance.sdk.component.wu.ro.lb lse;
    private volatile int maa;
    protected com.bytedance.sdk.openadsdk.yz.yz.jnr onz;
    protected com.bytedance.sdk.openadsdk.core.fhx.yz.ro qhl;
    private lse.fm sds;
    protected Context vt;
    private com.bytedance.sdk.component.adexpress.ro.wsy wey;
    private String wu;

    public mq(Context context, com.bytedance.sdk.component.adexpress.ro.dsz dszVar, com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar, com.bytedance.sdk.openadsdk.core.model.lse lseVar) {
        super(context, dszVar);
        this.gqi = Collections.synchronizedMap(new HashMap());
        this.maa = 0;
        this.lse = new com.bytedance.sdk.component.wu.ro.lb("webviewrender_template") { // from class: com.bytedance.sdk.openadsdk.core.vt.mq.1
            @Override // java.lang.Runnable
            public void run() {
                if (((com.bytedance.sdk.component.adexpress.jnr.fm) mq.this).wsy.get()) {
                    return;
                }
                mq mqVar = mq.this;
                mqVar.dsz = mqVar.onz().lb();
                mq mqVar2 = mq.this;
                mqVar2.fm(mqVar2.dsz);
                if (mq.this.maa == 0) {
                    mq.this.gqi();
                }
                com.bytedance.sdk.openadsdk.core.fhx.lb().post(mq.this.hlt);
            }
        };
        this.hlt = new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.vt.mq.2
            @Override // java.lang.Runnable
            public void run() {
                if (((com.bytedance.sdk.component.adexpress.jnr.fm) mq.this).wsy.get() || mq.this.wey == null) {
                    return;
                }
                mq.this.qhl();
                mq.this.irt();
            }
        };
        if (this.jnr == null) {
            return;
        }
        this.vt = context;
        this.ku = dszVar.yz();
        this.duv = lseVar;
        this.onz = jnrVar;
        gqi();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void gqi() {
        if (this.jnr.getWebView() == null || !xgn.ajl()) {
            this.maa = 1;
            xgn.fm(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.vt.mq.3
                @Override // java.lang.Runnable
                public void run() {
                    mq.this.wey();
                }
            });
        } else {
            wey();
        }
        if (!fhx.ro(this.duv) || this.f6538lb) {
            return;
        }
        fhx.fm(this.duv);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void wey() {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.jnr;
        if (wsyVar == null || wsyVar.getWebView() == null || this.maa == 2) {
            return;
        }
        this.wu = fm(this.duv);
        this.jnr.setDisplayZoomControls(false);
        fm(gc.fm(this.wu));
        maa();
        hxv hxvVar = new hxv(this.vt);
        this.fhx = hxvVar;
        hxvVar.jnr(true);
        fhx();
        this.maa = 2;
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public void dsz() {
        super.dsz();
        com.bytedance.sdk.openadsdk.utils.fm fmVar = this.gof;
        if (fmVar != null) {
            fmVar.ro(this);
        }
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public void duv() {
        super.duv();
        com.bytedance.sdk.openadsdk.utils.fm fmVarJnr = com.bytedance.sdk.openadsdk.core.irt.fm().jnr();
        this.gof = fmVarJnr;
        fmVarJnr.fm(this);
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public void ef() {
        if (yz() == null) {
            return;
        }
        try {
            yz().getWebView().resumeTimers();
        } catch (Exception unused) {
        }
    }

    public void fhx() {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.jnr;
        if (wsyVar == null || wsyVar.getWebView() == null) {
            return;
        }
        this.jnr.setBackgroundColor(0);
        this.jnr.setBackgroundResource(R.color.transparent);
        fm(this.jnr);
        if (yz() != null) {
            this.f7312ef = new com.bytedance.sdk.openadsdk.yz.dsz(this.duv, yz().getWebView()).ro(false);
        }
        this.f7312ef.fm(this.onz);
        ku kuVar = new ku(this.vt, this.fhx, this.duv, this.f7312ef, onz());
        this.irt = kuVar;
        this.jnr.setWebViewClient(kuVar);
        this.jnr.setWebChromeClient(new com.bytedance.sdk.openadsdk.core.widget.fm.jnr(this.fhx, this.f7312ef));
        sds();
    }

    public void gof() {
    }

    public hxv hlt() {
        return this.fhx;
    }

    public void irt() {
        com.bytedance.sdk.component.adexpress.ro.wsy wsyVar = this.wey;
        if (wsyVar != null) {
            super.fm(wsyVar);
        }
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public void ku() {
        super.ku();
        if (this.fhx == null) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("expressShow", true);
            this.fhx.fm("expressShow", jSONObject);
            this.fhx.lb(true);
        } catch (Exception unused) {
        }
    }

    public ku lse() {
        return this.irt;
    }

    public void maa() {
        com.bytedance.sdk.openadsdk.core.model.lse lseVar = this.duv;
        if (lseVar == null || lseVar.zzn() == null) {
            return;
        }
        this.sds = this.duv.zzn();
    }

    public void qhl() {
        hxv hxvVar;
        com.bytedance.sdk.component.ef.wsy wsyVar = this.jnr;
        if (wsyVar == null || wsyVar.getWebView() == null || (hxvVar = this.fhx) == null) {
            return;
        }
        hxvVar.ro(this.jnr).fm(this.duv).lb(this.duv.eo()).yz(this.duv.gt()).ro(bx.fm(this.ku)).jnr(this.duv.uuz()).fm(this).fm(this.dsz).fm(this.jnr).fm(this.onz);
    }

    public void sds() {
        com.bytedance.sdk.component.adexpress.jnr.jnr.fm().fm(this.jnr, this.fhx);
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public void vt() {
        hxv hxvVar = this.fhx;
        if (hxvVar == null) {
            return;
        }
        hxvVar.fm("expressWebviewRecycle", (JSONObject) null);
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public com.bytedance.sdk.component.ef.wsy yz() {
        return this.jnr;
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm, com.bytedance.sdk.component.adexpress.ro.yz
    public int lb() {
        return this.duv.te();
    }

    public void ro(int i10) {
        if (this.fhx == null) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("zoom_type", i10);
            this.fhx.fm("expressAdViewWillZoom", jSONObject);
        } catch (JSONException e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.WebViewRender", e10.getMessage());
        }
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public void wu() {
        if (this.wsy.get()) {
            return;
        }
        super.wu();
        hxv hxvVar = this.fhx;
        if (hxvVar != null) {
            hxvVar.lb();
            this.fhx.duv();
            this.fhx = null;
        }
        com.bytedance.sdk.openadsdk.yz.dsz dszVar = this.f7312ef;
        if (dszVar != null) {
            dszVar.yz(false);
        }
        com.bytedance.sdk.openadsdk.core.fhx.lb().removeCallbacks(this.hlt);
        this.gqi.clear();
    }

    public static String fm(com.bytedance.sdk.openadsdk.core.model.lse lseVar) {
        return com.bytedance.sdk.component.adexpress.fm.ro.ro.yz((lseVar == null || !lseVar.hm()) ? null : "v3");
    }

    private void lb(boolean z10) {
        if (this.fhx == null || this.jnr == null) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("adVisible", z10);
            this.fhx.fm("expressAdShow", jSONObject);
            this.fhx.ro(z10);
        } catch (Exception unused) {
        }
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm, com.bytedance.sdk.component.adexpress.ro.yz
    public void fm(com.bytedance.sdk.component.adexpress.ro.wsy wsyVar) {
        this.wey = wsyVar;
        xgn.lb((Runnable) this.lse);
    }

    private void fm(com.bytedance.sdk.component.ef.wsy wsyVar) {
        if (wsyVar == null) {
            return;
        }
        try {
            com.bytedance.sdk.openadsdk.core.widget.fm.yz.fm(this.vt).fm(false).fm(wsyVar.getWebView());
            wsyVar.setVerticalScrollBarEnabled(false);
            wsyVar.setHorizontalScrollBarEnabled(false);
            com.bytedance.sdk.openadsdk.core.widget.fm.yz.fm(wsyVar);
            wsyVar.dsz();
            wsyVar.setUserAgentString(com.bytedance.sdk.openadsdk.utils.wey.fm(wsyVar.getWebView(), BuildConfig.VERSION_CODE));
            wsyVar.setMixedContentMode(0);
            wsyVar.setJavaScriptEnabled(true);
            wsyVar.setJavaScriptCanOpenWindowsAutomatically(true);
            wsyVar.setDomStorageEnabled(true);
            wsyVar.setDatabaseEnabled(true);
            wsyVar.setAllowFileAccess(false);
            wsyVar.setSupportZoom(true);
            wsyVar.setBuiltInZoomControls(true);
            wsyVar.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
            wsyVar.setUseWideViewPort(true);
            wsyVar.setCacheMode(-1);
        } catch (Exception e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.WebViewRender", e10.toString());
        }
    }

    public static boolean ro(String str) {
        return "banner_call".equals(str) || "banner_ad".equals(str) || "slide_banner_ad".equals(str) || "banner_ad_landingpage".equals(str);
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm
    public void fm(int i10) {
        if (i10 == this.ajl) {
            return;
        }
        this.ajl = i10;
        lb(i10 == 0);
    }

    @Override // com.bytedance.sdk.component.adexpress.jnr.fm, com.bytedance.sdk.component.adexpress.ro.ku
    public void fm(com.bytedance.sdk.component.adexpress.ro.onz onzVar) {
        super.fm(onzVar);
        if (this.yz) {
            com.bytedance.sdk.component.utils.ef.ro().postDelayed(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.vt.mq.4
                @Override // java.lang.Runnable
                public void run() {
                    WebView webView = ((com.bytedance.sdk.component.adexpress.jnr.fm) mq.this).jnr.getWebView();
                    if (webView != null) {
                        webView.resumeTimers();
                    }
                }
            }, ExoPlayer.DEFAULT_DETACH_SURFACE_TIMEOUT_MS);
        }
    }

    public void fm(com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar) {
        this.qhl = roVar;
        hxv hxvVar = this.fhx;
        if (hxvVar != null) {
            hxvVar.fm(roVar);
        }
    }
}
