package l5;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.bumptech.glide.load.engine.o;
import com.bumptech.glide.r;
import com.bumptech.glide.u;
import java.util.ArrayList;
import t5.n;
import t5.p;

/* JADX INFO: loaded from: classes.dex */
public final class k {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final y4.a f30143a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Handler f30144b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ArrayList f30145c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final u f30146d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final c5.e f30147e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f30148f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f30149g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public r f30150h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public g f30151i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f30152j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public g f30153k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public Bitmap f30154l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public g f30155m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public int f30156n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f30157o;

    @Nullable
    private j onEveryFrameListener;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public int f30158p;

    public k(com.bumptech.glide.c cVar, y4.e eVar, int i10, int i11, i5.c cVar2, Bitmap bitmap) {
        c5.e eVar2 = cVar.f5552a;
        com.bumptech.glide.k kVar = cVar.f5554c;
        u uVarD = com.bumptech.glide.c.d(kVar.getBaseContext());
        r rVarV = com.bumptech.glide.c.d(kVar.getBaseContext()).e(Bitmap.class).a(u.f5902k).a(((q5.f) ((q5.f) q5.f.v(o.f5752b).u()).q(true)).i(i10, i11));
        this.f30145c = new ArrayList();
        this.f30146d = uVarD;
        Handler handler = new Handler(Looper.getMainLooper(), new i(this, 0));
        this.f30147e = eVar2;
        this.f30144b = handler;
        this.f30150h = rVarV;
        this.f30143a = eVar;
        c(cVar2, bitmap);
    }

    public final void a() {
        int i10;
        if (!this.f30148f || this.f30149g) {
            return;
        }
        g gVar = this.f30155m;
        if (gVar != null) {
            this.f30155m = null;
            b(gVar);
            return;
        }
        this.f30149g = true;
        y4.a aVar = this.f30143a;
        y4.e eVar = (y4.e) aVar;
        y4.c cVar = eVar.f36840m;
        int i11 = cVar.f36815c;
        long jUptimeMillis = SystemClock.uptimeMillis() + ((long) ((i11 <= 0 || (i10 = eVar.f36839l) < 0) ? 0 : (i10 < 0 || i10 >= i11) ? -1 : ((y4.b) cVar.f36817e.get(i10)).f36810i));
        int i12 = (eVar.f36839l + 1) % eVar.f36840m.f36815c;
        eVar.f36839l = i12;
        this.f30153k = new g(this.f30144b, i12, jUptimeMillis);
        this.f30150h.a((q5.f) new q5.f().n(new s5.d(Double.valueOf(Math.random())))).load((Object) aVar).into(this.f30153k, null, t5.g.f32964a);
    }

    public final void b(g gVar) {
        this.f30149g = false;
        boolean z10 = this.f30152j;
        Handler handler = this.f30144b;
        if (z10) {
            handler.obtainMessage(2, gVar).sendToTarget();
            return;
        }
        if (!this.f30148f) {
            this.f30155m = gVar;
            return;
        }
        if (gVar.f30140f != null) {
            Bitmap bitmap = this.f30154l;
            if (bitmap != null) {
                this.f30147e.a(bitmap);
                this.f30154l = null;
            }
            g gVar2 = this.f30151i;
            this.f30151i = gVar;
            ArrayList arrayList = this.f30145c;
            for (int size = arrayList.size() - 1; size >= 0; size--) {
                d dVar = (d) ((h) arrayList.get(size));
                Object callback = dVar.getCallback();
                while (callback instanceof Drawable) {
                    callback = ((Drawable) callback).getCallback();
                }
                if (callback == null) {
                    dVar.stop();
                    dVar.invalidateSelf();
                } else {
                    dVar.invalidateSelf();
                    g gVar3 = dVar.f30126a.f30125a.f30151i;
                    if ((gVar3 != null ? gVar3.f30138d : -1) == ((y4.e) r5.f30143a).f36840m.f36815c - 1) {
                        dVar.f30131f++;
                    }
                    int i10 = dVar.f30132g;
                    if (i10 != -1 && dVar.f30131f >= i10) {
                        dVar.stop();
                    }
                }
            }
            if (gVar2 != null) {
                handler.obtainMessage(2, gVar2).sendToTarget();
            }
        }
        a();
    }

    public final void c(a5.o oVar, Bitmap bitmap) {
        this.f30154l = (Bitmap) n.checkNotNull(bitmap);
        this.f30150h = this.f30150h.a(new q5.f().r(oVar, true));
        this.f30156n = p.b(bitmap);
        this.f30157o = bitmap.getWidth();
        this.f30158p = bitmap.getHeight();
    }

    @VisibleForTesting
    public void setOnEveryFrameReadyListener(@Nullable j jVar) {
    }
}
