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

import android.R;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.DownloadListener;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import com.bykv.vk.openvk.fm.fm.fm.lb.b;
import com.bykv.vk.openvk.preload.falconx.loader.ILoader;
import com.bykv.vk.openvk.preload.geckox.model.WebResourceResponseModel;
import com.bytedance.sdk.component.utils.gzf;
import com.bytedance.sdk.component.utils.maa;
import com.bytedance.sdk.openadsdk.BuildConfig;
import com.bytedance.sdk.openadsdk.core.hxv;
import com.bytedance.sdk.openadsdk.core.lb.lb;
import com.bytedance.sdk.openadsdk.core.lb.ro;
import com.bytedance.sdk.openadsdk.core.model.ai;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.model.wey;
import com.bytedance.sdk.openadsdk.core.widget.fm.wsy;
import com.bytedance.sdk.openadsdk.utils.DeviceUtils;
import com.bytedance.sdk.openadsdk.utils.bx;
import com.bytedance.sdk.openadsdk.utils.zan;
import com.bytedance.sdk.openadsdk.yz.lb;
import com.google.android.gms.measurement.internal.u1;
import defpackage.e;
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class gof implements com.bytedance.sdk.openadsdk.dsz.ef {
    private boolean ado;
    private final com.bytedance.sdk.openadsdk.component.reward.fm.ro ai;
    private boolean bkb;
    private long bx;
    private int dsz;
    private final boolean duv;
    private com.bytedance.sdk.component.ef.wsy fhx;
    hxv fm;

    /* JADX INFO: renamed from: gc, reason: collision with root package name */
    private boolean f6916gc;
    private boolean gof;
    private boolean gqi;
    private long hlt;
    private boolean hxv;
    private int ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected String f6919lb;
    private wsy.fm lmk;
    private float lse;
    private float maa;
    private boolean mj;
    private com.bytedance.sdk.openadsdk.common.jnr mpp;
    private int onz;
    private boolean pkk;

    /* JADX INFO: renamed from: qf, reason: collision with root package name */
    private String f6921qf;
    private View sds;
    private ILoader si;
    private int tzk;
    private final String vt;
    private com.bytedance.sdk.openadsdk.onz.yz vvj;
    private com.bytedance.sdk.openadsdk.core.widget.fm.ajl wbw;
    private View wey;
    protected com.bytedance.sdk.openadsdk.yz.yz.jnr wsy;
    private boolean xgn;
    com.bytedance.sdk.openadsdk.yz.dsz yz;
    protected boolean ro = true;
    private boolean irt = false;
    private final AtomicBoolean qhl = new AtomicBoolean(true);
    int jnr = 0;
    String ajl = "";
    boolean wu = false;
    private SparseArray<lb.fm> hi = new SparseArray<>();
    private boolean nt = true;
    private float mq = -1.0f;
    private float gzf = -1.0f;
    private boolean ol = false;

    /* JADX INFO: renamed from: ha, reason: collision with root package name */
    private long f6917ha = 0;
    private long mon = -1;
    private volatile int zan = 0;
    private int lz = -1;

    /* JADX INFO: renamed from: ib, reason: collision with root package name */
    private volatile int f6918ib = 0;

    /* JADX INFO: renamed from: ne, reason: collision with root package name */
    private volatile int f6920ne = 0;
    private long kwx = 0;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    public boolean f6915ef = false;
    private int bwv = -1;

    public interface ro {
        void fm(WebView webView, String str);
    }

    public gof(com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar) {
        this.ai = roVar;
        this.vt = roVar.jnr;
        this.duv = roVar.yz;
    }

    public static /* synthetic */ int dsz(gof gofVar) {
        int i10 = gofVar.f6920ne;
        gofVar.f6920ne = i10 + 1;
        return i10;
    }

    private com.bytedance.sdk.openadsdk.yz.yz.jnr hxv() {
        return new com.bytedance.sdk.openadsdk.yz.gqi(2, this.duv ? "rewarded_video" : "fullscreen_interstitial_ad", this.ai.ro);
    }

    public static /* synthetic */ int ku(gof gofVar) {
        int i10 = gofVar.f6918ib;
        gofVar.f6918ib = i10 + 1;
        return i10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void pkk() {
        this.pkk = true;
        this.ado = false;
        this.ai.zan.removeMessages(600);
        this.ai.zan.removeMessages(700);
        this.ai.zan.removeMessages(900);
        this.ai.f6938ha.yz(false);
        this.ai.irt.set(true);
        this.ai.so.dsz();
        lse lseVar = this.ai.ro;
        lseVar.vu();
        if (lseVar.vu() || !bx.wu(ai.fm(lseVar))) {
            return;
        }
        View viewVt = this.ai.hxv.vt();
        View.OnClickListener onClickListener = (View.OnClickListener) viewVt.getTag(viewVt.getId());
        if (onClickListener != null) {
            fm fmVar = new fm(this.ai, viewVt, onClickListener);
            viewVt.setOnClickListener(fmVar);
            viewVt.setOnTouchListener(fmVar);
        }
    }

    public boolean ai() {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.fhx;
        return wsyVar == null || wsyVar.getWebView() == null;
    }

    public hxv ef() {
        return this.fm;
    }

    public void fm(boolean z10) {
        this.ro = z10;
    }

    public int gof() {
        return this.jnr;
    }

    public String gqi() {
        return this.ajl;
    }

    public boolean gzf() {
        return this.ado;
    }

    public boolean ha() {
        return this.f6915ef;
    }

    public boolean hlt() {
        return this.wu;
    }

    public boolean lb() {
        return this.xgn;
    }

    public void ol() {
        com.bytedance.sdk.openadsdk.yz.dsz dszVar = this.yz;
        if (dszVar != null) {
            dszVar.jnr();
        }
    }

    public boolean onz() {
        return this.gof;
    }

    public boolean wbw() {
        return this.pkk;
    }

    public void wsy(boolean z10) {
        this.ado = z10;
    }

    public com.bytedance.sdk.component.ef.wsy wu() {
        return this.fhx;
    }

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

    public static /* synthetic */ int onz(gof gofVar) {
        int i10 = gofVar.zan;
        gofVar.zan = i10 + 1;
        return i10;
    }

    public boolean dsz() {
        return this.qhl.get();
    }

    public boolean duv() {
        String str = this.f6919lb;
        if (str == null) {
            return false;
        }
        try {
            return Uri.parse(str).getQueryParameterNames().contains("show_landingpage");
        } catch (Exception unused) {
            return false;
        }
    }

    public void fhx() {
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.wu();
        }
        com.bytedance.sdk.openadsdk.yz.dsz dszVar = this.yz;
        if (dszVar != null) {
            dszVar.wu();
        }
    }

    public void hi() {
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.ef();
        }
    }

    public void irt() {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.fhx;
        if (wsyVar != null) {
            wsyVar.onz();
        }
        if (this.mon > 0) {
            this.bx = (SystemClock.elapsedRealtime() - this.mon) + this.bx;
            this.mon = 0L;
        }
        hxv hxvVar = this.fm;
        if (hxvVar != null) {
            hxvVar.ro(false);
            ro(this.fm, false);
            fm(this.fm, true, false);
        }
    }

    public void ku() {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.fhx;
        if (wsyVar != null) {
            gzf.fm(wsyVar);
        }
        lse lseVar = this.ai.ro;
        long j10 = this.bx;
        if (j10 > 0) {
            if (this.mon > 0) {
                this.bx = (SystemClock.elapsedRealtime() - this.mon) + j10;
            }
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("endcard_overlay_render_type", lse.lb(lseVar) ? 7 : 0);
            } catch (Throwable unused) {
            }
            com.bytedance.sdk.openadsdk.yz.lb.fm(this.ai.ro, this.vt, "second_endcard_duration", jSONObject, this.bx);
        }
        this.fhx = null;
        if (this.wsy != null && !wey.yz(lseVar) && !wey.wu(lseVar) && !lse.lb(lseVar)) {
            this.wsy.fm(true);
            this.wsy.ku();
        }
        hxv hxvVar = this.fm;
        if (hxvVar != null) {
            hxvVar.duv();
        }
        com.bytedance.sdk.openadsdk.yz.dsz dszVar = this.yz;
        if (dszVar != null) {
            dszVar.yz(lseVar.pf());
        }
        com.bytedance.sdk.openadsdk.onz.yz yzVar = this.vvj;
        if (yzVar != null) {
            yzVar.lb();
        }
        DeviceUtils.AudioInfoReceiver.ro(this);
    }

    public void lse() {
        com.bytedance.sdk.openadsdk.yz.dsz dszVar = this.yz;
        if (dszVar != null) {
            dszVar.fm(System.currentTimeMillis());
        }
    }

    public void maa() {
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.ajl();
        }
    }

    public boolean mq() {
        this.qhl.get();
        return this.gof && this.qhl.get();
    }

    public boolean nt() {
        hxv hxvVar = this.fm;
        if (hxvVar == null) {
            return false;
        }
        return hxvVar.ef();
    }

    public void qhl() {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.fhx;
        if (wsyVar != null) {
            wsyVar.duv();
        }
        if (this.mon == 0) {
            this.mon = SystemClock.elapsedRealtime();
        }
        lse lseVar = this.ai.ro;
        hxv hxvVar = this.fm;
        if (hxvVar != null) {
            hxvVar.ku();
            com.bytedance.sdk.component.ef.wsy wsyVar2 = this.fhx;
            if (wsyVar2 != null) {
                if (wsyVar2.getVisibility() == 0) {
                    this.fm.ro(true);
                    ro(this.fm, true);
                    fm(this.fm, false, true);
                    if (ai.wu(lseVar) && !this.pkk && this.ai.ro.vu()) {
                        wsy();
                    }
                } else {
                    this.fm.ro(false);
                    ro(this.fm, false);
                    fm(this.fm, true, false);
                }
            }
        }
        com.bytedance.sdk.openadsdk.yz.dsz dszVar = this.yz;
        if (dszVar != null) {
            dszVar.wsy();
        }
    }

    public void sds() {
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.wsy();
        }
    }

    public void vt() {
        com.bytedance.sdk.openadsdk.activity.single.wu wuVar;
        lse lseVar = this.ai.ro;
        String strWu = lseVar.wu();
        if (!TextUtils.isEmpty(strWu) && (wuVar = this.ai.zow) != null && (wuVar.xgn() || this.ai.zow.zan().nt())) {
            this.f6919lb = strWu;
        } else if (ai.jnr(lseVar)) {
            b bVarEx = lseVar.ex();
            if (bVarEx != null) {
                this.f6919lb = bVarEx.f5928h;
            }
        } else {
            this.f6919lb = ai.duv(lseVar);
        }
        String strFm = fm(this.f6919lb, lseVar, this.ku, this.onz, this.dsz);
        this.f6919lb = strFm;
        if (TextUtils.isEmpty(strFm)) {
            return;
        }
        this.hxv = this.f6919lb.contains("use_second_endcard=1");
    }

    public boolean wey() {
        return lse.lb(this.ai.ro) ? this.hxv && !this.f6916gc && this.ai.wbw.duv() : this.hxv && !this.f6916gc && this.qhl.get() && this.gof;
    }

    public void ajl() {
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar = this.ai;
        lse lseVar = roVar.ro;
        if (TextUtils.isEmpty(lse.fm(roVar.bx, lseVar))) {
            if (lseVar != null && !lseVar.hxv() && this.si == null && duv()) {
                this.f6921qf = lseVar.kec();
                this.si = com.bytedance.sdk.openadsdk.wsy.ro.fm().ro();
                int iFm = com.bytedance.sdk.openadsdk.wsy.ro.fm().fm(this.si, this.f6921qf);
                this.tzk = iFm;
                this.lz = iFm > 0 ? 2 : 0;
                if (!TextUtils.isEmpty(this.f6921qf)) {
                    com.bytedance.sdk.openadsdk.yz.dsz dszVar = this.yz;
                    if (dszVar != null) {
                        dszVar.fm(this.lz);
                    }
                    lb.fm.fm(this.kwx, lseVar, "landingpage_endcard", this.si, this.f6921qf);
                }
            }
            if ((!TextUtils.isEmpty(this.f6919lb) && this.f6919lb.contains("play.google.com/store")) || ((lseVar != null && !lseVar.qf() && wey.ef(lseVar)) || wey.wu(lseVar))) {
                this.wu = true;
                return;
            }
            if (this.ro) {
                boolean z10 = this.ai.no;
                if (this.fhx == null || ((!z10 && TextUtils.isEmpty(this.f6919lb)) || !lse.ro(lseVar))) {
                    if (lse.lb(lseVar)) {
                        this.ai.wbw.lb();
                    }
                } else {
                    if (this.mj) {
                        return;
                    }
                    String strO = e.o(new StringBuilder(), this.f6919lb, "&is_pre_render=1");
                    com.bytedance.sdk.openadsdk.yz.dsz dszVar2 = this.yz;
                    if (dszVar2 != null) {
                        dszVar2.yz();
                    }
                    com.bytedance.sdk.openadsdk.utils.lse.fm(this.fhx, strO);
                    this.mj = true;
                }
            }
        }
    }

    public void jnr() {
        if (ai.jnr(this.ai.ro) && this.ai.f6944te) {
            return;
        }
        ajl();
    }

    public void wsy() {
        this.fm.fm("showPlayableEndCardOverlay", (JSONObject) null);
        this.ai.zan.sendEmptyMessageDelayed(600, 1000L);
        this.ai.zan.postDelayed(new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.10
            @Override // java.lang.Runnable
            public void run() {
                gof.this.pkk();
            }
        }, 1000L);
    }

    public void ro() {
        this.wey = this.ai.xgn.findViewById(R.id.content);
        com.bytedance.sdk.component.ef.wsy wsyVar = (com.bytedance.sdk.component.ef.wsy) this.ai.f6937gc.findViewById(com.bytedance.sdk.openadsdk.utils.qhl.irt);
        this.fhx = wsyVar;
        if (wsyVar != null && lse.ro(this.ai.ro)) {
            this.fhx.jnr();
        } else {
            zan.fm((View) this.fhx, 8);
        }
        com.bytedance.sdk.component.ef.wsy wsyVar2 = this.fhx;
        if (wsyVar2 != null) {
            wsyVar2.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.1
                @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
                public void onGlobalLayout() {
                    if (gof.this.fhx == null || gof.this.fhx.getViewTreeObserver() == null) {
                        return;
                    }
                    gof.this.fhx.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    int measuredWidth = gof.this.fhx.getMeasuredWidth();
                    int measuredHeight = gof.this.fhx.getMeasuredHeight();
                    if (gof.this.fhx.getVisibility() == 0) {
                        gof.this.fm(measuredWidth, measuredHeight);
                    }
                }
            });
        }
    }

    public void jnr(boolean z10) {
        if (this.fm == null || this.ai.xgn.isFinishing()) {
            return;
        }
        this.fm.wsy(z10);
    }

    public void lb(boolean z10) {
        ro(this.fm, z10);
    }

    public void yz(boolean z10) {
        if (ai.ro(this.ai.ro)) {
            return;
        }
        jnr(z10);
    }

    public static class fm extends com.bytedance.sdk.openadsdk.core.lb.fm implements ro.fm {
        private final com.bytedance.sdk.openadsdk.component.reward.fm.ro fm;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private final View.OnClickListener f6923lb;
        private final View ro;

        public fm(com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar, View view, View.OnClickListener onClickListener) {
            super(roVar.xgn, roVar.ro, roVar.jnr, roVar.yz ? 7 : 5);
            this.fm = roVar;
            this.ro = view;
            this.f6923lb = onClickListener;
            HashMap map = new HashMap();
            map.put("close_auto_click", Boolean.TRUE);
            map.put("click_scence", 2);
            fm(map);
            fm(roVar.maa.lb());
            fm(this);
        }

        @Override // com.bytedance.sdk.openadsdk.core.lb.fm, com.bytedance.sdk.openadsdk.core.lb.ro, com.bytedance.sdk.openadsdk.core.lb.lb
        public void fm(View view, float f10, float f11, float f12, float f13, SparseArray<lb.fm> sparseArray, boolean z10) {
            if (!this.fm.ro.vu()) {
                super.fm(view, f10, f11, f12, f13, sparseArray, z10);
                this.fm.mon.pkk();
            } else {
                this.f6923lb.onClick(view);
                this.ro.setOnTouchListener(null);
                this.ro.setOnClickListener(this.f6923lb);
            }
        }

        @Override // com.bytedance.sdk.openadsdk.core.lb.ro.fm
        public void fm(View view, int i10) {
            this.ro.setOnTouchListener(null);
            this.ro.setOnClickListener(this.f6923lb);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.dsz.ef
    public void lb(int i10) {
        int i11 = this.bwv;
        if (i11 <= 0 && i10 > 0) {
            yz(false);
        } else if (i11 > 0 && i10 == 0) {
            yz(true);
        }
        this.bwv = i10;
    }

    public void ro(boolean z10) {
        fm(this.fm, z10);
    }

    public void fm() {
        if (this.gqi) {
            return;
        }
        this.gqi = true;
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar = this.ai;
        this.ku = roVar.kwx;
        this.dsz = roVar.lmk;
        this.onz = roVar.mpp;
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        ro();
        this.kwx = SystemClock.elapsedRealtime() - jElapsedRealtime;
    }

    public void ro(hxv hxvVar, boolean z10) {
        try {
            hxvVar.wu(z10);
        } catch (Exception unused) {
        }
    }

    public void ro(int i10) {
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.fm(i10);
            this.wsy.lb();
        }
    }

    public void fm(String str, final com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar) {
        fm(str, new ro() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.5
            @Override // com.bytedance.sdk.openadsdk.component.reward.fm.gof.ro
            public void fm(WebView webView, String str2) {
                if (gof.this.ai.xgn.isFinishing()) {
                    return;
                }
                com.bytedance.sdk.openadsdk.component.reward.fm.ro unused = gof.this.ai;
                gof.this.dsz();
            }
        });
        fm(new DownloadListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.6
            @Override // android.webkit.DownloadListener
            public void onDownloadStart(String str2, String str3, String str4, String str5, long j10) {
                gof.this.ai.maa.ro();
                com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar2 = roVar;
                if (roVar2 != null) {
                    roVar2.ado();
                }
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(int i10, com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar) {
        this.ai.wey.get();
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar2 = this.ai;
        com.bytedance.sdk.openadsdk.activity.single.wu wuVar = roVar2.zow;
        if (wuVar == null || !wuVar.duv || roVar2.wey.get()) {
            return;
        }
        this.ai.wey.set(true);
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar3 = this.ai;
        if (roVar3.pbk && wey.onz(roVar3.ro) && roVar != null) {
            roVar.jnr();
        }
    }

    public void ajl(boolean z10) {
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar = this.ai;
        com.bytedance.sdk.openadsdk.utils.onz onzVar = roVar.rka;
        if (onzVar != null) {
            onzVar.fm(roVar, 5000L);
        }
        this.f6916gc = true;
        JSONObject jSONObject = new JSONObject();
        lse lseVar = this.ai.ro;
        try {
            jSONObject.put("endcard_overlay_render_type", lse.lb(lseVar) ? 7 : 0);
        } catch (Throwable unused) {
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(lseVar, this.vt, "use_second_endcard", jSONObject);
        this.mon = SystemClock.elapsedRealtime();
        try {
            if (!lse.lb(lseVar)) {
                this.fm.fm("click_endcard_close", (JSONObject) null);
            } else if (z10) {
                this.ai.wbw.wu();
                com.bytedance.sdk.openadsdk.yz.lb.ro(lseVar, this.vt, "endcard_close_skip", jSONObject);
            }
        } catch (Exception unused2) {
        }
    }

    public void fm(com.bytedance.sdk.openadsdk.dsz.wsy wsyVar, String str, final com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar) {
        if (this.fhx == null) {
            return;
        }
        HashMap map = new HashMap();
        final lse lseVar = this.ai.ro;
        map.put("click_scence", 2);
        this.wsy = hxv();
        hxv hxvVar = new hxv(this.ai.xgn);
        this.fm = hxvVar;
        hxvVar.fm(this.ai.mon);
        hxv hxvVarFm = this.fm.ro(this.fhx).fm(lseVar).fm(com.bytedance.sdk.openadsdk.core.vt.ro.lb.fm(lseVar)).lb(lseVar.eo()).yz(lseVar.gt()).ro(lseVar.ii() ? 7 : 5).fm(new com.bytedance.sdk.openadsdk.core.vt.fm.lb(this.fhx)).jnr(lseVar.uuz()).fm(this.fhx);
        if (duv()) {
            str = "landingpage_endcard";
        }
        hxvVarFm.ro(str).fm(map).fm(this.wsy).fm(new com.bytedance.sdk.openadsdk.core.widget.jnr() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.8
            @Override // com.bytedance.sdk.openadsdk.core.widget.jnr
            public void fm() {
                if (gof.this.wbw != null) {
                    gof.this.wbw.lb();
                }
                com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar2 = roVar;
                if (roVar2 != null) {
                    roVar2.ado();
                }
            }
        }).fm(new hxv.fm() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.7
            @Override // com.bytedance.sdk.openadsdk.core.hxv.fm
            public void fm() {
                gof.this.pkk();
            }
        });
        this.fm.fm(new com.bytedance.sdk.openadsdk.core.vt.fm.yz(this.fhx));
        this.fm.fm(this.ai.hxv.vt()).fm(this.ai.lse.lb()).fm(new com.bytedance.sdk.openadsdk.dsz.lb() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.9
            @Override // com.bytedance.sdk.openadsdk.dsz.lb
            public void fm(boolean z10, int i10, String str2) {
                if (z10) {
                    gof gofVar = gof.this;
                    gofVar.f6915ef = true;
                    if (gofVar.bkb) {
                        gof.this.bkb = false;
                        gof gofVar2 = gof.this;
                        gofVar2.fm(gofVar2.ai.f6943qf, true);
                    }
                }
                if (lse.yz(lseVar)) {
                    gof.this.fm(z10, i10, str2);
                }
            }

            @Override // com.bytedance.sdk.openadsdk.dsz.lb
            public void fm() {
                gof.this.xgn = true;
                gof.this.ai.hxv.vt().performClick();
            }
        });
        this.fm.ajl(this.hxv);
    }

    public void fm(int i10, int i11) {
        if (this.fm == null || this.ai.xgn.isFinishing()) {
            return;
        }
        this.fm.fm(i10, i11);
    }

    private static String fm(String str, lse lseVar, int i10, int i11, int i12) {
        String strConcat;
        String strConcat2;
        float fLvj = lseVar.lvj();
        if (!TextUtils.isEmpty(str)) {
            if (i10 == 1) {
                if (str.contains("?")) {
                    strConcat2 = str.concat("&");
                } else {
                    strConcat2 = str.concat("?");
                }
                str = u1.j(strConcat2, "orientation=portrait");
            }
            if (str.contains("?")) {
                strConcat = str.concat("&");
            } else {
                strConcat = str.concat("?");
            }
            str = strConcat + "height=" + i11 + "&width=" + i12 + "&aspect_ratio=" + fLvj;
        }
        return !ai.ro(lseVar) ? com.bytedance.sdk.openadsdk.utils.ajl.fm(str) : str;
    }

    public void fm(int i10) {
        if (this.gof || !this.qhl.get()) {
            fm(0, this.ai.mon);
        }
        zan.fm((View) this.fhx, i10);
        com.bytedance.sdk.component.ef.wsy wsyVar = this.fhx;
        if (wsyVar != null) {
            zan.fm((View) wsyVar.getWebView(), i10);
        }
        lse lseVar = this.ai.ro;
        if (this.fhx == null || !lseVar.pf()) {
            return;
        }
        this.fhx.setLandingPage(true);
        this.fhx.setTag("landingpage_endcard");
        this.fhx.setMaterialMeta(lseVar.ooo());
    }

    public void fm(float f10) {
        zan.fm(this.fhx, f10);
    }

    public void fm(hxv hxvVar, boolean z10) {
        if (this.fm == null || this.ai.xgn.isFinishing()) {
            return;
        }
        hxvVar.ro(z10);
    }

    @SuppressLint({"ClickableViewAccessibility"})
    private void fm(String str, final ro roVar) {
        com.bytedance.sdk.component.ef.wsy wsyVar;
        final lse lseVar = this.ai.ro;
        com.bytedance.sdk.component.ef.wsy wsyVar2 = this.fhx;
        if (wsyVar2 != null && wsyVar2.getWebView() != null) {
            com.bytedance.sdk.openadsdk.yz.dsz dszVarRo = new com.bytedance.sdk.openadsdk.yz.dsz(lseVar, this.fhx.getWebView(), new com.bytedance.sdk.openadsdk.yz.duv() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.11
                @Override // com.bytedance.sdk.openadsdk.yz.duv
                public void fm(int i10) {
                    if (TextUtils.isEmpty(gof.this.f6921qf)) {
                        return;
                    }
                    lb.fm.fm(gof.this.tzk, gof.this.zan, gof.this.f6920ne, gof.this.f6918ib - gof.this.f6920ne, lseVar, "landingpage_endcard", i10);
                }
            }, this.lz).ro(true);
            this.yz = dszVarRo;
            this.lmk = dszVarRo.fm;
            dszVarRo.fm(duv() ? "landingpage_endcard" : str);
            this.yz.ro(this.vt);
            this.yz.lb(true);
            this.fhx.getWebView().setOnScrollChangeListener(new View.OnScrollChangeListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.12
                @Override // android.view.View.OnScrollChangeListener
                public void onScrollChange(View view, int i10, int i11, int i12, int i13) {
                    com.bytedance.sdk.openadsdk.yz.dsz dszVar = gof.this.yz;
                    if (dszVar != null) {
                        dszVar.ro(i11);
                    }
                }
            });
            ef efVar = this.ai.lse;
            if (efVar != null) {
                this.yz.fm(efVar.fm());
            }
            com.bytedance.sdk.openadsdk.common.jnr jnrVarFm = bx.fm(lseVar, this.fhx, this.ai.xgn, this.vt);
            this.mpp = jnrVarFm;
            if (jnrVarFm != null) {
                if (duv()) {
                    str = "landingpage_endcard";
                }
                jnrVarFm.fm(str);
            }
            if (duv()) {
                bx.fm(lseVar, this.fhx);
            }
            this.vvj = new com.bytedance.sdk.openadsdk.onz.yz(this.yz);
            com.bytedance.sdk.openadsdk.core.widget.fm.ajl ajlVar = new com.bytedance.sdk.openadsdk.core.widget.fm.ajl(com.bytedance.sdk.openadsdk.core.gof.fm(), this.fm, lseVar.eo(), this.mpp, this.yz, lseVar.pf()) { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.2
                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                public void onPageFinished(WebView webView, String str2) {
                    super.onPageFinished(webView, str2);
                    gof.this.mj = false;
                    gof.this.gof = true;
                    gof gofVar = gof.this;
                    gofVar.fm(100, gofVar.ai.mon);
                    if (gof.this.ai.ol.wey()) {
                        View viewVt = gof.this.ai.hxv.vt();
                        if (viewVt instanceof com.bytedance.sdk.openadsdk.core.ajl.yz) {
                            ((com.bytedance.sdk.openadsdk.core.ajl.yz) viewVt).setImageResource(maa.yz(gof.this.ai.bx, "tt_skip_btn"));
                        }
                    }
                    DeviceUtils.AudioInfoReceiver.fm(gof.this);
                    gof.this.bwv = DeviceUtils.wsy();
                    com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = gof.this.wsy;
                    if (jnrVar != null) {
                        jnrVar.jnr();
                    }
                    com.bytedance.sdk.openadsdk.component.reward.fm.ro unused = gof.this.ai;
                    ro roVar2 = roVar;
                    if (roVar2 != null) {
                        roVar2.fm(webView, str2);
                    }
                }

                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                public void onPageStarted(WebView webView, String str2, Bitmap bitmap) {
                    super.onPageStarted(webView, str2, bitmap);
                    com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = gof.this.wsy;
                    if (jnrVar != null) {
                        jnrVar.yz();
                    }
                }

                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                public void onReceivedError(WebView webView, int i10, String str2, String str3) {
                    super.onReceivedError(webView, i10, str2, str3);
                }

                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                @TargetApi(21)
                public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
                    com.bytedance.sdk.openadsdk.component.reward.fm.ro unused = gof.this.ai;
                    webResourceRequest.isForMainFrame();
                    webResourceRequest.getUrl();
                    webResourceResponse.getStatusCode();
                    if (webResourceRequest.getUrl() != null) {
                        webResourceRequest.getUrl().toString();
                    }
                    if (webResourceRequest.isForMainFrame()) {
                        gof.this.qhl.set(false);
                        gof.this.mj = false;
                        gof.this.jnr = webResourceResponse.getStatusCode();
                        gof gofVar = gof.this;
                        gofVar.ajl = "onReceivedHttpError";
                        gofVar.fm(gofVar.jnr, gofVar.ai.mon);
                    }
                    if (gof.this.wsy != null) {
                        try {
                            JSONObject jSONObject = new JSONObject();
                            jSONObject.put("code", webResourceResponse.getStatusCode());
                            jSONObject.put("msg", webResourceResponse.getReasonPhrase());
                            gof.this.wsy.fm(jSONObject);
                        } catch (JSONException unused2) {
                        }
                    }
                    super.onReceivedHttpError(webView, webResourceRequest, webResourceResponse);
                }

                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
                    super.onReceivedSslError(webView, sslErrorHandler, sslError);
                }

                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                public WebResourceResponse shouldInterceptRequest(WebView webView, String str2) {
                    try {
                        if (TextUtils.isEmpty(gof.this.f6921qf)) {
                            return super.shouldInterceptRequest(webView, str2);
                        }
                        gof.ku(gof.this);
                        WebResourceResponseModel webResourceResponseModelFm = com.bytedance.sdk.openadsdk.wsy.ro.fm().fm(gof.this.si, gof.this.f6921qf, str2);
                        if (webResourceResponseModelFm != null && webResourceResponseModelFm.getWebResourceResponse() != null) {
                            gof.dsz(gof.this);
                            return webResourceResponseModelFm.getWebResourceResponse();
                        }
                        if (webResourceResponseModelFm != null && webResourceResponseModelFm.getMsg() == 2) {
                            gof.onz(gof.this);
                        }
                        return super.shouldInterceptRequest(webView, str2);
                    } catch (Throwable th) {
                        com.bytedance.sdk.component.utils.wey.fm("TTAD.RFWVM", "shouldInterceptRequest url error", th);
                        return super.shouldInterceptRequest(webView, str2);
                    }
                }

                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                @TargetApi(23)
                public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
                    super.onReceivedError(webView, webResourceRequest, webResourceError);
                    if (webResourceError != null && webResourceRequest != null && webResourceRequest.getUrl() != null) {
                        Objects.toString(webResourceError.getDescription());
                        webResourceRequest.getUrl().toString();
                    }
                    if (webResourceRequest == null || webResourceRequest.getUrl() == null || !gof.this.fm(webResourceRequest.getUrl().toString())) {
                        if (webResourceError != null && webResourceRequest != null && webResourceRequest.isForMainFrame()) {
                            com.bytedance.sdk.openadsdk.component.reward.fm.ro unused = gof.this.ai;
                            webResourceError.getErrorCode();
                            String.valueOf(webResourceError.getDescription());
                            String.valueOf(webResourceRequest.getUrl());
                        }
                        if (webResourceRequest == null || webResourceRequest.isForMainFrame()) {
                            gof.this.qhl.set(false);
                            gof.this.mj = false;
                            gof.this.fm(webResourceError != null ? webResourceError.getErrorCode() : -1, gof.this.ai.mon);
                        }
                        if (gof.this.wsy != null) {
                            try {
                                JSONObject jSONObject = new JSONObject();
                                if (webResourceError != null) {
                                    jSONObject.put("code", webResourceError.getErrorCode());
                                    jSONObject.put("msg", webResourceError.getDescription());
                                }
                                gof.this.wsy.fm(jSONObject);
                            } catch (JSONException unused2) {
                            }
                        }
                        if (webResourceError != null) {
                            gof.this.jnr = webResourceError.getErrorCode();
                            gof.this.ajl = String.valueOf(webResourceError.getDescription());
                        }
                    }
                }

                @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ajl, android.webkit.WebViewClient
                @TargetApi(21)
                public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
                    try {
                        return shouldInterceptRequest(webView, webResourceRequest.getUrl().toString());
                    } catch (Throwable th) {
                        com.bytedance.sdk.component.utils.wey.fm("TTAD.RFWVM", "shouldInterceptRequest error1", th);
                        return super.shouldInterceptRequest(webView, webResourceRequest);
                    }
                }
            };
            this.wbw = ajlVar;
            this.fhx.setWebViewClient(ajlVar);
            this.wbw.fm(lseVar);
            this.wbw.fm(this.duv ? "rewarded_video" : "fullscreen_interstitial_ad");
            if (lseVar.pf() && (wsyVar = this.fhx) != null && wsyVar.getWebView() != null) {
                this.fhx.getWebView().setOnTouchListener(new View.OnTouchListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.3

                    /* JADX INFO: renamed from: lb, reason: collision with root package name */
                    private final int f6922lb = com.bytedance.sdk.openadsdk.core.gof.ro();

                    @Override // android.view.View.OnTouchListener
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        int i10;
                        com.bytedance.sdk.openadsdk.yz.dsz dszVar = gof.this.yz;
                        if (dszVar != null) {
                            dszVar.fm(motionEvent);
                        }
                        if (gof.this.mpp != null) {
                            gof.this.mpp.fm(motionEvent);
                        }
                        if (gof.this.vvj != null) {
                            gof.this.vvj.fm();
                        }
                        try {
                            int actionMasked = motionEvent.getActionMasked();
                            if (actionMasked != 0) {
                                int i11 = 3;
                                if (actionMasked == 1) {
                                    i10 = i11;
                                } else if (actionMasked != 2) {
                                    i11 = actionMasked != 3 ? -1 : 4;
                                    i10 = i11;
                                } else {
                                    float rawX = motionEvent.getRawX();
                                    float rawY = motionEvent.getRawY();
                                    if (Math.abs(rawX - gof.this.maa) >= this.f6922lb || Math.abs(rawY - gof.this.lse) >= this.f6922lb) {
                                        gof.this.nt = false;
                                    }
                                    gof.this.mq += Math.abs(motionEvent.getX() - gof.this.maa);
                                    gof.this.gzf += Math.abs(motionEvent.getY() - gof.this.lse);
                                    i10 = (System.currentTimeMillis() - gof.this.hlt <= 200 || (gof.this.mq <= 8.0f && gof.this.gzf <= 8.0f)) ? 2 : 1;
                                }
                            } else {
                                gof.this.nt = true;
                                gof.this.hi = new SparseArray();
                                gof.this.maa = motionEvent.getRawX();
                                gof.this.lse = motionEvent.getRawY();
                                gof.this.hlt = System.currentTimeMillis();
                                try {
                                    long landingPageClickBegin = gof.this.fhx.getLandingPageClickBegin();
                                    if (landingPageClickBegin > 0 && landingPageClickBegin < gof.this.hlt) {
                                        gof.this.hlt = landingPageClickBegin;
                                        gof.this.fhx.setLandingPageClickBegin(-1L);
                                    }
                                } catch (Exception unused) {
                                }
                                gof.this.mq = -1.0f;
                                gof.this.gzf = -1.0f;
                                i10 = 0;
                            }
                            gof.this.hi.put(motionEvent.getActionMasked(), new lb.fm(i10, motionEvent.getSize(), motionEvent.getPressure(), System.currentTimeMillis()));
                            if (motionEvent.getAction() == 1 && wey.wsy(gof.this.ai.ro) && gof.this.ai.mon != null) {
                                gof.this.fm(new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.3.1
                                    @Override // java.lang.Runnable
                                    public void run() {
                                        gof.this.ai.mon.mj();
                                    }
                                });
                            }
                            if (motionEvent.getAction() != 1 || view.getVisibility() != 0 || Float.valueOf(view.getAlpha()).intValue() != 1) {
                                return false;
                            }
                            if ((gof.this.irt && !wey.ku(lseVar)) || !gof.this.nt) {
                                return false;
                            }
                            JSONObject jSONObject = new JSONObject();
                            jSONObject.put("down_x", gof.this.maa);
                            jSONObject.put("down_y", gof.this.lse);
                            jSONObject.put("down_time", gof.this.hlt);
                            jSONObject.put("up_x", motionEvent.getRawX());
                            jSONObject.put("up_y", motionEvent.getRawY());
                            long jCurrentTimeMillis = System.currentTimeMillis();
                            try {
                                long landingPageClickEnd = gof.this.fhx.getLandingPageClickEnd();
                                if (landingPageClickEnd > 0 && landingPageClickEnd < jCurrentTimeMillis) {
                                    try {
                                        gof.this.fhx.setLandingPageClickEnd(-1L);
                                    } catch (Exception unused2) {
                                    }
                                    jCurrentTimeMillis = landingPageClickEnd;
                                }
                            } catch (Exception unused3) {
                            }
                            jSONObject.put("up_time", jCurrentTimeMillis);
                            int[] iArr = new int[2];
                            gof gofVar = gof.this;
                            gofVar.sds = gofVar.ai.f6937gc.findViewById(520093713);
                            if (gof.this.sds != null) {
                                gof.this.sds.getLocationOnScreen(iArr);
                                jSONObject.put("button_x", iArr[0]);
                                jSONObject.put("button_y", iArr[1]);
                                jSONObject.put("button_width", gof.this.sds.getWidth());
                                jSONObject.put("button_height", gof.this.sds.getHeight());
                            }
                            if (gof.this.wey != null) {
                                int[] iArr2 = new int[2];
                                gof.this.wey.getLocationOnScreen(iArr2);
                                jSONObject.put("ad_x", iArr2[0]);
                                jSONObject.put("ad_y", iArr2[1]);
                                jSONObject.put("width", gof.this.wey.getWidth());
                                jSONObject.put("height", gof.this.wey.getHeight());
                            }
                            jSONObject.put("toolType", motionEvent.getToolType(0));
                            jSONObject.put("deviceId", motionEvent.getDeviceId());
                            jSONObject.put("source", motionEvent.getSource());
                            jSONObject.put("ft", com.bytedance.sdk.openadsdk.core.model.duv.fm(gof.this.hi, com.bytedance.sdk.openadsdk.core.vt.ro().fm() ? 1 : 2));
                            jSONObject.put("user_behavior_type", gof.this.nt ? 1 : 2);
                            jSONObject.put("click_scence", 2);
                            if (gof.this.wbw != null) {
                                gof.this.wbw.fm(jSONObject);
                            }
                            if (gof.this.irt || wey.vt(lseVar)) {
                                return false;
                            }
                            if (gof.this.duv) {
                                com.bytedance.sdk.openadsdk.yz.lb.fm(lseVar, "rewarded_video", "click", jSONObject);
                            } else {
                                com.bytedance.sdk.openadsdk.yz.lb.fm(lseVar, "fullscreen_interstitial_ad", "click", jSONObject);
                            }
                            gof.this.irt = true;
                            return false;
                        } catch (Throwable unused4) {
                            return false;
                        }
                    }
                });
            }
            com.bytedance.sdk.component.ef.wsy wsyVar3 = this.fhx;
            if (wsyVar3 != null) {
                wsyVar3.setWebChromeClient(new com.bytedance.sdk.openadsdk.core.widget.fm.jnr(this.fm, this.yz, this.mpp) { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.gof.4
                    @Override // com.bytedance.sdk.openadsdk.core.widget.fm.jnr, android.webkit.WebChromeClient
                    public void onProgressChanged(WebView webView, int i10) {
                        super.onProgressChanged(webView, i10);
                    }
                });
            }
            fm(this.fhx);
            this.fhx.setLayerType(1, null);
            this.fhx.setBackgroundColor(-1);
            this.fhx.setDisplayZoomControls(false);
        }
        com.bytedance.sdk.openadsdk.onz.yz yzVar = this.vvj;
        if (yzVar != null) {
            this.wbw.fm(yzVar);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean fm(String str) {
        if (TextUtils.isEmpty(str)) {
            return true;
        }
        return this.ai.ro.pf() && str.endsWith(".mp4");
    }

    public void fm(DownloadListener downloadListener) {
        com.bytedance.sdk.component.ef.wsy wsyVar = this.fhx;
        if (wsyVar == null || downloadListener == null) {
            return;
        }
        wsyVar.setDownloadListener(downloadListener);
    }

    public void fm(com.bytedance.sdk.component.ef.wsy wsyVar) {
        if (wsyVar == null) {
            return;
        }
        com.bytedance.sdk.openadsdk.core.widget.fm.yz.fm(this.ai.xgn).fm(false).ro(false).fm(wsyVar.getWebView());
        wsyVar.setUserAgentString(com.bytedance.sdk.openadsdk.utils.wey.fm(wsyVar.getWebView(), BuildConfig.VERSION_CODE));
        wsyVar.setMixedContentMode(0);
    }

    public void fm(boolean z10, boolean z11) {
        fm(this.fm, z10, z11);
    }

    public void fm(hxv hxvVar, boolean z10, boolean z11) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("endcard_mute", z10);
            jSONObject.put("endcard_show", z11);
            com.bytedance.sdk.openadsdk.activity.single.wu wuVar = this.ai.zow;
            String str = "end";
            if (wuVar != null) {
                jSONObject.put("multi_ads_show", wuVar.zan().vt());
                if (!wuVar.qhl) {
                    str = "mid";
                }
                jSONObject.put("endcard_type", str);
            } else {
                jSONObject.put("endcard_type", "end");
            }
            hxvVar.fm("endcard_control_event", jSONObject);
            if (!z11) {
                this.bkb = false;
            } else {
                if (this.gof) {
                    return;
                }
                this.bkb = true;
            }
        } catch (Exception unused) {
        }
    }

    public void fm(boolean z10, int i10, String str) {
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.wsy;
        if (jnrVar == null) {
            return;
        }
        if (z10) {
            jnrVar.ro();
        } else {
            jnrVar.fm(i10, str);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean fm(Runnable runnable) {
        long jCurrentTimeMillis = System.currentTimeMillis();
        if (jCurrentTimeMillis - this.f6917ha < 100) {
            return false;
        }
        this.f6917ha = jCurrentTimeMillis;
        if (runnable == null) {
            return true;
        }
        runnable.run();
        return true;
    }
}
