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

import android.content.Context;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import com.brentvatne.react.ReactVideoViewManager;
import com.bytedance.sdk.component.NjR.AlY;
import com.bytedance.sdk.openadsdk.core.qsH.tN;
import com.iab.omid.library.bytedance2.adsession.FriendlyObstructionPurpose;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONArray;
import org.json.JSONObject;
/* loaded from: classes7.dex */
public class wN extends com.bytedance.sdk.component.NjR.AlY implements tN.InterfaceC0157tN {
    AtomicBoolean AlY;
    private com.bytedance.sdk.openadsdk.core.model.Wwa DSW;
    private long GA;
    private int NjR;
    protected boolean Sg;
    protected boolean YFl;
    private int YoT;
    private Sg eT;
    private List<String> nc;
    private String qsH;
    AtomicBoolean tN;
    private tN vc;
    private Ne wN;

    /* loaded from: classes2.dex */
    public interface Sg {
        View Sg();

        View YFl();

        void YFl(int i, int i2);

        void YFl(View view, int i);

        void e_();
    }

    public wN(Context context) {
        super(context);
        this.YFl = false;
        this.Sg = false;
        this.tN = new AtomicBoolean(false);
        this.AlY = new AtomicBoolean(false);
        this.NjR = 0;
    }

    public void YFl(com.bytedance.sdk.openadsdk.core.model.Wwa wwa, Sg sg, String str) {
        this.eT = sg;
        this.DSW = wwa;
        this.qsH = str;
        this.vc = new tN();
        this.wN = new Ne(getContext());
        setWebViewClient(new YFl(this));
        setWebChromeClient(new WebChromeClient() { // from class: com.bytedance.sdk.openadsdk.core.qsH.wN.1
            @Override // android.webkit.WebChromeClient
            public void onProgressChanged(WebView webView, int i) {
                wN.this.YoT = i;
                super.onProgressChanged(webView, i);
                if (i >= 100) {
                    wN.this.YFl();
                }
            }
        });
        com.bytedance.sdk.component.utils.DSW.Sg().post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.qsH.wN.2
            @Override // java.lang.Runnable
            public void run() {
                WebView webView = wN.this.getWebView();
                if (webView != null) {
                    webView.setOnTouchListener(new View.OnTouchListener() { // from class: com.bytedance.sdk.openadsdk.core.qsH.wN.2.1
                        @Override // android.view.View.OnTouchListener
                        public boolean onTouch(View view, MotionEvent motionEvent) {
                            wN.this.wN.onTouchEvent(motionEvent);
                            return false;
                        }
                    });
                }
            }
        });
    }

    private void lG() {
        if (this.nc == null) {
            com.bytedance.sdk.openadsdk.AlY.tN.Sg(this.DSW, this.qsH, "dsp_html_success_url", (JSONObject) null);
        } else {
            com.bytedance.sdk.openadsdk.AlY.tN.YFl(new com.bytedance.sdk.component.qsH.qsH("dsp_html_error_url") { // from class: com.bytedance.sdk.openadsdk.core.qsH.wN.3
                @Override // java.lang.Runnable
                public void run() {
                    try {
                        if (wN.this.nc != null && wN.this.AlY.compareAndSet(false, true)) {
                            JSONObject jSONObject = new JSONObject();
                            JSONArray jSONArray = new JSONArray();
                            for (String str : wN.this.nc) {
                                jSONArray.put(str);
                            }
                            jSONObject.put("url", jSONArray);
                            com.bytedance.sdk.openadsdk.AlY.tN.Sg(wN.this.DSW, wN.this.qsH, "dsp_html_error_url", jSONObject);
                            wN.this.nc = null;
                        }
                    } catch (Exception unused) {
                    }
                }
            });
        }
    }

    @Override // com.bytedance.sdk.component.NjR.AlY
    public void YoT() {
        super.YoT();
        this.vc.Sg();
    }

    public void YFl(View view, FriendlyObstructionPurpose friendlyObstructionPurpose) {
        this.vc.YFl(view, friendlyObstructionPurpose);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.bytedance.sdk.component.NjR.AlY, android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (this.YFl) {
            this.vc.YFl(getWebView());
        }
    }

    @Override // android.view.View
    protected void onVisibilityChanged(View view, int i) {
        super.onVisibilityChanged(view, i);
        boolean z = i == 0;
        this.Sg = z;
        this.vc.YFl(z);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.bytedance.sdk.component.NjR.AlY, android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(ReactVideoViewManager.PROP_RATE, this.YoT / 100.0f);
        } catch (Throwable unused) {
        }
        com.bytedance.sdk.openadsdk.AlY.tN.Sg(this.DSW, this.qsH, "load_rate", jSONObject);
        this.vc.YFl();
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x00ab  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00c6  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0117  */
    /* JADX WARN: Removed duplicated region for block: B:52:? A[RETURN, SYNTHETIC] */
    @Override // com.bytedance.sdk.openadsdk.core.qsH.tN.InterfaceC0157tN
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void YFl(java.lang.String r21) {
        /*
            Method dump skipped, instructions count: 283
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.sdk.openadsdk.core.qsH.wN.YFl(java.lang.String):void");
    }

    public void EH() {
        Sg sg = this.eT;
        if (sg != null) {
            sg.e_();
        }
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("render_duration", SystemClock.elapsedRealtime() - this.GA);
        } catch (Throwable unused) {
        }
        com.bytedance.sdk.openadsdk.AlY.tN.Sg(this.DSW, this.qsH, "render_html_success", jSONObject);
    }

    @Override // com.bytedance.sdk.openadsdk.core.qsH.tN.InterfaceC0157tN
    public void YFl(int i, int i2) {
        Sg sg = this.eT;
        if (sg != null) {
            sg.YFl(i, i2);
        }
        this.NjR = i2;
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("error_code", i2);
            jSONObject.put("render_duration", SystemClock.elapsedRealtime() - this.GA);
        } catch (Throwable unused) {
        }
        com.bytedance.sdk.openadsdk.AlY.tN.Sg(this.DSW, this.qsH, "render_html_fail", jSONObject);
    }

    @Override // com.bytedance.sdk.openadsdk.core.qsH.tN.InterfaceC0157tN
    public void Sg(String str) {
        if (this.nc == null) {
            this.nc = new ArrayList();
        }
        this.nc.add(str);
    }

    @Override // com.bytedance.sdk.openadsdk.core.qsH.tN.InterfaceC0157tN
    public void YFl() {
        if (this.tN.compareAndSet(false, true)) {
            this.YFl = true;
            this.vc.YFl(getWebView());
            this.vc.YFl(this.Sg);
            EH();
            lG();
        }
    }

    public void rkt() {
        this.tN.set(false);
        String PT = this.DSW.PT();
        if (TextUtils.isEmpty(PT)) {
            return;
        }
        String YFl2 = com.bytedance.sdk.openadsdk.core.YoT.wN.YFl(PT);
        String str = TextUtils.isEmpty(YFl2) ? PT : YFl2;
        this.NjR = 0;
        YFl(null, str, "text/html", "UTF-8", null);
        this.GA = SystemClock.elapsedRealtime();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes2.dex */
    public static class YFl extends AlY.YFl {
        public static final Set<String> YFl = new HashSet<String>() { // from class: com.bytedance.sdk.openadsdk.core.qsH.wN.YFl.1
            {
                add(".jpeg");
                add(".png");
                add(".bmp");
                add(".gif");
                add(".jpg");
                add(".webp");
            }
        };
        tN.InterfaceC0157tN Sg;

        public YFl(tN.InterfaceC0157tN interfaceC0157tN) {
            this.Sg = interfaceC0157tN;
        }

        @Override // android.webkit.WebViewClient
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            this.Sg.YFl(str);
            return true;
        }

        @Override // android.webkit.WebViewClient
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            super.onReceivedHttpError(webView, webResourceRequest, webResourceResponse);
            if (webResourceRequest == null || webResourceResponse == null || webResourceRequest.getUrl() == null) {
                return;
            }
            if (webResourceRequest.isForMainFrame()) {
                YFl(webResourceRequest.getUrl().toString(), webResourceResponse.getStatusCode(), "");
            }
            YFl(webResourceRequest.getUrl().toString());
        }

        @Override // android.webkit.WebViewClient
        public void onReceivedError(WebView webView, int i, String str, String str2) {
            super.onReceivedError(webView, i, str, str2);
        }

        @Override // android.webkit.WebViewClient
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            super.onReceivedError(webView, webResourceRequest, webResourceError);
            if (webResourceRequest == null || webResourceRequest.getUrl() == null) {
                return;
            }
            YFl(webResourceRequest.getUrl().toString());
        }

        private void YFl(String str) {
            int lastIndexOf;
            tN.InterfaceC0157tN interfaceC0157tN;
            if (!TextUtils.isEmpty(str) && (lastIndexOf = str.lastIndexOf(".")) > 0) {
                if (!YFl.contains(str.substring(lastIndexOf).toLowerCase()) || (interfaceC0157tN = this.Sg) == null) {
                    return;
                }
                interfaceC0157tN.Sg(str);
            }
        }

        @Override // android.webkit.WebViewClient
        public void onPageFinished(WebView webView, String str) {
            super.onPageFinished(webView, str);
            tN.InterfaceC0157tN interfaceC0157tN = this.Sg;
            if (interfaceC0157tN != null) {
                interfaceC0157tN.YFl();
            }
        }

        private void YFl(String str, int i, String str2) {
            tN.InterfaceC0157tN interfaceC0157tN = this.Sg;
            if (interfaceC0157tN != null) {
                interfaceC0157tN.YFl(106, i);
            }
        }
    }

    /* loaded from: classes2.dex */
    public static class tN {
        protected int YFl = 0;
        private com.bytedance.sdk.openadsdk.core.YoT.vc Sg = com.bytedance.sdk.openadsdk.core.YoT.vc.YFl();

        tN() {
        }

        public void YFl(WebView webView) {
            if (webView != null && this.YFl == 0) {
                if (this.Sg == null) {
                    this.Sg = com.bytedance.sdk.openadsdk.core.YoT.vc.YFl();
                }
                this.Sg.YFl(webView);
                this.Sg.Sg();
                this.YFl = 1;
            }
        }

        public void YFl(boolean z) {
            com.bytedance.sdk.openadsdk.core.YoT.vc vcVar;
            if (this.YFl == 1 && z && (vcVar = this.Sg) != null) {
                vcVar.tN();
                this.YFl = 3;
            }
        }

        public void YFl(View view, FriendlyObstructionPurpose friendlyObstructionPurpose) {
            com.bytedance.sdk.openadsdk.core.YoT.vc vcVar = this.Sg;
            if (vcVar != null) {
                vcVar.YFl(view, friendlyObstructionPurpose);
            }
        }

        public void YFl() {
            com.bytedance.sdk.openadsdk.core.YoT.vc vcVar;
            int i = this.YFl;
            if (i != 0 && i != 4 && (vcVar = this.Sg) != null) {
                vcVar.AlY();
            }
            this.YFl = 4;
            this.Sg = null;
        }

        public void Sg() {
            YFl();
        }
    }
}
