package com.bumptech.glide.load.model; import androidx.core.util.Pools$Pool; import com.bumptech.glide.Priority; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.util.Preconditions; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; /* loaded from: classes.dex */ class MultiModelLoader implements ModelLoader { private final List> a; private final Pools$Pool> b; MultiModelLoader(List> list, Pools$Pool> pools$Pool) { this.a = list; this.b = pools$Pool; } @Override // com.bumptech.glide.load.model.ModelLoader public ModelLoader.LoadData a(Model model, int i, int i2, Options options) { ModelLoader.LoadData a; int size = this.a.size(); ArrayList arrayList = new ArrayList(size); Key key = null; for (int i3 = 0; i3 < size; i3++) { ModelLoader modelLoader = this.a.get(i3); if (modelLoader.a(model) && (a = modelLoader.a(model, i, i2, options)) != null) { key = a.a; arrayList.add(a.c); } } if (arrayList.isEmpty() || key == null) { return null; } return new ModelLoader.LoadData<>(key, new MultiFetcher(arrayList, this.b)); } public String toString() { return "MultiModelLoader{modelLoaders=" + Arrays.toString(this.a.toArray()) + '}'; } static class MultiFetcher implements DataFetcher, DataFetcher.DataCallback { private final List> a; private final Pools$Pool> b; private int c; private Priority d; private DataFetcher.DataCallback e; private List f; MultiFetcher(List> list, Pools$Pool> pools$Pool) { this.b = pools$Pool; Preconditions.a(list); this.a = list; this.c = 0; } private void c() { if (this.c < this.a.size() - 1) { this.c++; a(this.d, this.e); } else { Preconditions.a(this.f); this.e.a((Exception) new GlideException("Fetch failed", new ArrayList(this.f))); } } @Override // com.bumptech.glide.load.data.DataFetcher public void a(Priority priority, DataFetcher.DataCallback dataCallback) { this.d = priority; this.e = dataCallback; this.f = this.b.a(); this.a.get(this.c).a(priority, this); } @Override // com.bumptech.glide.load.data.DataFetcher public void b() { List list = this.f; if (list != null) { this.b.a(list); } this.f = null; Iterator> it = this.a.iterator(); while (it.hasNext()) { it.next().b(); } } @Override // com.bumptech.glide.load.data.DataFetcher public void cancel() { Iterator> it = this.a.iterator(); while (it.hasNext()) { it.next().cancel(); } } @Override // com.bumptech.glide.load.data.DataFetcher public DataSource getDataSource() { return this.a.get(0).getDataSource(); } @Override // com.bumptech.glide.load.data.DataFetcher public Class a() { return this.a.get(0).a(); } @Override // com.bumptech.glide.load.data.DataFetcher.DataCallback public void a(Data data) { if (data != null) { this.e.a((DataFetcher.DataCallback) data); } else { c(); } } @Override // com.bumptech.glide.load.data.DataFetcher.DataCallback public void a(Exception exc) { List list = this.f; Preconditions.a(list); list.add(exc); c(); } } @Override // com.bumptech.glide.load.model.ModelLoader public boolean a(Model model) { Iterator> it = this.a.iterator(); while (it.hasNext()) { if (it.next().a(model)) { return true; } } return false; } }