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

import android.app.Activity;
import android.os.Message;
import android.view.View;
import android.widget.FrameLayout;
import b6.f;
import com.bytedance.sdk.component.utils.mq;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.CacheDirFactory;
import com.bytedance.sdk.openadsdk.core.fhx.yz.fm;
import com.bytedance.sdk.openadsdk.core.model.ai;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.model.sds;
import com.bytedance.sdk.openadsdk.utils.bx;
import com.bytedance.sdk.openadsdk.yz.jnr.ro.fhx;
import java.io.File;
import java.util.HashSet;
import java.util.Map;
import org.json.JSONObject;
import v5.b;
import z5.a;

/* JADX INFO: loaded from: classes2.dex */
public class qhl {
    private fm.InterfaceC0073fm ai;
    f ajl;
    private boolean dsz;
    private long duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private FrameLayout f6934ef;
    private boolean fhx;
    private long gof;
    private long gqi;
    private boolean hlt;
    private long ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    boolean f6935lb;
    private final ro lse;
    private boolean maa;
    private com.bytedance.sdk.openadsdk.yz.wsy ol;
    private boolean onz;
    private final String vt;
    private String wey;
    private final Activity wsy;
    private final lse wu;
    final boolean yz;
    protected boolean fm = false;
    boolean ro = false;
    protected boolean jnr = false;
    private long irt = -1;
    private int qhl = -1;
    private boolean hi = false;
    private int nt = 0;
    private float mq = 1.0f;
    private boolean gzf = false;
    private volatile boolean wbw = false;
    private HashSet<String> sds = new HashSet<>();

    public qhl(ro roVar) {
        this.lse = roVar;
        this.wsy = roVar.xgn;
        this.wu = roVar.ro;
        this.yz = roVar.yz;
        this.vt = roVar.jnr;
    }

    private void ne() {
        f fVar = this.ajl;
        if (fVar == null || fVar.ku() == null) {
            return;
        }
        this.ku = this.ajl.ajl();
        if (this.ajl.ku().lb() || !this.ajl.ku().ro()) {
            this.ajl.ro();
            this.ajl.yz();
            this.fm = true;
        }
    }

    public boolean ai() {
        return this.ajl != null;
    }

    public boolean ajl() {
        f fVar = this.ajl;
        return (fVar == null || fVar.ku() == null || !this.ajl.ku().ajl()) ? false : true;
    }

    public void bx() {
        f fVar = this.ajl;
        if (fVar instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
            ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) fVar).hxv();
        }
    }

    public long dsz() {
        f fVar = this.ajl;
        return fVar != null ? fVar.ajl() : this.ku;
    }

    public boolean duv() {
        return this.fm;
    }

    public boolean ef() {
        f fVar = this.ajl;
        return (fVar == null || fVar.ku() == null || !this.ajl.ku().wsy()) ? false : true;
    }

    public long fhx() {
        return this.ku;
    }

    public long fm() {
        return this.irt;
    }

    public void gc() {
        try {
            if (ajl()) {
                this.jnr = true;
                maa();
            }
        } catch (Exception e10) {
            wey.lb("TTAD.RFVideoPlayerMag", "onPause throw Exception :" + e10.getMessage());
        }
    }

    public b gof() {
        f fVar = this.ajl;
        if (fVar != null) {
            return fVar.ku();
        }
        return null;
    }

    public void gqi() {
        f fVar = this.ajl;
        if (fVar == null) {
            return;
        }
        fVar.yz();
        this.ajl = null;
    }

    public boolean gzf() {
        f fVar = this.ajl;
        if (fVar != null) {
            if (fVar.ku() != null) {
                b bVarKu = this.ajl.ku();
                if (bVarKu.wsy() || bVarKu.wu()) {
                    f fVar2 = this.ajl;
                    if (fVar2 instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
                        ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) fVar2).gc();
                    }
                    return true;
                }
            } else if (duv()) {
                fm(false);
                f fVar3 = this.ajl;
                if (fVar3 instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
                    ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) fVar3).gc();
                }
                return true;
            }
        }
        return false;
    }

    public void ha() {
        int i10 = this.nt;
        if (i10 == 1 || i10 == 2) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("switch", 0);
                fm(jSONObject);
            } catch (Throwable th) {
                wey.fm("TTAD.RFVideoPlayerMag", "onStopPlaySpeed: ", th);
            }
        }
    }

    public int hi() {
        f fVar = this.ajl;
        if (fVar != null) {
            return fVar.wu();
        }
        return 0;
    }

    public int hlt() {
        f fVar = this.ajl;
        if (fVar != null) {
            return fVar.vt();
        }
        return 0;
    }

    public void hxv() {
        this.hi = false;
        gqi();
    }

    public boolean ib() {
        return this.dsz;
    }

    public void irt() {
        try {
            if (ajl()) {
                this.ajl.ro();
            }
        } catch (Throwable th) {
            wey.lb("RewardFullVideoPlayerManager onPause throw Exception :" + th.getMessage(), new Object[0]);
        }
    }

    public com.bytedance.sdk.openadsdk.yz.wsy jnr() {
        return this.ol;
    }

    public void ku() {
        this.wbw = false;
        mq mqVar = this.lse.zan;
        if (mqVar != null) {
            mqVar.removeMessages(300);
        }
    }

    public void lb(boolean z10) {
        this.f6935lb = z10;
    }

    public long lse() {
        f fVar = this.ajl;
        if (fVar != null) {
            return fVar.ef();
        }
        return 0L;
    }

    public void lz() {
        f fVar = this.ajl;
        if (fVar instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
            ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) fVar).bx();
        }
    }

    public void maa() {
        f fVar = this.ajl;
        if (fVar != null) {
            fVar.ro();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x003d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public double mon() {
        double d10;
        long jYz;
        com.bytedance.sdk.openadsdk.component.reward.duv duvVar;
        sds sdsVarHlt = this.wu.hlt();
        if (com.bytedance.sdk.openadsdk.core.model.wey.yz(this.wu) && sdsVarHlt != null) {
            jYz = sdsVarHlt.ro();
        } else {
            if (!com.bytedance.sdk.openadsdk.core.model.wey.wu(this.wu) || sdsVarHlt == null) {
                com.bykv.vk.openvk.fm.fm.fm.lb.b bVarEx = this.wu.ex();
                d10 = bVarEx != null ? bVarEx.f5924d * ((double) bVarEx.f5938r) : 0.0d;
                duvVar = this.lse.f6942qb;
                if (duvVar != null) {
                    duvVar.fm((long) d10);
                }
                return d10;
            }
            jYz = sdsVarHlt.yz();
        }
        d10 = jYz;
        duvVar = this.lse.f6942qb;
        if (duvVar != null) {
        }
        return d10;
    }

    public long mq() {
        f fVar = this.ajl;
        if (fVar != null) {
            return fVar.ef();
        }
        return 0L;
    }

    public long nt() {
        f fVar = this.ajl;
        if (fVar == null) {
            return 0L;
        }
        return this.ajl.wsy() + fVar.ef();
    }

    public boolean ol() {
        f fVar = this.ajl;
        return fVar != null && fVar.ku() == null;
    }

    public long onz() {
        return this.duv;
    }

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

    public void qf() {
        f fVar = this.ajl;
        if (fVar != null) {
            fVar.fm();
        }
    }

    public long qhl() {
        f fVar = this.ajl;
        if (fVar != null) {
            return fVar.wsy();
        }
        return 0L;
    }

    public long ro() {
        return this.gof;
    }

    public void sds() {
        f fVar = this.ajl;
        if (fVar != null) {
            fVar.lb();
        }
    }

    public void si() {
        f fVar = this.ajl;
        if (fVar == null || fVar.ku() == null) {
            return;
        }
        this.ku = this.ajl.ajl();
        wey();
        fm(true);
        this.dsz = true;
    }

    public void tzk() {
        f fVar = this.ajl;
        if (fVar instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
            ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) fVar).mon();
        }
    }

    public boolean vt() {
        f fVar = this.ajl;
        return fVar != null && fVar.onz();
    }

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

    public void wey() {
        f fVar = this.ajl;
        if (fVar != null) {
            fVar.jnr();
        }
    }

    public boolean wsy() {
        f fVar = this.ajl;
        return fVar != null && fVar.dsz();
    }

    public a wu() {
        f fVar = this.ajl;
        if (fVar != null) {
            return fVar instanceof com.bytedance.sdk.openadsdk.component.reward.yz ? ((com.bytedance.sdk.openadsdk.component.reward.yz) fVar).qhl() : fVar.duv();
        }
        return null;
    }

    public boolean xgn() {
        f fVar = this.ajl;
        if (fVar == null || fVar.ku() == null) {
            return false;
        }
        return this.ajl.ku().fm();
    }

    public boolean yz() {
        int i10;
        return this.gzf ? this.hi && this.nt == 1 : this.hi && ((i10 = this.nt) == 2 || i10 == 1);
    }

    public View zan() {
        f fVar = this.ajl;
        if (fVar instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
            return (View) ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) fVar).xgn();
        }
        return null;
    }

    public void fm(int i10, String str) {
        this.qhl = i10;
        this.wey = str;
    }

    public void jnr(boolean z10) {
        this.fhx = z10;
        f fVar = this.ajl;
        if (fVar instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
            ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) fVar).ajl(z10);
        }
    }

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

    public void ro(long j10) {
        this.ku = j10;
    }

    public void yz(boolean z10) {
        this.hlt = z10;
        if (this.ajl instanceof com.bytedance.sdk.openadsdk.core.fhx.yz.fm) {
            if (z10) {
                ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) this.ajl).ro(this.wu.ex().f5938r);
            } else {
                com.bykv.vk.openvk.fm.fm.fm.lb.b bVarEx = this.wu.ex();
                bVarEx.getClass();
                bVarEx.f5938r = Math.min(4, Math.max(1, 1));
                ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) this.ajl).ro(1);
            }
        }
    }

    public void fm(long j10) {
        this.irt = j10;
    }

    private void ro(long j10, long j11) {
        int iAbs = (int) Math.abs(((long) this.qhl) - j10);
        int i10 = this.qhl;
        if (i10 < 0 || iAbs > 500 || i10 > j11 || iAbs >= 500 || this.sds.contains(this.wey)) {
            return;
        }
        if (this.qhl > j10) {
            com.bytedance.sdk.openadsdk.core.fhx.lb().postDelayed(new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.qhl.1
                @Override // java.lang.Runnable
                public void run() {
                    qhl.this.gc();
                    qhl.this.lse.hlt.fm(qhl.this.qhl, qhl.this.wey);
                }
            }, iAbs);
        } else {
            gc();
            this.lse.hlt.fm(this.qhl, this.wey);
        }
        this.sds.add(this.wey);
    }

    public void fm(fm.InterfaceC0073fm interfaceC0073fm) {
        this.ai = interfaceC0073fm;
    }

    public void fm(com.bytedance.sdk.openadsdk.yz.wsy wsyVar) {
        this.ol = wsyVar;
    }

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

    public void fm(FrameLayout frameLayout, com.bytedance.sdk.openadsdk.yz.wsy wsyVar) {
        if (this.maa) {
            return;
        }
        this.maa = true;
        this.f6934ef = frameLayout;
        if (this.wu.cap() != null) {
            this.nt = this.wu.cap().ro();
            this.mq = this.wu.cap().fm();
        }
        this.ol = wsyVar;
        if (lse.jnr(this.wu)) {
            this.gzf = true;
            this.ajl = new com.bytedance.sdk.openadsdk.core.fhx.yz.fm(this.wsy, this.f6934ef, this.wu, wsyVar);
            yz(this.hlt);
            fm.InterfaceC0073fm interfaceC0073fm = this.ai;
            if (interfaceC0073fm != null) {
                ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) this.ajl).fm(interfaceC0073fm);
            }
            ((com.bytedance.sdk.openadsdk.core.fhx.yz.fm) this.ajl).ajl(this.fhx);
            return;
        }
        this.gzf = false;
        com.bytedance.sdk.openadsdk.component.reward.yz yzVar = new com.bytedance.sdk.openadsdk.component.reward.yz(this.wu, wsyVar);
        this.ajl = yzVar;
        fm.InterfaceC0073fm interfaceC0073fm2 = this.ai;
        if (interfaceC0073fm2 != null) {
            yzVar.fm(interfaceC0073fm2);
        }
    }

    public void ro(boolean z10) {
        f fVar = this.ajl;
        if (fVar != null) {
            fVar.ro();
            this.onz = z10;
        }
    }

    public void ro(com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar) {
        if (!gzf() || roVar == null) {
            return;
        }
        roVar.fm(fhx(), true);
    }

    public void fm(long j10, long j11) {
        this.duv = j10;
        if (this.wbw && (xgn() || ajl() || j10 > 0)) {
            ku();
        }
        ro(j10, j11);
    }

    public void fm(int i10, int i11) {
        if (this.ajl != null) {
            fhx.fm fmVar = new fhx.fm();
            fmVar.lb(qhl());
            fmVar.yz(nt());
            fmVar.ro(dsz());
            fmVar.fm(i10);
            fmVar.ro(i11);
            com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.yz(this.ajl.duv(), fmVar);
        }
    }

    public void fm(b6.b bVar) {
        f fVar = this.ajl;
        if (fVar != null) {
            fVar.fm(bVar);
        }
    }

    public void fm(boolean z10, String str) {
        f fVar = this.ajl;
        if (fVar != null) {
            fVar.fm(z10, str);
        }
    }

    public void fm(String str, boolean z10) {
        if (this.ajl != null) {
            long jDsz = dsz();
            if (this.wu.bkb()) {
                jDsz = this.lse.ajl();
            }
            long j10 = jDsz;
            JSONObject jSONObjectFm = bx.fm(this.wu, this.ajl.wsy(), this.ajl.ku());
            try {
                jSONObjectFm.put("auto_click", z10);
                if (!z10) {
                    ro roVar = this.lse;
                    com.bytedance.sdk.openadsdk.yz.lb.fm(jSONObjectFm, roVar.yz ? roVar.ro.we() : roVar.ro.mxq(), (int) j10);
                }
            } catch (Exception unused) {
            }
            com.bytedance.sdk.openadsdk.yz.lb.fm(this.wu, this.vt, str, j10, hlt(), jSONObjectFm, this.ol);
            nt();
            hlt();
        }
        tzk();
    }

    public boolean fm(long j10, boolean z10, Map<String, Object> map, com.bytedance.sdk.openadsdk.component.reward.ro.ro roVar) {
        boolean zFm;
        boolean z11 = false;
        if (!ai()) {
            ro roVar2 = this.lse;
            com.bytedance.sdk.openadsdk.yz.vt.fm(roVar2.ro, "show_ad_fail", roVar2.jnr, "video_controller_not_ready");
            return false;
        }
        if (com.bytedance.sdk.openadsdk.core.model.wey.yz(this.lse.ro) || com.bytedance.sdk.openadsdk.core.model.wey.wu(this.lse.ro)) {
            return true;
        }
        if (!z10 || !ol()) {
            fm(roVar);
        }
        try {
            zFm = fm(j10, this.lse.f6943qf);
            try {
                this.dsz = false;
            } catch (Exception unused) {
                z11 = zFm;
                zFm = z11;
            }
        } catch (Exception unused2) {
        }
        if (zFm && !z10) {
            this.lse.nt.fm(map);
        } else if (!zFm) {
            ro roVar3 = this.lse;
            com.bytedance.sdk.openadsdk.yz.vt.fm(roVar3.ro, "show_ad_fail", roVar3.jnr, "video_play_fail");
        }
        return zFm;
    }

    public void fm(com.bytedance.sdk.openadsdk.component.reward.ro.ro roVar) {
        if (this.lse.f6936ef.get()) {
            return;
        }
        ro roVar2 = this.lse;
        if (roVar2.si && !ai.lb(roVar2.ro)) {
            boolean z10 = !lse.jnr(this.lse.ro);
            boolean zYz = this.lse.hlt.yz();
            int iOnz = com.bytedance.sdk.openadsdk.core.gof.yz().onz(String.valueOf(this.lse.ajl));
            if ((z10 && iOnz == 1 && zYz) || com.bytedance.sdk.openadsdk.core.model.wey.yz(this.lse.ro) || com.bytedance.sdk.openadsdk.core.model.wey.wu(this.lse.ro) || this.jnr || !roVar.jnr()) {
                return;
            }
            this.lse.sds.ku();
            Message messageObtain = Message.obtain();
            messageObtain.what = 300;
            this.lse.zan.sendMessageDelayed(messageObtain, 5000L);
            this.wbw = true;
        }
    }

    public boolean fm(JSONObject jSONObject) {
        int i10;
        if (this.ajl == null || jSONObject == null || !((i10 = this.nt) == 1 || i10 == 2)) {
            this.hi = false;
            return false;
        }
        int iOptInt = jSONObject.optInt("switch", 0);
        float fOptDouble = (float) jSONObject.optDouble("speed", 0.0d);
        this.mq = fOptDouble;
        if (fOptDouble <= 0.0f && this.lse.ro.cap() != null) {
            this.mq = this.lse.ro.cap().fm();
        }
        if (iOptInt == 0) {
            this.mq = 1.0f;
            if (this.hi) {
                long jCurrentTimeMillis = (System.currentTimeMillis() - this.gqi) + this.gof;
                this.gof = jCurrentTimeMillis;
                f fVar = this.ajl;
                if (fVar != null) {
                    fVar.fm(jCurrentTimeMillis);
                }
                com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar = this.lse.mon;
                if (roVar != null) {
                    roVar.yz(false);
                }
            }
        } else if (iOptInt == 1 && !this.hi) {
            this.gqi = System.currentTimeMillis();
            com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar2 = this.lse.mon;
            if (roVar2 != null) {
                roVar2.yz(true);
            }
        }
        this.hi = iOptInt == 1;
        if (this.nt == 1) {
            return true;
        }
        f fVar2 = this.ajl;
        if (fVar2 == null) {
            return false;
        }
        return fVar2.fm(this.mq);
    }

    private boolean fm(long j10, boolean z10) {
        if (this.ajl == null || this.wu.ex() == null) {
            return false;
        }
        String strB = ((e6.a) CacheDirFactory.getICacheDir(this.wu.il())).b();
        File file = new File(strB, this.wu.ex().c());
        if (file.exists() && file.length() > 0) {
            this.ro = true;
        }
        com.bytedance.sdk.openadsdk.core.fhx.fm.ro roVarFm = lse.fm(strB, this.wu);
        roVarFm.ro(this.wu.eo());
        roVarFm.ro(this.f6934ef.getWidth());
        roVarFm.lb(this.f6934ef.getHeight());
        roVarFm.lb(this.wu.gt());
        roVarFm.fm(j10);
        roVarFm.fm(z10);
        return this.ajl.fm(roVarFm);
    }

    public void fm(com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar) {
        try {
            this.jnr = false;
            if (duv()) {
                ne();
                ro(roVar);
            } else if (ef()) {
                sds();
            }
        } catch (Throwable th) {
            wey.lb("TTAD.RFVideoPlayerMag", "onContinue throw Exception :" + th.getMessage());
        }
    }

    public void fm(boolean z10, com.bytedance.sdk.openadsdk.core.fhx.yz.ro roVar, boolean z11) {
        if (this.onz || !(!z11 || z10 || this.jnr)) {
            if (ef()) {
                sds();
            } else {
                ne();
                ro(roVar);
            }
            this.onz = false;
        }
    }
}
