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

import android.os.Handler;
import android.os.Message;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.core.model.ai;
import com.bytedance.sdk.openadsdk.maa.fm.fm;
import com.bytedance.sdk.openadsdk.utils.DeviceUtils;

/* JADX INFO: loaded from: classes2.dex */
public class wu extends vt implements Handler.Callback {
    boolean ajl;
    boolean fm;
    private int hi;
    private boolean hlt;
    int jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    int f6947lb;
    private int lse;
    private int maa;
    private boolean mq;
    private int nt;
    long ro;
    private boolean sds;
    private final Handler wey;
    protected int wsy;
    int yz;

    public wu(ro roVar) {
        super(roVar);
        this.wey = new Handler(this);
        this.fm = false;
        this.ro = 0L;
        this.f6947lb = 0;
        this.yz = 0;
        this.jnr = 0;
        this.ajl = false;
        this.sds = false;
        this.maa = 0;
        this.hlt = false;
        this.hi = 0;
        this.nt = 0;
        this.mq = false;
        this.wsy = ai.ef(this.vt);
        this.yz = this.vt.nss();
        int iQu = this.vt.qu();
        this.jnr = iQu;
        this.hi = Math.max(0, this.yz - iQu);
    }

    private boolean gof() {
        return this.wu && ai.lb(this.duv.ro) && !this.gqi.get();
    }

    private boolean irt() {
        if (this.duv.pbk) {
            return false;
        }
        int i10 = this.wsy;
        return 1 == i10 || 2 == i10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void qhl() {
        int i10 = !this.hlt ? this.jnr - this.f6947lb : this.jnr + this.nt;
        int i11 = com.bytedance.sdk.openadsdk.core.gof.yz().mq(String.valueOf(this.duv.ajl)).ajl;
        int i12 = this.yz;
        boolean z10 = i12 <= 0 || (((float) i10) / ((float) i12)) * 100.0f >= ((float) i11);
        int iFm = com.bytedance.sdk.openadsdk.core.gof.yz().fm(String.valueOf(this.duv.ajl));
        if (iFm == 0) {
            com.bytedance.sdk.openadsdk.maa.fm.fm fmVar = this.gof;
            boolean zAjl = fmVar != null ? fmVar.ajl() : false;
            if (this.fhx) {
                zAjl = true;
            }
            if (!z10 || !zAjl) {
                return;
            }
        } else if (iFm != 1 || !z10) {
            return;
        }
        this.duv.mon.ro(true);
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void ajl() {
        if (this.onz && !this.irt) {
            super.ajl();
            this.wey.removeCallbacksAndMessages(null);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void ef() {
        if (this.onz) {
            this.sds = true;
            this.wey.removeMessages(900);
            this.wey.removeMessages(600);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void fm(int i10) {
        this.f6947lb = i10;
        this.lse = i10;
    }

    @Override // android.os.Handler.Callback
    public boolean handleMessage(Message message) {
        if (message.what != 900 || !gof()) {
            return true;
        }
        int i10 = message.arg1;
        boolean z10 = false;
        if (this.hlt) {
            int i11 = this.jnr;
            int i12 = this.nt;
            int i13 = i11 + i12;
            int i14 = this.yz;
            if (i13 < i14) {
                this.nt = i12 + 1;
                Message messageObtain = Message.obtain();
                messageObtain.what = 900;
                messageObtain.arg1 = 0;
                this.wey.sendMessageDelayed(messageObtain, 1000L);
            } else {
                this.nt = i14 - i11;
            }
        } else if (i10 > 0) {
            if (this.maa == 0 && 2 == this.wsy) {
                z10 = true;
            }
            this.duv.f6938ha.yz(true);
            if (!z10) {
                this.duv.f6938ha.fm(String.valueOf(i10), null);
            }
            Message messageObtain2 = Message.obtain();
            messageObtain2.what = 900;
            int i15 = i10 - 1;
            messageObtain2.arg1 = i15;
            this.wey.sendMessageDelayed(messageObtain2, 1000L);
            this.f6947lb = i15;
            this.lse = i10;
        } else {
            this.ajl = true;
            if (!ai.wu(this.vt) || (ai.wey(this.vt) && this.gof.jnr())) {
                this.duv.f6938ha.yz(false);
                this.duv.irt.set(true);
                this.duv.so.dsz();
            } else {
                this.duv.f6938ha.lb();
                this.duv.f6938ha.jnr(true);
            }
            com.bytedance.sdk.openadsdk.maa.fm.fm fmVar = this.gof;
            if (fmVar == null || fmVar.jnr()) {
                this.fhx = true;
            }
            if (this.hi > 0) {
                this.hlt = true;
                this.nt++;
                Message messageObtain3 = Message.obtain();
                messageObtain3.what = 900;
                messageObtain3.arg1 = 0;
                this.wey.sendMessageDelayed(messageObtain3, 1000L);
            }
            this.lse = 0;
        }
        qhl();
        return true;
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void jnr() {
        if (this.onz) {
            super.jnr();
            ef();
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void lb() {
        if (this.onz) {
            this.wu = true;
            boolean zIrt = irt();
            if (zIrt) {
                this.gof.fm(new fm.InterfaceC0099fm() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.wu.2
                    @Override // com.bytedance.sdk.openadsdk.maa.fm.fm.InterfaceC0099fm
                    public void fm(int i10) {
                        if (wu.this.mq) {
                            return;
                        }
                        wu.this.maa = i10;
                        wu.this.gof.fm((fm.InterfaceC0099fm) null);
                        wu.this.ro(i10);
                    }
                });
            }
            this.gof.fm();
            if (ai.wu(this.vt)) {
                this.duv.ol.ajl();
            }
            this.ro = System.currentTimeMillis();
            if (!zIrt) {
                ro(0);
            }
            this.duv.mon.pcm();
            com.bytedance.sdk.openadsdk.component.reward.duv duvVar = this.duv.f6942qb;
            if (duvVar != null) {
                duvVar.fm(this.yz);
            }
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public boolean vt() {
        return this.ajl;
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public int wsy() {
        return this.f6947lb;
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public int wu() {
        return this.lse;
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void yz() {
        com.bytedance.sdk.openadsdk.core.widget.ro roVar;
        if (this.onz) {
            super.yz();
            if (DeviceUtils.wsy() == 0) {
                this.duv.f6943qf = true;
            }
            ro roVar2 = this.duv;
            if (roVar2.f6943qf) {
                roVar2.f6938ha.ro(true);
                lb(true);
            }
            com.bytedance.sdk.openadsdk.component.reward.ro.ro roVar3 = this.duv.so;
            if ((roVar3 == null || (roVar = roVar3.duv) == null || !roVar.isShowing()) && ku() && wsy() > 0) {
                fm(0L);
            }
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public com.bytedance.sdk.openadsdk.dsz.wsy ro() {
        return new com.bytedance.sdk.openadsdk.dsz.wsy() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.wu.1
            @Override // com.bytedance.sdk.openadsdk.dsz.wsy
            public void fm() {
                wu.this.qhl();
            }
        };
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void ro(int i10) {
        fm(this.jnr);
        if (this.sds) {
            return;
        }
        Handler handler = this.wey;
        handler.sendMessage(handler.obtainMessage(900, this.jnr, i10));
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void fm() {
        if (this.onz && !this.dsz) {
            super.fm();
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void fm(boolean z10) {
        if (this.qhl != null) {
            try {
                com.bytedance.sdk.openadsdk.maa.fm.ro roVarFm = com.bytedance.sdk.openadsdk.maa.fm.yz.fm().fm(this.vt, this.qhl, ro());
                this.gof = roVarFm;
                roVarFm.fm(this.duv.mon);
            } catch (Throwable th) {
                wey.lb("RVIVPlayableNewManager", "PreRender injection exception" + th.getMessage());
            }
            if (this.gof == null) {
                super.fm(z10);
            }
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.fm.vt
    public void fm(long j10) {
        if (this.onz && this.wu && !this.duv.vt.get() && this.sds) {
            this.sds = false;
            Message messageObtain = Message.obtain();
            messageObtain.what = 900;
            messageObtain.arg1 = wsy();
            messageObtain.arg2 = this.maa;
            this.wey.sendMessageDelayed(messageObtain, j10);
        }
    }
}
