jimu-decompiled/sources/com/bumptech/glide/load/model/MultiModelLoader.java
2025-05-13 19:24:51 +02:00

143 lines
4.7 KiB
Java

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<Model, Data> implements ModelLoader<Model, Data> {
private final List<ModelLoader<Model, Data>> a;
private final Pools$Pool<List<Throwable>> b;
MultiModelLoader(List<ModelLoader<Model, Data>> list, Pools$Pool<List<Throwable>> pools$Pool) {
this.a = list;
this.b = pools$Pool;
}
@Override // com.bumptech.glide.load.model.ModelLoader
public ModelLoader.LoadData<Data> a(Model model, int i, int i2, Options options) {
ModelLoader.LoadData<Data> a;
int size = this.a.size();
ArrayList arrayList = new ArrayList(size);
Key key = null;
for (int i3 = 0; i3 < size; i3++) {
ModelLoader<Model, Data> 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<Data> implements DataFetcher<Data>, DataFetcher.DataCallback<Data> {
private final List<DataFetcher<Data>> a;
private final Pools$Pool<List<Throwable>> b;
private int c;
private Priority d;
private DataFetcher.DataCallback<? super Data> e;
private List<Throwable> f;
MultiFetcher(List<DataFetcher<Data>> list, Pools$Pool<List<Throwable>> 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<? super Data> 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<Throwable> list = this.f;
if (list != null) {
this.b.a(list);
}
this.f = null;
Iterator<DataFetcher<Data>> it = this.a.iterator();
while (it.hasNext()) {
it.next().b();
}
}
@Override // com.bumptech.glide.load.data.DataFetcher
public void cancel() {
Iterator<DataFetcher<Data>> 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<Data> 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<? super Data>) data);
} else {
c();
}
}
@Override // com.bumptech.glide.load.data.DataFetcher.DataCallback
public void a(Exception exc) {
List<Throwable> list = this.f;
Preconditions.a(list);
list.add(exc);
c();
}
}
@Override // com.bumptech.glide.load.model.ModelLoader
public boolean a(Model model) {
Iterator<ModelLoader<Model, Data>> it = this.a.iterator();
while (it.hasNext()) {
if (it.next().a(model)) {
return true;
}
}
return false;
}
}