package com.bumptech.glide.request;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import com.bumptech.glide.c;
import ei.l;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
import lh.k;
import lh.q;
import lh.v;

/* loaded from: classes4.dex */
public final class h implements c, bi.g, g {
    private static final boolean E = Log.isLoggable("GlideRequest", 2);
    private int A;
    private int B;
    private boolean C;
    private RuntimeException D;

    /* renamed from: a, reason: collision with root package name */
    private int f12623a;

    /* renamed from: b, reason: collision with root package name */
    private final String f12624b;

    /* renamed from: c, reason: collision with root package name */
    private final fi.c f12625c;

    /* renamed from: d, reason: collision with root package name */
    private final Object f12626d;

    /* renamed from: e, reason: collision with root package name */
    private final e f12627e;

    /* renamed from: f, reason: collision with root package name */
    private final d f12628f;

    /* renamed from: g, reason: collision with root package name */
    private final Context f12629g;

    /* renamed from: h, reason: collision with root package name */
    private final com.bumptech.glide.d f12630h;

    /* renamed from: i, reason: collision with root package name */
    private final Object f12631i;

    /* renamed from: j, reason: collision with root package name */
    private final Class f12632j;

    /* renamed from: k, reason: collision with root package name */
    private final com.bumptech.glide.request.a f12633k;

    /* renamed from: l, reason: collision with root package name */
    private final int f12634l;

    /* renamed from: m, reason: collision with root package name */
    private final int f12635m;

    /* renamed from: n, reason: collision with root package name */
    private final com.bumptech.glide.g f12636n;

    /* renamed from: o, reason: collision with root package name */
    private final bi.h f12637o;

    /* renamed from: p, reason: collision with root package name */
    private final List f12638p;

    /* renamed from: q, reason: collision with root package name */
    private final ci.c f12639q;

    /* renamed from: r, reason: collision with root package name */
    private final Executor f12640r;

    /* renamed from: s, reason: collision with root package name */
    private v f12641s;

    /* renamed from: t, reason: collision with root package name */
    private k.d f12642t;

    /* renamed from: u, reason: collision with root package name */
    private long f12643u;

    /* renamed from: v, reason: collision with root package name */
    private volatile k f12644v;

    /* renamed from: w, reason: collision with root package name */
    private a f12645w;

    /* renamed from: x, reason: collision with root package name */
    private Drawable f12646x;

    /* renamed from: y, reason: collision with root package name */
    private Drawable f12647y;

    /* renamed from: z, reason: collision with root package name */
    private Drawable f12648z;

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes4.dex */
    public enum a {
        PENDING,
        RUNNING,
        WAITING_FOR_SIZE,
        COMPLETE,
        FAILED,
        CLEARED
    }

    private h(Context context, com.bumptech.glide.d dVar, Object obj, Object obj2, Class cls, com.bumptech.glide.request.a aVar, int i10, int i11, com.bumptech.glide.g gVar, bi.h hVar, e eVar, List list, d dVar2, k kVar, ci.c cVar, Executor executor) {
        this.f12624b = E ? String.valueOf(super.hashCode()) : null;
        this.f12625c = fi.c.a();
        this.f12626d = obj;
        this.f12629g = context;
        this.f12630h = dVar;
        this.f12631i = obj2;
        this.f12632j = cls;
        this.f12633k = aVar;
        this.f12634l = i10;
        this.f12635m = i11;
        this.f12636n = gVar;
        this.f12637o = hVar;
        this.f12627e = eVar;
        this.f12638p = list;
        this.f12628f = dVar2;
        this.f12644v = kVar;
        this.f12639q = cVar;
        this.f12640r = executor;
        this.f12645w = a.PENDING;
        if (this.D == null && dVar.g().a(c.C0289c.class)) {
            this.D = new RuntimeException("Glide request origin trace");
        }
    }

    private void A(v vVar, Object obj, jh.a aVar, boolean z10) {
        boolean z11;
        boolean s10 = s();
        this.f12645w = a.COMPLETE;
        this.f12641s = vVar;
        if (this.f12630h.h() <= 3) {
            Log.d("Glide", "Finished loading " + obj.getClass().getSimpleName() + " from " + aVar + " for " + this.f12631i + " with size [" + this.A + "x" + this.B + "] in " + ei.g.a(this.f12643u) + " ms");
        }
        x();
        boolean z12 = true;
        this.C = true;
        try {
            List list = this.f12638p;
            if (list != null) {
                Iterator it = list.iterator();
                z11 = false;
                while (it.hasNext()) {
                    z11 |= ((e) it.next()).b(obj, this.f12631i, this.f12637o, aVar, s10);
                }
            } else {
                z11 = false;
            }
            e eVar = this.f12627e;
            if (eVar == null || !eVar.b(obj, this.f12631i, this.f12637o, aVar, s10)) {
                z12 = false;
            }
            if (!(z12 | z11)) {
                this.f12637o.h(obj, this.f12639q.a(aVar, s10));
            }
            this.C = false;
            fi.b.f("GlideRequest", this.f12623a);
        } catch (Throwable th2) {
            this.C = false;
            throw th2;
        }
    }

    private void B() {
        if (l()) {
            Drawable q10 = this.f12631i == null ? q() : null;
            if (q10 == null) {
                q10 = p();
            }
            if (q10 == null) {
                q10 = r();
            }
            this.f12637o.d(q10);
        }
    }

    private void j() {
        if (this.C) {
            throw new IllegalStateException("You can't start or clear loads in RequestListener or Target callbacks. If you're trying to start a fallback request when a load fails, use RequestBuilder#error(RequestBuilder). Otherwise consider posting your into() or clear() calls to the main thread using a Handler instead.");
        }
    }

    private boolean k() {
        d dVar = this.f12628f;
        return dVar == null || dVar.j(this);
    }

    private boolean l() {
        d dVar = this.f12628f;
        return dVar == null || dVar.c(this);
    }

    private boolean m() {
        d dVar = this.f12628f;
        return dVar == null || dVar.e(this);
    }

    private void n() {
        j();
        this.f12625c.c();
        this.f12637o.a(this);
        k.d dVar = this.f12642t;
        if (dVar != null) {
            dVar.a();
            this.f12642t = null;
        }
    }

    private void o(Object obj) {
        List<e> list = this.f12638p;
        if (list == null) {
            return;
        }
        for (e eVar : list) {
        }
    }

    private Drawable p() {
        if (this.f12646x == null) {
            Drawable k10 = this.f12633k.k();
            this.f12646x = k10;
            if (k10 == null && this.f12633k.j() > 0) {
                this.f12646x = t(this.f12633k.j());
            }
        }
        return this.f12646x;
    }

    private Drawable q() {
        if (this.f12648z == null) {
            Drawable l10 = this.f12633k.l();
            this.f12648z = l10;
            if (l10 == null && this.f12633k.n() > 0) {
                this.f12648z = t(this.f12633k.n());
            }
        }
        return this.f12648z;
    }

    private Drawable r() {
        if (this.f12647y == null) {
            Drawable t10 = this.f12633k.t();
            this.f12647y = t10;
            if (t10 == null && this.f12633k.u() > 0) {
                this.f12647y = t(this.f12633k.u());
            }
        }
        return this.f12647y;
    }

    private boolean s() {
        d dVar = this.f12628f;
        return dVar == null || !dVar.getRoot().b();
    }

    private Drawable t(int i10) {
        return uh.b.a(this.f12629g, i10, this.f12633k.z() != null ? this.f12633k.z() : this.f12629g.getTheme());
    }

    private void u(String str) {
        Log.v("GlideRequest", str + " this: " + this.f12624b);
    }

    private static int v(int i10, float f10) {
        return i10 == Integer.MIN_VALUE ? i10 : Math.round(f10 * i10);
    }

    private void w() {
        d dVar = this.f12628f;
        if (dVar != null) {
            dVar.a(this);
        }
    }

    private void x() {
        d dVar = this.f12628f;
        if (dVar != null) {
            dVar.g(this);
        }
    }

    public static h y(Context context, com.bumptech.glide.d dVar, Object obj, Object obj2, Class cls, com.bumptech.glide.request.a aVar, int i10, int i11, com.bumptech.glide.g gVar, bi.h hVar, e eVar, List list, d dVar2, k kVar, ci.c cVar, Executor executor) {
        return new h(context, dVar, obj, obj2, cls, aVar, i10, i11, gVar, hVar, eVar, list, dVar2, kVar, cVar, executor);
    }

    private void z(q qVar, int i10) {
        boolean z10;
        this.f12625c.c();
        synchronized (this.f12626d) {
            qVar.k(this.D);
            int h10 = this.f12630h.h();
            if (h10 <= i10) {
                Log.w("Glide", "Load failed for [" + this.f12631i + "] with dimensions [" + this.A + "x" + this.B + "]", qVar);
                if (h10 <= 4) {
                    qVar.g("Glide");
                }
            }
            this.f12642t = null;
            this.f12645w = a.FAILED;
            w();
            boolean z11 = true;
            this.C = true;
            try {
                List list = this.f12638p;
                if (list != null) {
                    Iterator it = list.iterator();
                    z10 = false;
                    while (it.hasNext()) {
                        z10 |= ((e) it.next()).a(qVar, this.f12631i, this.f12637o, s());
                    }
                } else {
                    z10 = false;
                }
                e eVar = this.f12627e;
                if (eVar == null || !eVar.a(qVar, this.f12631i, this.f12637o, s())) {
                    z11 = false;
                }
                if (!(z10 | z11)) {
                    B();
                }
                this.C = false;
                fi.b.f("GlideRequest", this.f12623a);
            } catch (Throwable th2) {
                this.C = false;
                throw th2;
            }
        }
    }

    @Override // com.bumptech.glide.request.g
    public void a(v vVar, jh.a aVar, boolean z10) {
        this.f12625c.c();
        v vVar2 = null;
        try {
            synchronized (this.f12626d) {
                try {
                    this.f12642t = null;
                    if (vVar == null) {
                        c(new q("Expected to receive a Resource<R> with an object of " + this.f12632j + " inside, but instead got null."));
                        return;
                    }
                    Object obj = vVar.get();
                    try {
                        if (obj != null && this.f12632j.isAssignableFrom(obj.getClass())) {
                            if (m()) {
                                A(vVar, obj, aVar, z10);
                                return;
                            }
                            this.f12641s = null;
                            this.f12645w = a.COMPLETE;
                            fi.b.f("GlideRequest", this.f12623a);
                            this.f12644v.k(vVar);
                            return;
                        }
                        this.f12641s = null;
                        StringBuilder sb2 = new StringBuilder();
                        sb2.append("Expected to receive an object of ");
                        sb2.append(this.f12632j);
                        sb2.append(" but instead got ");
                        sb2.append(obj != null ? obj.getClass() : "");
                        sb2.append("{");
                        sb2.append(obj);
                        sb2.append("} inside Resource{");
                        sb2.append(vVar);
                        sb2.append("}.");
                        sb2.append(obj != null ? "" : " To indicate failure return a null Resource object, rather than a Resource object containing null data.");
                        c(new q(sb2.toString()));
                        this.f12644v.k(vVar);
                    } catch (Throwable th2) {
                        vVar2 = vVar;
                        th = th2;
                        throw th;
                    }
                } catch (Throwable th3) {
                    th = th3;
                }
            }
        } catch (Throwable th4) {
            if (vVar2 != null) {
                this.f12644v.k(vVar2);
            }
            throw th4;
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean b() {
        boolean z10;
        synchronized (this.f12626d) {
            z10 = this.f12645w == a.COMPLETE;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.g
    public void c(q qVar) {
        z(qVar, 5);
    }

    @Override // com.bumptech.glide.request.c
    public void clear() {
        synchronized (this.f12626d) {
            j();
            this.f12625c.c();
            a aVar = this.f12645w;
            a aVar2 = a.CLEARED;
            if (aVar == aVar2) {
                return;
            }
            n();
            v vVar = this.f12641s;
            if (vVar != null) {
                this.f12641s = null;
            } else {
                vVar = null;
            }
            if (k()) {
                this.f12637o.g(r());
            }
            fi.b.f("GlideRequest", this.f12623a);
            this.f12645w = aVar2;
            if (vVar != null) {
                this.f12644v.k(vVar);
            }
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean d(c cVar) {
        int i10;
        int i11;
        Object obj;
        Class cls;
        com.bumptech.glide.request.a aVar;
        com.bumptech.glide.g gVar;
        int size;
        int i12;
        int i13;
        Object obj2;
        Class cls2;
        com.bumptech.glide.request.a aVar2;
        com.bumptech.glide.g gVar2;
        int size2;
        if (!(cVar instanceof h)) {
            return false;
        }
        synchronized (this.f12626d) {
            i10 = this.f12634l;
            i11 = this.f12635m;
            obj = this.f12631i;
            cls = this.f12632j;
            aVar = this.f12633k;
            gVar = this.f12636n;
            List list = this.f12638p;
            size = list != null ? list.size() : 0;
        }
        h hVar = (h) cVar;
        synchronized (hVar.f12626d) {
            i12 = hVar.f12634l;
            i13 = hVar.f12635m;
            obj2 = hVar.f12631i;
            cls2 = hVar.f12632j;
            aVar2 = hVar.f12633k;
            gVar2 = hVar.f12636n;
            List list2 = hVar.f12638p;
            size2 = list2 != null ? list2.size() : 0;
        }
        return i10 == i12 && i11 == i13 && l.b(obj, obj2) && cls.equals(cls2) && aVar.equals(aVar2) && gVar == gVar2 && size == size2;
    }

    @Override // bi.g
    public void e(int i10, int i11) {
        this.f12625c.c();
        synchronized (this.f12626d) {
            try {
                try {
                    boolean z10 = E;
                    if (z10) {
                        u("Got onSizeReady in " + ei.g.a(this.f12643u));
                    }
                    if (this.f12645w != a.WAITING_FOR_SIZE) {
                        return;
                    }
                    a aVar = a.RUNNING;
                    this.f12645w = aVar;
                    float y10 = this.f12633k.y();
                    this.A = v(i10, y10);
                    this.B = v(i11, y10);
                    if (z10) {
                        u("finished setup for calling load in " + ei.g.a(this.f12643u));
                    }
                    this.f12642t = this.f12644v.f(this.f12630h, this.f12631i, this.f12633k.x(), this.A, this.B, this.f12633k.w(), this.f12632j, this.f12636n, this.f12633k.i(), this.f12633k.A(), this.f12633k.M(), this.f12633k.G(), this.f12633k.p(), this.f12633k.E(), this.f12633k.C(), this.f12633k.B(), this.f12633k.o(), this, this.f12640r);
                    if (this.f12645w != aVar) {
                        this.f12642t = null;
                    }
                    if (z10) {
                        u("finished onSizeReady in " + ei.g.a(this.f12643u));
                    }
                } catch (Throwable th2) {
                    th = th2;
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                throw th;
            }
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean f() {
        boolean z10;
        synchronized (this.f12626d) {
            z10 = this.f12645w == a.CLEARED;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.g
    public Object g() {
        this.f12625c.c();
        return this.f12626d;
    }

    @Override // com.bumptech.glide.request.c
    public void h() {
        synchronized (this.f12626d) {
            j();
            this.f12625c.c();
            this.f12643u = ei.g.b();
            Object obj = this.f12631i;
            if (obj == null) {
                if (l.s(this.f12634l, this.f12635m)) {
                    this.A = this.f12634l;
                    this.B = this.f12635m;
                }
                z(new q("Received null model"), q() == null ? 5 : 3);
                return;
            }
            a aVar = this.f12645w;
            a aVar2 = a.RUNNING;
            if (aVar == aVar2) {
                throw new IllegalArgumentException("Cannot restart a running request");
            }
            if (aVar == a.COMPLETE) {
                a(this.f12641s, jh.a.MEMORY_CACHE, false);
                return;
            }
            o(obj);
            this.f12623a = fi.b.b("GlideRequest");
            a aVar3 = a.WAITING_FOR_SIZE;
            this.f12645w = aVar3;
            if (l.s(this.f12634l, this.f12635m)) {
                e(this.f12634l, this.f12635m);
            } else {
                this.f12637o.c(this);
            }
            a aVar4 = this.f12645w;
            if ((aVar4 == aVar2 || aVar4 == aVar3) && l()) {
                this.f12637o.e(r());
            }
            if (E) {
                u("finished run method in " + ei.g.a(this.f12643u));
            }
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean i() {
        boolean z10;
        synchronized (this.f12626d) {
            z10 = this.f12645w == a.COMPLETE;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.c
    public boolean isRunning() {
        boolean z10;
        synchronized (this.f12626d) {
            a aVar = this.f12645w;
            z10 = aVar == a.RUNNING || aVar == a.WAITING_FOR_SIZE;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.c
    public void pause() {
        synchronized (this.f12626d) {
            if (isRunning()) {
                clear();
            }
        }
    }

    public String toString() {
        Object obj;
        Class cls;
        synchronized (this.f12626d) {
            obj = this.f12631i;
            cls = this.f12632j;
        }
        return super.toString() + "[model=" + obj + ", transcodeClass=" + cls + "]";
    }
}
