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

import android.text.TextUtils;
import com.bykv.vk.openvk.fm.fm.fm.lb.b;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.onz.ro.fm;
import com.bytedance.sdk.openadsdk.core.onz.ro.lb;
import com.bytedance.sdk.openadsdk.core.onz.ro.ro;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes2.dex */
public class yz {
    private boolean fhx;
    private boolean gof;
    private boolean gqi;
    private long irt;
    private String maa;
    private lse qhl;
    private String sds;
    private boolean wey;
    private final AtomicBoolean dsz = new AtomicBoolean(false);
    private final AtomicBoolean onz = new AtomicBoolean(false);
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> fm = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> ro = new ArrayList();

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> f7268lb = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> yz = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> jnr = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> ajl = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> wsy = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> wu = new ArrayList();

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> f7267ef = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> vt = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.ro> ku = new ArrayList();
    public List<com.bytedance.sdk.openadsdk.core.onz.ro.fm> duv = new ArrayList();

    public void ajl(long j10) {
        if (!fm(j10, this.wsy, null, this.fhx ? null : new lb.ro("skip", this.qhl)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_skip", (JSONObject) null);
    }

    public void duv(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.vt.addAll(list);
    }

    public void ef(long j10) {
        if (!fm(j10, this.vt, null, this.fhx ? null : new lb.ro("unmute", this.qhl, j10)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_unmute", (JSONObject) null);
    }

    public void fm(com.bytedance.sdk.openadsdk.core.onz.fm.fm fmVar) {
        if (!fm(-1L, this.fm, fmVar, this.fhx ? null : new lb.ro(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, this.qhl, 0.0f)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_error", (JSONObject) null);
    }

    public void jnr(long j10) {
        if (this.onz.compareAndSet(false, true)) {
            fm(j10, this.ajl, (com.bytedance.sdk.openadsdk.core.onz.fm.fm) null);
        }
    }

    public void ku(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.f7267ef.addAll(list);
    }

    public void lb(long j10) {
        if (!fm(j10, this.yz, null, this.fhx ? null : new lb.ro("resume", this.qhl, j10)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_resume", (JSONObject) null);
    }

    public void ro(long j10) {
        if (!fm(j10, this.f7268lb, null, this.fhx ? null : new lb.ro("pause", this.qhl, j10)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_pause", (JSONObject) null);
    }

    public void vt(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.fm.addAll(list);
    }

    public void wsy(long j10) {
        if (!fm(j10, this.wu, null, new lb.ro(this.fhx ? "click" : "clickTracking", this.qhl)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_video_click", (JSONObject) null);
    }

    public void wu(long j10) {
        if (!fm(j10, this.f7267ef, null, this.fhx ? null : new lb.ro("mute", this.qhl, j10)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_mute", (JSONObject) null);
    }

    public void yz(long j10) {
        if (!fm(j10, this.jnr, null, new lb.ro(this.fhx ? "video_progress" : "complete", this.qhl, 1.0f)) || this.fhx) {
            return;
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_complete", (JSONObject) null);
    }

    public void ajl(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.wsy.addAll(list);
    }

    public void ef(List<com.bytedance.sdk.openadsdk.core.onz.ro.fm> list) {
        this.duv.addAll(list);
        Collections.sort(this.duv);
    }

    public void fm(long j10) {
        if (this.dsz.compareAndSet(false, true)) {
            if (!fm(j10, this.ro, null, new lb.ro(this.fhx ? "show_impression" : "impression", this.qhl)) || this.fhx) {
                return;
            }
            com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_impression", (JSONObject) null);
        }
    }

    public void jnr(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.ajl.addAll(list);
    }

    public void lb(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.yz.addAll(list);
    }

    public void ro(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.f7268lb.addAll(list);
    }

    public void wsy(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.wu.addAll(list);
    }

    public void wu(List<com.bytedance.sdk.openadsdk.core.onz.ro.ro> list) {
        this.ku.addAll(list);
        Collections.sort(this.ku);
    }

    public void yz(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.jnr.addAll(list);
    }

    public void fm(long j10, long j11, ajl ajlVar) {
        lb.ro roVar;
        if (System.currentTimeMillis() - this.irt >= 1000 && j10 >= 0 && j11 > 0) {
            this.irt = System.currentTimeMillis();
            float f10 = j10 / j11;
            List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> listFm = fm(j10, f10);
            float f11 = 0.25f;
            if (f10 < 0.25f || this.gof) {
                f11 = 0.5f;
                if (f10 < 0.5f || this.gqi) {
                    f11 = 0.75f;
                    if (f10 >= 0.75f && !this.wey) {
                        fm("thirdQuartile");
                        this.wey = true;
                        if (ajlVar != null) {
                            fm(ajlVar, 8);
                        }
                        if (!this.fhx) {
                            roVar = new lb.ro("thirdQuartile", this.qhl, 0.75f);
                            f10 = f11;
                        }
                        f10 = f11;
                    }
                    roVar = null;
                } else {
                    fm("midpoint");
                    this.gqi = true;
                    if (ajlVar != null) {
                        fm(ajlVar, 7);
                    }
                    if (!this.fhx) {
                        roVar = new lb.ro("midpoint", this.qhl, 0.5f);
                        f10 = f11;
                    }
                    f10 = f11;
                    roVar = null;
                }
            } else {
                fm("firstQuartile");
                this.gof = true;
                if (ajlVar != null) {
                    fm(ajlVar, 6);
                }
                if (!this.fhx) {
                    roVar = new lb.ro("firstQuartile", this.qhl, 0.25f);
                    f10 = f11;
                }
                f10 = f11;
                roVar = null;
            }
            if (f10 < 0.03f) {
                f10 = 0.0f;
            }
            if (!this.fhx && !listFm.isEmpty()) {
                com.bytedance.sdk.openadsdk.core.onz.ro.lb lbVar = listFm.get(0);
                if ((lbVar instanceof com.bytedance.sdk.openadsdk.core.onz.ro.fm) && ((com.bytedance.sdk.openadsdk.core.onz.ro.fm) lbVar).fm() == 0) {
                    com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_start", (JSONObject) null);
                    roVar = new lb.ro("start", this.qhl, f10);
                }
            }
            if (listFm.isEmpty()) {
                return;
            }
            fm(j10, listFm, null, roVar != null ? roVar : new lb.ro("video_progress", this.qhl, f10));
        }
    }

    public void fm(int i10, long j10, long j11) {
        if (System.currentTimeMillis() - this.irt < 1000) {
            return;
        }
        this.irt = System.currentTimeMillis();
        float f10 = j10 / j11;
        List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> listFm = fm(j10, f10);
        lb.ro roVar = null;
        if (i10 != 6) {
            if (i10 == 7) {
                fm("midpoint");
                this.gqi = true;
                f10 = 0.5f;
                if (!this.fhx) {
                    roVar = new lb.ro("midpoint", this.qhl, 0.5f);
                }
            } else if (i10 != 8) {
                if (i10 == 15 && (listFm.get(0) instanceof com.bytedance.sdk.openadsdk.core.onz.ro.fm)) {
                    com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_start", (JSONObject) null);
                    roVar = new lb.ro("start", this.qhl, f10);
                }
            } else {
                fm("thirdQuartile");
                this.wey = true;
                f10 = 0.75f;
                if (!this.fhx) {
                    roVar = new lb.ro("thirdQuartile", this.qhl, 0.75f);
                }
            }
        } else if (!this.gof) {
            fm("firstQuartile");
            this.gof = true;
            f10 = 0.25f;
            if (!this.fhx) {
                roVar = new lb.ro("firstQuartile", this.qhl, 0.25f);
            }
        }
        if (listFm.isEmpty()) {
            return;
        }
        fm(j10, listFm, null, roVar != null ? roVar : new lb.ro("video_progress", this.qhl, f10));
    }

    private void fm(final ajl ajlVar, final int i10) {
        com.bytedance.sdk.component.utils.ef.ro().post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.onz.yz.1
            @Override // java.lang.Runnable
            public void run() {
                ajl ajlVar2 = ajlVar;
                if (ajlVar2 != null) {
                    ajlVar2.fm(i10);
                }
            }
        });
    }

    private void fm(String str) {
        try {
            if (this.fhx) {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("event", str);
                com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "vast_play_track", jSONObject);
            } else if ("firstQuartile".equals(str)) {
                com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_first_quartile", (JSONObject) null);
            } else if ("midpoint".equals(str)) {
                com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_midpoint", (JSONObject) null);
            } else if ("thirdQuartile".equals(str)) {
                com.bytedance.sdk.openadsdk.yz.lb.ro(this.qhl, this.sds, "track_third_quartile", (JSONObject) null);
            }
        } catch (Throwable unused) {
        }
    }

    private boolean fm(long j10, List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list, com.bytedance.sdk.openadsdk.core.onz.fm.fm fmVar, lb.ro roVar) {
        b bVarEx;
        lse lseVar = this.qhl;
        String str = null;
        if (lseVar != null && (bVarEx = lseVar.ex()) != null) {
            str = bVarEx.f5927g;
        }
        return com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(this.qhl, list, fmVar, j10, str, roVar, fm());
    }

    private String fm() {
        if (this.maa == null) {
            this.maa = UUID.randomUUID().toString();
        }
        return this.maa;
    }

    private boolean fm(long j10, List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list, com.bytedance.sdk.openadsdk.core.onz.fm.fm fmVar) {
        return fm(j10, list, fmVar, null);
    }

    public List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> fm(long j10, float f10) {
        ArrayList arrayList = new ArrayList();
        for (int i10 = 0; i10 < this.ku.size(); i10++) {
            com.bytedance.sdk.openadsdk.core.onz.ro.ro roVar = this.ku.get(i10);
            if (roVar.fm(f10)) {
                arrayList.add(roVar);
            }
        }
        for (int i11 = 0; i11 < this.duv.size(); i11++) {
            com.bytedance.sdk.openadsdk.core.onz.ro.fm fmVar = this.duv.get(i11);
            if (fmVar.fm(j10)) {
                arrayList.add(fmVar);
            }
        }
        return arrayList;
    }

    public void fm(List<com.bytedance.sdk.openadsdk.core.onz.ro.lb> list) {
        this.ro.addAll(list);
    }

    public void fm(JSONObject jSONObject) {
        vt(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("errorTrackers")));
        fm(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("impressionTrackers")));
        ro(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("pauseTrackers"), true));
        lb(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("resumeTrackers"), true));
        yz(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("completeTrackers")));
        jnr(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("closeTrackers")));
        ajl(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("skipTrackers")));
        wsy(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("clickTrackers")));
        ku(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("muteTrackers"), true));
        duv(com.bytedance.sdk.openadsdk.core.onz.ro.lb.fm(jSONObject.optJSONArray("unMuteTrackers"), true));
        wu(com.bytedance.sdk.openadsdk.core.onz.ro.lb.ro(jSONObject.optJSONArray("fractionalTrackers")));
        ef(com.bytedance.sdk.openadsdk.core.onz.ro.lb.lb(jSONObject.optJSONArray("absoluteTrackers")));
    }

    public void fm(lse lseVar) {
        this.qhl = lseVar;
        this.sds = lseVar.jnr();
        this.fhx = lseVar.zn();
    }

    public void fm(String str, long j10) {
        if (TextUtils.isEmpty(str) || j10 < 0) {
            return;
        }
        ef(Collections.singletonList(new fm.C0081fm(str, j10).fm()));
    }

    public void fm(String str, float f10) {
        if (TextUtils.isEmpty(str) || f10 < 0.0f) {
            return;
        }
        wu(Collections.singletonList(new ro.fm(str, f10).fm()));
    }

    public void fm(yz yzVar) {
        vt(yzVar.fm);
        fm(yzVar.ro);
        ro(yzVar.f7268lb);
        lb(yzVar.yz);
        yz(yzVar.jnr);
        jnr(yzVar.ajl);
        ajl(yzVar.wsy);
        wsy(yzVar.wu);
        ku(yzVar.f7267ef);
        duv(yzVar.vt);
        wu(yzVar.ku);
        ef(yzVar.duv);
    }
}
