package com.bytedance.sdk.openadsdk.component.ajl;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.NonNull;

/* JADX INFO: loaded from: classes2.dex */
public class ro implements Handler.Callback {
    private boolean duv;
    private long ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private fm f6871lb;
    private final com.bytedance.sdk.openadsdk.component.wu.fm ro;
    private long vt;
    private boolean wsy;
    private Handler fm = new Handler(Looper.myLooper(), this);
    private int yz = 0;
    private int jnr = 5;
    private int ajl = 0;
    private final int wu = 1000;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private int f6870ef = 1000;

    public ro(com.bytedance.sdk.openadsdk.component.wu.fm fmVar) {
        this.ro = fmVar;
    }

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

    @Override // android.os.Handler.Callback
    public boolean handleMessage(@NonNull Message message) {
        if (message.what == 100 && this.fm != null) {
            int i10 = message.arg1;
            fm(i10);
            if (i10 > 0) {
                Message messageObtain = Message.obtain();
                messageObtain.what = 100;
                messageObtain.arg1 = i10 - 1;
                this.fm.sendMessageDelayed(messageObtain, this.f6870ef);
            }
        }
        return true;
    }

    public void jnr() {
        this.fm.removeCallbacksAndMessages(null);
        this.fm = null;
    }

    public void lb() {
        if (this.fm != null) {
            Message messageObtain = Message.obtain();
            messageObtain.what = 100;
            messageObtain.arg1 = this.yz;
            this.fm.sendMessage(messageObtain);
        }
    }

    public void ro(int i10) {
        this.ajl = Math.min(i10, this.jnr);
    }

    public void yz() {
        Handler handler = this.fm;
        if (handler != null) {
            handler.removeMessages(100);
        }
    }

    public void fm(float f10) {
        int i10 = (int) f10;
        this.jnr = i10;
        if (i10 <= 0) {
            this.jnr = 5;
        }
    }

    public void ro() {
        Handler handler = this.fm;
        if (handler != null) {
            handler.sendMessage(handler.obtainMessage(100, this.jnr, 0));
        }
    }

    public void fm(fm fmVar) {
        this.f6871lb = fmVar;
    }

    public void fm(int i10) {
        this.yz = i10;
        int i11 = this.jnr - i10;
        this.ro.ro(((long) i11) * 1000);
        boolean z10 = true;
        if (i10 <= 0) {
            fm fmVar = this.f6871lb;
            if (fmVar != null && !this.wsy) {
                fmVar.ro();
                this.wsy = true;
            }
            i10 = 0;
        }
        fm fmVar2 = this.f6871lb;
        if (fmVar2 != null) {
            int iMax = Math.max(this.ajl - i11, 0);
            if (i10 != 0 && i11 < this.ajl) {
                z10 = false;
            }
            fmVar2.fm(iMax, z10);
        }
    }

    public void fm(int i10, float f10, boolean z10) {
        com.bytedance.sdk.openadsdk.component.wu.fm fmVar;
        if ((i10 == 1 || i10 == 2) && this.duv != z10) {
            this.duv = z10;
            if (i10 == 1 && (fmVar = this.ro) != null) {
                fmVar.fm(z10);
            }
            if (z10) {
                try {
                    this.f6870ef = (int) (1000.0f / f10);
                    this.ku = System.currentTimeMillis();
                    return;
                } catch (Throwable unused) {
                }
            } else {
                long jCurrentTimeMillis = (System.currentTimeMillis() - this.ku) + this.vt;
                this.vt = jCurrentTimeMillis;
                com.bytedance.sdk.openadsdk.component.wu.fm fmVar2 = this.ro;
                if (fmVar2 != null) {
                    fmVar2.fm(jCurrentTimeMillis);
                }
            }
            this.f6870ef = 1000;
        }
    }
}
