package com.bytedance.sdk.openadsdk.utils;

import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.NonNull;
import com.bytedance.sdk.openadsdk.activity.single.TTFullScreenVideoActivity;
import com.bytedance.sdk.openadsdk.activity.single.TTRewardVideoActivity;
import com.bytedance.sdk.openadsdk.common.TTAdDislikeToast;
import com.bytedance.sdk.openadsdk.core.fhx.yz.fm;

/* JADX INFO: loaded from: classes2.dex */
public class pkk implements Handler.Callback, fm.InterfaceC0073fm {
    private boolean ajl;
    private int duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private boolean f7548ef;
    private final com.bytedance.sdk.openadsdk.component.reward.fm.ro jnr;
    private int vt;
    private boolean wsy;
    private boolean wu;
    private final com.bytedance.sdk.openadsdk.core.model.lse yz;
    private float fm = 1.0f;
    private int ro = 1000;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private final Handler f7549lb = new Handler(Looper.getMainLooper(), this);
    private int ku = 0;

    public pkk(@NonNull com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar, @NonNull com.bytedance.sdk.openadsdk.core.model.lse lseVar) {
        this.vt = 0;
        this.duv = 0;
        this.jnr = roVar;
        this.yz = lseVar;
        if (lseVar.ii()) {
            if (lseVar.we() >= 0) {
                this.duv = lseVar.we();
            } else {
                this.duv = com.bytedance.sdk.openadsdk.core.gof.yz().ku(String.valueOf(lseVar.pg()));
            }
        } else if (lseVar.vc()) {
            if (lseVar.mxq() >= 0) {
                this.duv = lseVar.mxq();
            } else {
                this.duv = com.bytedance.sdk.openadsdk.core.gof.yz().wey(String.valueOf(lseVar.pg()));
            }
        }
        this.vt = (int) roVar.sds.mon();
        com.bytedance.sdk.component.utils.wey.fm("TTAD.TopLayoutHelper", "totalTime: " + this.vt + ", skipTime=" + this.duv);
    }

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

    @Override // android.os.Handler.Callback
    public boolean handleMessage(@NonNull Message message) {
        if (message.what == 1024) {
            int i10 = this.vt;
            int i11 = this.ku;
            int i12 = i10 - i11;
            this.jnr.sds.fm(((long) i11) * 1000);
            com.bytedance.sdk.component.utils.wey.fm("TTAD.TopLayoutHelper", "handleMessage: currentTime= " + this.ku + ", mRemainTimeInSeconds=" + i12);
            if (i12 > 0) {
                Activity activity = this.jnr.xgn;
                if (activity instanceof TTRewardVideoActivity) {
                    ((TTRewardVideoActivity) activity).lb(((long) this.ku) * 1000, this.vt);
                }
                com.bytedance.sdk.openadsdk.component.reward.view.ef efVar = this.jnr.hlt;
                boolean z10 = false;
                if (efVar != null && efVar.fm() != null) {
                    this.jnr.hlt.fm().setTime(String.valueOf(i12), this.ku, 0, false);
                }
                if (this.yz.ii()) {
                    com.bytedance.sdk.openadsdk.component.reward.view.ef efVar2 = this.jnr.hlt;
                    if (efVar2 != null) {
                        if (efVar2.ef() && this.duv > 0) {
                            z10 = true;
                        }
                        this.f7548ef = z10;
                    }
                    if (!this.f7548ef || this.ku < this.duv || this.jnr.ro.ywr() == 5 || this.jnr.ro.ywr() == 33) {
                        this.jnr.f6938ha.fm(String.valueOf(i12), null);
                    } else {
                        this.jnr.fm(true);
                        this.jnr.f6938ha.fm(String.valueOf(i12), TTAdDislikeToast.getSkipText());
                        this.jnr.f6938ha.jnr(true);
                    }
                } else if (this.yz.vc() && (this.jnr.hlt.ef() || this.jnr.ro.bq())) {
                    Activity activity2 = this.jnr.xgn;
                    if (activity2 instanceof TTFullScreenVideoActivity) {
                        ((TTFullScreenVideoActivity) activity2).fm(this.ku);
                    }
                    this.jnr.f6938ha.yz(true);
                    this.jnr.f6938ha.fm(String.valueOf(i12), null);
                }
                this.ku++;
                if (this.jnr.sds.lb()) {
                    com.bytedance.sdk.openadsdk.core.model.ol olVarCap = this.jnr.ro.cap();
                    if (olVarCap != null) {
                        float fFm = olVarCap.fm();
                        this.fm = fFm;
                        if (fFm <= 0.0f) {
                            this.fm = 1.0f;
                        }
                    }
                } else {
                    this.fm = 1.0f;
                }
                int i13 = (int) (1000.0f / this.fm);
                com.bytedance.sdk.component.utils.wey.fm("TTAD.TopLayoutHelper", "handleMessage: next msg intervalInMillis = ".concat(String.valueOf(i13)));
                this.f7549lb.sendEmptyMessageDelayed(message.what, i13);
            }
        }
        return true;
    }

    public void jnr() {
        this.f7549lb.removeMessages(1024);
        this.ajl = false;
        this.wu = true;
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar = this.jnr;
        if (roVar != null) {
            roVar.sds.ha();
        }
    }

    public void lb() {
        if (this.ajl) {
            this.f7549lb.removeMessages(1024);
            this.f7549lb.sendEmptyMessage(1024);
            this.wsy = false;
        }
    }

    public void ro() {
        this.f7549lb.sendEmptyMessage(1024);
        this.wsy = false;
    }

    public void yz() {
        if (!this.ajl || this.wsy) {
            return;
        }
        this.f7549lb.removeMessages(1024);
        this.wsy = true;
    }

    public void fm(long j10) {
        int iCeil = (int) Math.ceil(j10 / 1000.0d);
        if (this.wsy && !this.wu) {
            this.ku = iCeil;
            lb();
        } else {
            if (this.ajl || this.wu) {
                return;
            }
            this.ku = iCeil;
            this.ajl = true;
            ro();
        }
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.yz.fm.InterfaceC0073fm
    public void fm(int i10) {
        com.bytedance.sdk.component.utils.wey.fm("TTAD.TopLayoutHelper", "onPlayerStateChanged: ".concat(String.valueOf(i10)));
        if (i10 == 1) {
            lb();
            return;
        }
        if (i10 == 2) {
            yz();
        } else if (i10 == 3 || i10 == 4) {
            jnr();
        }
    }
}
