package g5;

import androidx.annotation.Nullable;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public final class f0 implements com.bumptech.glide.load.data.e, com.bumptech.glide.load.data.d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final List f26177a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final p0.e f26178b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Priority f26180d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public com.bumptech.glide.load.data.d f26181e;

    @Nullable
    private List<Throwable> exceptions;

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

    public f0(ArrayList arrayList, p0.e eVar) {
        this.f26178b = eVar;
        if (arrayList.isEmpty()) {
            throw new IllegalArgumentException("Must not be empty.");
        }
        this.f26177a = arrayList;
        this.f26179c = 0;
    }

    @Override // com.bumptech.glide.load.data.e
    public final Class a() {
        return ((com.bumptech.glide.load.data.e) this.f26177a.get(0)).a();
    }

    @Override // com.bumptech.glide.load.data.e
    public final void b() {
        List<Throwable> list = this.exceptions;
        if (list != null) {
            this.f26178b.a(list);
        }
        this.exceptions = null;
        Iterator it = this.f26177a.iterator();
        while (it.hasNext()) {
            ((com.bumptech.glide.load.data.e) it.next()).b();
        }
    }

    @Override // com.bumptech.glide.load.data.d
    public final void c(Exception exc) {
        ((List) t5.n.checkNotNull(this.exceptions)).add(exc);
        f();
    }

    @Override // com.bumptech.glide.load.data.e
    public final void cancel() {
        this.f26182f = true;
        Iterator it = this.f26177a.iterator();
        while (it.hasNext()) {
            ((com.bumptech.glide.load.data.e) it.next()).cancel();
        }
    }

    @Override // com.bumptech.glide.load.data.e
    public final DataSource d() {
        return ((com.bumptech.glide.load.data.e) this.f26177a.get(0)).d();
    }

    @Override // com.bumptech.glide.load.data.e
    public final void e(Priority priority, com.bumptech.glide.load.data.d dVar) {
        this.f26180d = priority;
        this.f26181e = dVar;
        this.exceptions = (List) this.f26178b.acquire();
        ((com.bumptech.glide.load.data.e) this.f26177a.get(this.f26179c)).e(priority, this);
        if (this.f26182f) {
            cancel();
        }
    }

    public final void f() {
        if (this.f26182f) {
            return;
        }
        if (this.f26179c < this.f26177a.size() - 1) {
            this.f26179c++;
            e(this.f26180d, this.f26181e);
        } else {
            t5.n.checkNotNull(this.exceptions);
            this.f26181e.c(new GlideException("Fetch failed", new ArrayList(this.exceptions)));
        }
    }

    @Override // com.bumptech.glide.load.data.d
    public void onDataReady(@Nullable Object obj) {
        if (obj != null) {
            this.f26181e.onDataReady(obj);
        } else {
            f();
        }
    }
}
