package defpackage;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.util.Log;
import com.bumptech.glide.b;
import com.bumptech.glide.d;
import defpackage.vl2;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

/* JADX INFO: loaded from: classes.dex */
public final class bv8<R> implements j08, zv8, f28 {
    public static final boolean aa = Log.isLoggable("GlideRequest", 2);
    public final o49 a;
    public final Object b;
    public final n08 c;
    public final Context d;
    public final d e;
    public final Object f;
    public final Class g;
    public final f80 h;
    public final int i;
    public final int j;
    public final di7 k;
    public final nj9 l;
    public final List m;
    public final gu9 n;
    public final Executor o;
    public b28 p;
    public vl2.d q;
    public volatile vl2 r;
    public a s;
    public Drawable t;
    public Drawable u;
    public Drawable v;
    public int w;
    public int x;
    public boolean y;
    public final RuntimeException z;

    /* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
    /* JADX WARN: Unknown enum class pattern. Please report as an issue! */
    public static final class a {
        public static final a a;
        public static final a b;
        public static final a c;
        public static final a d;
        public static final a e;
        public static final a f;
        public static final /* synthetic */ a[] i;

        static {
            a aVar = new a("PENDING", 0);
            a = aVar;
            a aVar2 = new a("RUNNING", 1);
            b = aVar2;
            a aVar3 = new a("WAITING_FOR_SIZE", 2);
            c = aVar3;
            a aVar4 = new a("COMPLETE", 3);
            d = aVar4;
            a aVar5 = new a("FAILED", 4);
            e = aVar5;
            a aVar6 = new a("CLEARED", 5);
            f = aVar6;
            i = new a[]{aVar, aVar2, aVar3, aVar4, aVar5, aVar6};
        }

        public static a valueOf(String str) {
            return (a) Enum.valueOf(a.class, str);
        }

        public static a[] values() {
            return (a[]) i.clone();
        }
    }

    public bv8(Context context, d dVar, Object obj, Object obj2, Class cls, f80 f80Var, int i, int i2, di7 di7Var, nj9 nj9Var, ArrayList arrayList, n08 n08Var, vl2 vl2Var, gu9 gu9Var) {
        Executor executor = xr2.a;
        if (aa) {
            String.valueOf(hashCode());
        }
        this.a = o49.a();
        this.b = obj;
        this.d = context;
        this.e = dVar;
        this.f = obj2;
        this.g = cls;
        this.h = f80Var;
        this.i = i;
        this.j = i2;
        this.k = di7Var;
        this.l = nj9Var;
        this.m = arrayList;
        this.c = n08Var;
        this.r = vl2Var;
        this.n = gu9Var;
        this.o = executor;
        this.s = a.a;
        if (this.z == null && dVar.h.a.containsKey(b.c.class)) {
            this.z = new RuntimeException("Glide request origin trace");
        }
    }

    @Override // defpackage.j08
    public final boolean a() {
        boolean z;
        synchronized (this.b) {
            z = this.s == a.d;
        }
        return z;
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // defpackage.zv8
    public final void b(int i, int i2) {
        Object obj;
        bv8<R> bv8Var = this;
        int iRound = i;
        bv8Var.a.b();
        Object obj2 = bv8Var.b;
        synchronized (obj2) {
            try {
                try {
                    boolean z = aa;
                    if (z) {
                        int i3 = zg5.a;
                        SystemClock.elapsedRealtimeNanos();
                    }
                    if (bv8Var.s == a.c) {
                        a aVar = a.b;
                        bv8Var.s = aVar;
                        float f = bv8Var.h.b;
                        if (iRound != Integer.MIN_VALUE) {
                            iRound = Math.round(iRound * f);
                        }
                        bv8Var.w = iRound;
                        bv8Var.x = i2 == Integer.MIN_VALUE ? i2 : Math.round(f * i2);
                        if (z) {
                            int i4 = zg5.a;
                            SystemClock.elapsedRealtimeNanos();
                        }
                        vl2 vl2Var = bv8Var.r;
                        try {
                            d dVar = bv8Var.e;
                            Object obj3 = bv8Var.f;
                            f80 f80Var = bv8Var.h;
                            try {
                                v25 v25Var = f80Var.n;
                                int i5 = bv8Var.w;
                                try {
                                    int i6 = bv8Var.x;
                                    Class cls = f80Var.r;
                                    try {
                                        Class cls2 = bv8Var.g;
                                        di7 di7Var = bv8Var.k;
                                        try {
                                            dc2 dc2Var = f80Var.c;
                                            cr0 cr0Var = f80Var.q;
                                            try {
                                                boolean z2 = f80Var.o;
                                                boolean z3 = f80Var.v;
                                                try {
                                                    my6 my6Var = f80Var.p;
                                                    boolean z4 = f80Var.k;
                                                    boolean z5 = f80Var.w;
                                                    Executor executor = bv8Var.o;
                                                    Object obj4 = obj2;
                                                    try {
                                                        bv8Var.q = vl2Var.d(dVar, obj3, v25Var, i5, i6, cls, cls2, di7Var, dc2Var, cr0Var, z2, z3, my6Var, z4, z5, bv8Var, executor);
                                                        if (bv8Var.s != aVar) {
                                                            bv8Var.q = null;
                                                        }
                                                        if (z) {
                                                            int i7 = zg5.a;
                                                            SystemClock.elapsedRealtimeNanos();
                                                        }
                                                    } catch (Throwable th) {
                                                        th = th;
                                                        obj = obj4;
                                                        throw th;
                                                    }
                                                } catch (Throwable th2) {
                                                    th = th2;
                                                    obj = obj2;
                                                }
                                            } catch (Throwable th3) {
                                                th = th3;
                                                obj = obj2;
                                            }
                                        } catch (Throwable th4) {
                                            th = th4;
                                            obj = obj2;
                                        }
                                    } catch (Throwable th5) {
                                        th = th5;
                                        obj = obj2;
                                    }
                                } catch (Throwable th6) {
                                    th = th6;
                                    obj = obj2;
                                }
                            } catch (Throwable th7) {
                                th = th7;
                                obj = obj2;
                            }
                        } catch (Throwable th8) {
                            th = th8;
                            obj = obj2;
                        }
                    }
                } catch (Throwable th9) {
                    th = th9;
                    obj = bv8Var;
                }
            } catch (Throwable th10) {
                th = th10;
                obj = obj2;
            }
        }
    }

    @Override // defpackage.j08
    public final boolean c() {
        boolean z;
        synchronized (this.b) {
            z = this.s == a.f;
        }
        return z;
    }

    @Override // defpackage.j08
    public final void clear() {
        synchronized (this.b) {
            try {
                if (this.y) {
                    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.");
                }
                this.a.b();
                a aVar = this.s;
                a aVar2 = a.f;
                if (aVar == aVar2) {
                    return;
                }
                if (this.y) {
                    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.");
                }
                this.a.b();
                this.l.a(this);
                vl2.d dVar = this.q;
                b28 b28Var = null;
                if (dVar != null) {
                    synchronized (vl2.this) {
                        dVar.a.g(dVar.b);
                    }
                    this.q = null;
                }
                b28 b28Var2 = this.p;
                if (b28Var2 != null) {
                    this.p = null;
                    b28Var = b28Var2;
                }
                n08 n08Var = this.c;
                if (n08Var == null || n08Var.b(this)) {
                    this.l.f(g());
                }
                this.s = aVar2;
                if (b28Var != null) {
                    this.r.getClass();
                    vl2.g(b28Var);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // defpackage.j08
    public final boolean d() {
        boolean z;
        synchronized (this.b) {
            z = this.s == a.d;
        }
        return z;
    }

    @Override // defpackage.j08
    public final boolean e(j08 j08Var) {
        int i;
        int i2;
        Object obj;
        Class cls;
        f80 f80Var;
        di7 di7Var;
        int size;
        int i3;
        int i4;
        Object obj2;
        Class cls2;
        f80 f80Var2;
        di7 di7Var2;
        int size2;
        if (!(j08Var instanceof bv8)) {
            return false;
        }
        synchronized (this.b) {
            try {
                i = this.i;
                i2 = this.j;
                obj = this.f;
                cls = this.g;
                f80Var = this.h;
                di7Var = this.k;
                List list = this.m;
                size = list != null ? list.size() : 0;
            } finally {
            }
        }
        bv8 bv8Var = (bv8) j08Var;
        synchronized (bv8Var.b) {
            try {
                i3 = bv8Var.i;
                i4 = bv8Var.j;
                obj2 = bv8Var.f;
                cls2 = bv8Var.g;
                f80Var2 = bv8Var.h;
                di7Var2 = bv8Var.k;
                List list2 = bv8Var.m;
                size2 = list2 != null ? list2.size() : 0;
            } finally {
            }
        }
        if (i != i3 || i2 != i4) {
            return false;
        }
        char[] cArr = hda.a;
        if ((obj == null ? obj2 == null : obj instanceof w76 ? ((w76) obj).a() : obj.equals(obj2)) && cls.equals(cls2)) {
            return (f80Var == null ? f80Var2 == null : f80Var.h(f80Var2)) && di7Var == di7Var2 && size == size2;
        }
        return false;
    }

    public final Object f() {
        this.a.b();
        return this.b;
    }

    public final Drawable g() {
        int i;
        if (this.u == null) {
            f80 f80Var = this.h;
            Drawable drawable = f80Var.i;
            this.u = drawable;
            if (drawable == null && (i = f80Var.j) > 0) {
                Resources.Theme theme = f80Var.t;
                Context context = this.d;
                if (theme == null) {
                    theme = context.getTheme();
                }
                this.u = lf2.a(context, context, i, theme);
            }
        }
        return this.u;
    }

    public final void h(jv3 jv3Var, int i) {
        boolean zJ;
        int i2;
        this.a.b();
        synchronized (this.b) {
            try {
                jv3Var.getClass();
                int i3 = this.e.i;
                if (i3 <= i) {
                    Log.w("Glide", "Load failed for [" + this.f + "] with dimensions [" + this.w + "x" + this.x + "]", jv3Var);
                    if (i3 <= 4) {
                        jv3Var.d();
                    }
                }
                Drawable drawableG = null;
                this.q = null;
                this.s = a.e;
                n08 n08Var = this.c;
                if (n08Var != null) {
                    n08Var.f(this);
                }
                boolean z = true;
                this.y = true;
                try {
                    List<z08> list = this.m;
                    if (list != null) {
                        zJ = false;
                        for (z08 z08Var : list) {
                            Object obj = this.f;
                            nj9 nj9Var = this.l;
                            n08 n08Var2 = this.c;
                            if (n08Var2 != null) {
                                n08Var2.getRoot().a();
                            }
                            zJ |= z08Var.j(jv3Var, obj, nj9Var);
                        }
                    } else {
                        zJ = false;
                    }
                    if (!zJ) {
                        n08 n08Var3 = this.c;
                        if (n08Var3 != null && !n08Var3.h(this)) {
                            z = false;
                        }
                        if (z) {
                            if (this.f == null) {
                                if (this.v == null) {
                                    this.h.getClass();
                                    this.v = null;
                                }
                                drawableG = this.v;
                            }
                            if (drawableG == null) {
                                if (this.t == null) {
                                    f80 f80Var = this.h;
                                    Drawable drawable = f80Var.e;
                                    this.t = drawable;
                                    if (drawable == null && (i2 = f80Var.f) > 0) {
                                        Context context = this.d;
                                        Resources.Theme theme = f80Var.t;
                                        if (theme == null) {
                                            theme = context.getTheme();
                                        }
                                        this.t = lf2.a(context, context, i2, theme);
                                    }
                                }
                                drawableG = this.t;
                            }
                            if (drawableG == null) {
                                drawableG = g();
                            }
                            this.l.i(drawableG);
                        }
                    }
                } finally {
                    this.y = false;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void i(b28 b28Var, zq1 zq1Var, boolean z) {
        this.a.b();
        b28 b28Var2 = null;
        try {
            synchronized (this.b) {
                try {
                    this.q = null;
                    if (b28Var == null) {
                        h(new jv3("Expected to receive a Resource<R> with an object of " + this.g + " inside, but instead got null."), 5);
                        return;
                    }
                    Object obj = b28Var.get();
                    try {
                        if (obj == null || !this.g.isAssignableFrom(obj.getClass())) {
                            this.p = null;
                            StringBuilder sb = new StringBuilder("Expected to receive an object of ");
                            sb.append(this.g);
                            sb.append(" but instead got ");
                            sb.append(obj != null ? obj.getClass() : "");
                            sb.append("{");
                            sb.append(obj);
                            sb.append("} inside Resource{");
                            sb.append(b28Var);
                            sb.append("}.");
                            sb.append(obj != null ? "" : " To indicate failure return a null Resource object, rather than a Resource object containing null data.");
                            h(new jv3(sb.toString()), 5);
                        } else {
                            n08 n08Var = this.c;
                            if (n08Var == null || n08Var.i(this)) {
                                k(b28Var, obj, zq1Var, z);
                                return;
                            } else {
                                this.p = null;
                                this.s = a.d;
                            }
                        }
                        this.r.getClass();
                        vl2.g(b28Var);
                    } catch (Throwable th) {
                        b28Var2 = b28Var;
                        th = th;
                        throw th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                }
            }
        } catch (Throwable th3) {
            if (b28Var2 != null) {
                this.r.getClass();
                vl2.g(b28Var2);
            }
            throw th3;
        }
    }

    @Override // defpackage.j08
    public final boolean isRunning() {
        boolean z;
        synchronized (this.b) {
            try {
                a aVar = this.s;
                z = aVar == a.b || aVar == a.c;
            } finally {
            }
        }
        return z;
    }

    @Override // defpackage.j08
    public final void j() {
        synchronized (this.b) {
            try {
                if (this.y) {
                    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.");
                }
                this.a.b();
                int i = zg5.a;
                SystemClock.elapsedRealtimeNanos();
                if (this.f == null) {
                    if (hda.j(this.i, this.j)) {
                        this.w = this.i;
                        this.x = this.j;
                    }
                    if (this.v == null) {
                        this.h.getClass();
                        this.v = null;
                    }
                    h(new jv3("Received null model"), this.v == null ? 5 : 3);
                    return;
                }
                a aVar = this.s;
                if (aVar == a.b) {
                    throw new IllegalArgumentException("Cannot restart a running request");
                }
                if (aVar == a.d) {
                    i(this.p, zq1.e, false);
                    return;
                }
                List<z08> list = this.m;
                if (list != null) {
                    for (z08 z08Var : list) {
                    }
                }
                a aVar2 = a.c;
                this.s = aVar2;
                if (hda.j(this.i, this.j)) {
                    b(this.i, this.j);
                } else {
                    this.l.g(this);
                }
                a aVar3 = this.s;
                if (aVar3 == a.b || aVar3 == aVar2) {
                    n08 n08Var = this.c;
                    if (n08Var == null || n08Var.h(this)) {
                        this.l.c(g());
                    }
                }
                if (aa) {
                    SystemClock.elapsedRealtimeNanos();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void k(b28 b28Var, Object obj, zq1 zq1Var, boolean z) {
        boolean zB;
        n08 n08Var = this.c;
        boolean z2 = n08Var == null || !n08Var.getRoot().a();
        this.s = a.d;
        this.p = b28Var;
        int i = this.e.i;
        Object obj2 = this.f;
        if (i <= 3) {
            Objects.toString(zq1Var);
            Objects.toString(obj2);
            int i2 = zg5.a;
            SystemClock.elapsedRealtimeNanos();
        }
        if (n08Var != null) {
            n08Var.g(this);
        }
        this.y = true;
        try {
            List<z08> list = this.m;
            if (list != null) {
                zB = false;
                for (z08 z08Var : list) {
                    zB |= z08Var.b(obj, obj2, zq1Var);
                    if (z08Var instanceof nt2) {
                        zB |= ((nt2) z08Var).a();
                    }
                }
            } else {
                zB = false;
            }
            if (!zB) {
                this.l.d(obj, this.n.a(zq1Var, z2));
            }
            this.y = false;
        } catch (Throwable th) {
            this.y = false;
            throw th;
        }
    }

    @Override // defpackage.j08
    public final void pause() {
        synchronized (this.b) {
            try {
                if (isRunning()) {
                    clear();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final String toString() {
        Object obj;
        Class cls;
        synchronized (this.b) {
            obj = this.f;
            cls = this.g;
        }
        return super.toString() + "[model=" + obj + ", transcodeClass=" + cls + "]";
    }
}
