package com.bytedance.sdk.openadsdk.core.dsz.ajl;

import android.content.Context;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.media3.exoplayer.upstream.CmcdData;
import com.bytedance.adsdk.ugeno.core.dsz;
import com.bytedance.adsdk.ugeno.core.duv;
import com.bytedance.adsdk.ugeno.core.fhx;
import com.bytedance.adsdk.ugeno.core.irt;
import com.bytedance.adsdk.ugeno.yz.ajl;
import com.bytedance.sdk.component.adexpress.ro.onz;
import com.bytedance.sdk.component.utils.maa;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.lb.lb;
import com.bytedance.sdk.openadsdk.core.model.ai;
import com.bytedance.sdk.openadsdk.core.model.irt;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.settings.ku;
import com.bytedance.sdk.openadsdk.core.vt.sds;
import com.bytedance.sdk.openadsdk.utils.xgn;
import com.bytedance.sdk.openadsdk.utils.zan;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class yz implements fhx, irt, com.bytedance.sdk.component.adexpress.dynamic.yz, com.bytedance.sdk.component.adexpress.ro.yz<View> {
    protected static int sds = 24;
    protected fm ajl;
    protected com.bytedance.adsdk.ugeno.ro.lb dsz;
    protected com.bytedance.adsdk.ugeno.ro.lb duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    protected com.bytedance.sdk.openadsdk.core.vt.irt f7031ef;
    protected float fhx;
    protected duv fm;
    protected long gof;
    protected long gqi;

    /* JADX INFO: renamed from: ha, reason: collision with root package name */
    private jnr f7033ha;
    private com.bytedance.sdk.component.adexpress.ro.wsy hi;
    protected JSONObject hlt;
    protected float irt;
    protected lse jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected com.bytedance.adsdk.ugeno.ro.lb<View> f7034lb;
    protected String maa;
    private boolean nt;
    protected float onz;
    private sds pkk;
    protected float qhl;
    protected Context ro;
    protected onz vt;
    protected FrameLayout wsy;
    protected com.bytedance.sdk.component.adexpress.ro.wu wu;
    protected JSONObject yz;
    protected boolean wey = true;
    private long mq = 0;
    private float gzf = 0.0f;
    private float ai = 0.0f;
    private float ol = 0.0f;
    private float wbw = 0.0f;
    public SparseArray<lb.fm> lse = new SparseArray<>();
    private String hxv = "";

    /* JADX INFO: renamed from: gc, reason: collision with root package name */
    private final com.bytedance.sdk.component.wu.ro.lb f7032gc = new com.bytedance.sdk.component.wu.ro.lb("ugen_render_template") { // from class: com.bytedance.sdk.openadsdk.core.dsz.ajl.yz.1
        @Override // java.lang.Runnable
        public void run() {
            yz yzVar = yz.this;
            yzVar.yz = yzVar.fm();
            yz yzVar2 = yz.this;
            yzVar2.hlt = yzVar2.ro();
            yz yzVar3 = yz.this;
            yzVar3.f7033ha = new jnr(yzVar3.ro, yzVar3.jnr, yzVar3.maa, yzVar3.hlt);
            if (yz.this.pkk != null) {
                yz yzVar4 = yz.this;
                yzVar4.hxv = yzVar4.pkk.getUgenTemplateErrorReason();
            } else {
                yz.this.hxv = "expressView is null";
            }
            com.bytedance.sdk.openadsdk.core.fhx.lb().post(yz.this.xgn);
        }
    };
    private final Runnable xgn = new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.dsz.ajl.yz.2
        @Override // java.lang.Runnable
        public void run() {
            if (yz.this.hi != null) {
                yz yzVar = yz.this;
                yzVar.ro(yzVar.hi);
            }
        }
    };
    private boolean mon = false;
    protected AtomicBoolean ku = new AtomicBoolean(false);

    static {
        if (gof.fm() != null) {
            sds = gof.ro();
        }
    }

    public yz(Context context, lse lseVar, boolean z10, fm fmVar, ViewGroup viewGroup) {
        this.ro = context;
        this.nt = z10;
        this.fm = new duv(context);
        this.jnr = lseVar;
        this.ajl = fmVar;
        this.wsy = new FrameLayout(context);
        if (viewGroup instanceof sds) {
            this.pkk = (sds) viewGroup;
        }
        this.maa = fmVar.yz();
    }

    private void ef() {
        com.bytedance.adsdk.ugeno.ro.lb<T> lbVarJnr;
        if (this.f7034lb == null) {
            return;
        }
        if (this.jnr.dh() && (lbVarJnr = this.f7034lb.jnr("tvskip")) != 0) {
            lbVarJnr.lb(8);
        }
        com.bytedance.adsdk.ugeno.ro.lb<T> lbVarJnr2 = this.f7034lb.jnr("skip");
        if (lbVarJnr2 != 0 && (lbVarJnr2 instanceof com.bytedance.adsdk.ugeno.ef.yz.lb)) {
            if (!ku.ro().fhx(String.valueOf(this.jnr.pg())) || this.jnr.ywr() == 5 || this.jnr.ywr() == 6 || this.jnr.tmm() == 3) {
                ((com.bytedance.adsdk.ugeno.ef.yz.lb) lbVarJnr2).onz("local://tt_close_btn");
                lbVarJnr2.ro();
            }
        }
    }

    public com.bytedance.adsdk.ugeno.ro.lb ajl() {
        com.bytedance.adsdk.ugeno.ro.lb<View> lbVar = this.f7034lb;
        if (lbVar == null) {
            return null;
        }
        return lbVar.ajl("PlayableComponent");
    }

    public void fm(long j10, long j11) {
    }

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

    @Override // com.bytedance.sdk.component.adexpress.dynamic.yz
    public void onvideoComplate() {
    }

    public void setSoundMute(boolean z10) {
        com.bytedance.adsdk.ugeno.ro.lb<T> lbVarJnr;
        com.bytedance.adsdk.ugeno.ro.lb<View> lbVar = this.f7034lb;
        if (lbVar == null || (lbVarJnr = lbVar.jnr("mute")) == 0) {
            return;
        }
        if (z10) {
            ((com.bytedance.adsdk.ugeno.ef.yz.lb) lbVarJnr).onz("local://tt_reward_full_mute");
        } else {
            ((com.bytedance.adsdk.ugeno.ef.yz.lb) lbVarJnr).onz("local://tt_reward_full_unmute");
        }
        lbVarJnr.ro();
    }

    public void setTime(CharSequence charSequence, int i10, int i11, boolean z10) {
        if (this.f7034lb == null) {
            return;
        }
        boolean z11 = i10 == 1;
        fm(charSequence, z11, i11, z10);
        ro(charSequence, z11, i11, z10);
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.yz
    public void setTimeUpdate(int i10) {
    }

    public com.bytedance.adsdk.ugeno.ro.lb wsy() {
        return null;
    }

    public com.bytedance.adsdk.ugeno.ro.lb wu() {
        com.bytedance.adsdk.ugeno.ro.lb<View> lbVar = this.f7034lb;
        if (lbVar == null) {
            return null;
        }
        return lbVar.jnr("video");
    }

    public int yz() {
        this.fm.fm((fhx) this);
        this.fm.fm((irt) this);
        com.bytedance.adsdk.ugeno.ro.lb<View> lbVarFm = this.fm.fm(this.yz);
        this.f7034lb = lbVarFm;
        jnr jnrVar = this.f7033ha;
        if (jnrVar != null && lbVarFm != null) {
            jnrVar.fm(lbVarFm);
        }
        if (!(this instanceof com.bytedance.sdk.openadsdk.core.dsz.ajl.fm.ajl)) {
            this.ajl.pkk().ro();
            this.ajl.pkk().lb();
        }
        this.fm.ro(this.hlt);
        return 0;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void ro(com.bytedance.sdk.component.adexpress.ro.wsy wsyVar) {
        if (this instanceof com.bytedance.sdk.openadsdk.core.dsz.ajl.fm.ajl) {
            this.ajl.jnr().wsy(1);
        } else {
            this.ajl.pkk().fm();
        }
        if (this.yz == null) {
            wsyVar.fm(133, "ugen template is null real reason is " + this.hxv);
            return;
        }
        if (this.hlt == null) {
            wsyVar.fm(133, "ugen data is null");
            return;
        }
        int iYz = yz();
        if (this.fm.fm()) {
            List<String> listRo = this.fm.ro();
            if (listRo == null) {
                wsyVar.fm(138, "unknow widget");
                return;
            }
            wsyVar.fm(138, "unknow widget;" + listRo.toString());
            return;
        }
        if (iYz != 0) {
            wsyVar.fm(iYz, "ugen render fail");
            return;
        }
        if (this.f7034lb == null) {
            wsyVar.fm(138, "ugen render error");
            return;
        }
        ro roVar = new ro();
        this.vt = roVar;
        roVar.fm(true);
        this.vt.fm(lb());
        setSoundMute(this.nt);
        ef();
        com.bytedance.adsdk.ugeno.ro.lb lbVarWu = wu();
        this.duv = lbVarWu;
        if (lbVarWu != null && (lbVarWu instanceof com.bytedance.sdk.openadsdk.core.dsz.ro.ajl.ro)) {
            ((ro) this.vt).fm((FrameLayout) ((com.bytedance.sdk.openadsdk.core.dsz.ro.ajl.ro) lbVarWu).yz());
        }
        jnr jnrVar = this.f7033ha;
        if (jnrVar != null) {
            jnrVar.fm();
        }
        com.bytedance.adsdk.ugeno.ro.lb lbVarAjl = ajl();
        this.dsz = lbVarAjl;
        if (lbVarAjl != null && (lbVarAjl instanceof com.bytedance.adsdk.ugeno.ef.ro.ro)) {
            ((ro) this.vt).ro((FrameLayout) lbVarAjl.ku());
        }
        if (ai.lb(this.jnr)) {
            com.bytedance.adsdk.ugeno.ro.lb lbVarWsy = wsy();
            if (lbVarWsy instanceof com.bytedance.sdk.openadsdk.core.dsz.ro.lb.ro) {
                ((ro) this.vt).lb(((com.bytedance.sdk.openadsdk.core.dsz.ro.lb.ro) lbVarWsy).yz());
            }
        }
        int iGc = this.f7034lb.gc();
        int iXgn = this.f7034lb.xgn();
        this.wsy.removeAllViews();
        this.wsy.addView(this.f7034lb.ku(), new FrameLayout.LayoutParams(iGc, iXgn));
        float fOl = this.ajl.ol();
        float fWbw = this.ajl.wbw();
        float fRo = zan.ro(this.ro, fOl);
        float fRo2 = zan.ro(this.ro, fWbw);
        if (lb() != 7) {
            this.wsy.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        } else if (fWbw <= 0.0f) {
            this.wsy.setLayoutParams(new FrameLayout.LayoutParams((int) fRo, -2));
        } else {
            this.wsy.setLayoutParams(new FrameLayout.LayoutParams((int) fRo, (int) fRo2));
        }
        if (fWbw <= 0.0f || fOl <= 0.0f) {
            this.wsy.measure(View.MeasureSpec.makeMeasureSpec(0, 0), View.MeasureSpec.makeMeasureSpec(0, 0));
            int iLb = zan.lb(this.ro, this.wsy.getMeasuredWidth());
            int iLb2 = zan.lb(this.ro, this.wsy.getMeasuredHeight());
            this.vt.fm(iLb);
            this.vt.ro(iLb2);
        } else {
            this.vt.fm(fOl);
            this.vt.ro(fWbw);
        }
        if (this.ku.get()) {
            wsyVar.fm(137, "ugen render timeout");
        } else {
            this.fm.fm(this.f7034lb, "renderDidFinish", new Object[0]);
            wsyVar.fm(this.wsy, this.vt);
        }
    }

    @Override // com.bytedance.adsdk.ugeno.core.fhx
    public void fm(com.bytedance.adsdk.ugeno.ro.lb lbVar, String str, ajl.fm fmVar) {
    }

    public int lb() {
        return this.jnr.te();
    }

    public void fm(com.bytedance.sdk.component.adexpress.ro.wu wuVar) {
        this.wu = wuVar;
    }

    public void fm(com.bytedance.sdk.openadsdk.core.vt.irt irtVar) {
        this.f7031ef = irtVar;
    }

    public void fm(lse lseVar, boolean z10, fm fmVar, ViewGroup viewGroup) {
        this.jnr = lseVar;
        this.ajl = fmVar;
        this.maa = fmVar.yz();
        if (viewGroup instanceof sds) {
            this.pkk = (sds) viewGroup;
        }
        this.nt = z10;
    }

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

    public JSONObject fm() {
        return this.ajl.lb();
    }

    public void fm(boolean z10) {
        this.ku.set(z10);
    }

    public void fm(com.bytedance.sdk.openadsdk.core.widget.jnr jnrVar) {
        jnr jnrVar2 = this.f7033ha;
        if (jnrVar2 != null) {
            jnrVar2.fm(jnrVar);
        }
    }

    @Override // com.bytedance.adsdk.ugeno.core.fhx
    public void fm(dsz dszVar, fhx.ro roVar, fhx.fm fmVar) {
        if (dszVar == null) {
            return;
        }
        if (dszVar.ro() == 1 || dszVar.ro() == 4) {
            fm(dszVar);
        }
        if (dszVar.ro() == 10) {
            fm(dszVar.lb());
        }
        if (roVar == null || dszVar.yz() == null) {
            return;
        }
        roVar.fm(dszVar.yz());
    }

    private void fm(JSONObject jSONObject) {
        com.bytedance.adsdk.ugeno.ro.lb<T> lbVarJnr;
        if (this.f7034lb == null || jSONObject == null) {
            return;
        }
        String strOptString = jSONObject.optString("type");
        String strOptString2 = jSONObject.optString("nodeId");
        if (TextUtils.isEmpty(strOptString2) || (lbVarJnr = this.f7034lb.jnr(strOptString2)) == 0) {
            return;
        }
        if (TextUtils.equals(strOptString, "onShow")) {
            lbVarJnr.lb(0);
        } else if (TextUtils.equals(strOptString, "onDismiss")) {
            lbVarJnr.lb(8);
        }
    }

    private void fm(dsz dszVar) {
        int i10;
        JSONObject jSONObjectYz;
        boolean zFm;
        int i11;
        String str;
        jnr jnrVar;
        jnr jnrVar2;
        jnr jnrVar3;
        if (this.wu == null) {
            return;
        }
        String strOptString = dszVar.lb().optString("type");
        if ("swiperLeft".equals(strOptString) && (jnrVar3 = this.f7033ha) != null) {
            jnrVar3.ro();
            return;
        }
        if ("swiperRight".equals(strOptString) && (jnrVar2 = this.f7033ha) != null) {
            jnrVar2.lb();
            return;
        }
        i10 = 2;
        if (!"swiperClick".equals(strOptString) || (jnrVar = this.f7033ha) == null) {
            jSONObjectYz = null;
            zFm = false;
            i11 = 0;
        } else {
            zFm = jnrVar.fm(dszVar);
            jSONObjectYz = this.f7033ha.yz();
            i11 = 2;
        }
        strOptString.getClass();
        switch (strOptString) {
            case "privacy":
                i10 = 7;
                break;
            case "feedback":
                i10 = 3;
                break;
            case "mute":
                i10 = 5;
                break;
            case "skip":
                i10 = 6;
                break;
            case "video":
                i10 = 4;
                break;
            case "creative":
                break;
            default:
                i10 = i11;
                break;
        }
        com.bytedance.adsdk.ugeno.ro.lb lbVarFm = dszVar.fm();
        irt.fm fmVarFm = new irt.fm().yz(this.onz).lb(this.fhx).ro(this.irt).fm(this.qhl).ro(this.gof).fm(this.gqi).fm(this.lse).fm(dszVar.ro() != 1 || this.wey);
        if (lbVarFm == null) {
            str = "";
        } else {
            str = lbVarFm.hxv() + "_" + lbVarFm.pkk();
        }
        this.wu.fm(dszVar.fm().ku(), i10, fmVarFm.fm(str).ro(zFm).ro(jSONObjectYz).fm());
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0059  */
    @Override // com.bytedance.adsdk.ugeno.core.irt
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void fm(com.bytedance.adsdk.ugeno.ro.lb lbVar, MotionEvent motionEvent) {
        int i10;
        int action = motionEvent.getAction();
        int i11 = 0;
        int i12 = 1;
        if (action != 0) {
            if (action == 1) {
                this.irt = motionEvent.getRawX();
                this.qhl = motionEvent.getRawY();
                if (Math.abs(this.irt - this.onz) >= sds || Math.abs(this.qhl - this.fhx) >= sds) {
                    this.wey = false;
                }
                this.gqi = System.currentTimeMillis();
            } else if (action == 2) {
                this.ol = Math.abs(motionEvent.getX() - this.gzf) + this.ol;
                this.wbw = Math.abs(motionEvent.getY() - this.ai) + this.wbw;
                this.gzf = motionEvent.getX();
                this.ai = motionEvent.getY();
                if (System.currentTimeMillis() - this.mq > 200) {
                    float f10 = this.ol;
                    int i13 = sds;
                    if (f10 <= i13 && this.wbw <= i13) {
                        i12 = 2;
                    }
                    if (Math.abs(motionEvent.getRawX() - this.onz) >= sds || Math.abs(motionEvent.getRawY() - this.fhx) >= sds) {
                        this.wey = false;
                    }
                    i10 = i12;
                }
                this.lse.put(motionEvent.getActionMasked(), new lb.fm(i10, motionEvent.getSize(), motionEvent.getPressure(), System.currentTimeMillis()));
            }
            i11 = -1;
        } else {
            this.gof = System.currentTimeMillis();
            this.onz = motionEvent.getRawX();
            this.fhx = motionEvent.getRawY();
            this.wey = true;
            this.ol = 0.0f;
            this.wbw = 0.0f;
            this.mq = System.currentTimeMillis();
            com.bytedance.sdk.openadsdk.core.duv.lb.fm(motionEvent);
            this.gzf = motionEvent.getX();
            this.ai = motionEvent.getY();
        }
        i10 = i11;
        this.lse.put(motionEvent.getActionMasked(), new lb.fm(i10, motionEvent.getSize(), motionEvent.getPressure(), System.currentTimeMillis()));
    }

    public JSONObject ro() {
        return this.ajl.ha();
    }

    private void ro(CharSequence charSequence, boolean z10, int i10, boolean z11) {
        com.bytedance.adsdk.ugeno.ro.lb<T> lbVarJnr;
        View viewKu;
        com.bytedance.adsdk.ugeno.ro.lb<View> lbVar = this.f7034lb;
        if (lbVar == null || (lbVarJnr = lbVar.jnr("skip")) == 0 || (viewKu = lbVarJnr.ku()) == null) {
            return;
        }
        int i11 = 0;
        if (!z10 && !z11) {
            i11 = 8;
        }
        viewKu.setVisibility(i11);
    }

    private void fm(CharSequence charSequence, boolean z10, int i10, boolean z11) {
        com.bytedance.adsdk.ugeno.ro.lb<T> lbVarJnr;
        int i11;
        com.bytedance.adsdk.ugeno.ro.lb<View> lbVar = this.f7034lb;
        if (lbVar == null || (lbVarJnr = lbVar.jnr("countdown")) == 0) {
            return;
        }
        View viewKu = lbVarJnr.ku();
        if (viewKu instanceof TextView) {
            try {
                i11 = Integer.parseInt((String) charSequence);
            } catch (Exception unused) {
                wey.lb("UGenRender", "parse duration exception", charSequence);
                i11 = 0;
            }
            if (!z11 && i11 > 0 && !this.mon) {
                viewKu.setVisibility(0);
                if (!z10 && this.ajl.fm() && com.bytedance.sdk.component.adexpress.yz.ajl.ro(this.ajl.yz())) {
                    ((TextView) viewKu).setText(String.format(maa.fm(com.bytedance.sdk.component.adexpress.yz.fm(), "tt_reward_full_skip"), Integer.valueOf(i10)));
                    return;
                }
                if (!"open_ad".equals(this.ajl.yz()) && this.ajl.fm()) {
                    this.mon = true;
                    viewKu.setVisibility(8);
                    return;
                } else {
                    ((TextView) viewKu).setText(((Object) charSequence) + CmcdData.STREAMING_FORMAT_SS);
                    return;
                }
            }
            viewKu.setVisibility(8);
        }
    }
}
