package c.f.e; import c.f.d.d.i; import com.airbnb.lottie.parser.AnimatableValueParser; import com.facebook.common.internal.Supplier; import com.facebook.datasource.DataSource; import java.util.List; import java.util.Objects; /* compiled from: FirstAvailableDataSourceSupplier */ public class g implements Supplier> { public final List>> a; /* compiled from: FirstAvailableDataSourceSupplier */ public class b extends c { public int h = 0; public DataSource i = null; public DataSource j = null; /* compiled from: FirstAvailableDataSourceSupplier */ public class a implements f { public a(a aVar) { } @Override // c.f.e.f public void onCancellation(DataSource dataSource) { } @Override // c.f.e.f public void onFailure(DataSource dataSource) { b.o(b.this, dataSource); } /* JADX WARNING: Removed duplicated region for block: B:17:0x0029 */ @Override // c.f.e.f public void onNewResult(DataSource dataSource) { if (dataSource.b()) { b bVar = b.this; Objects.requireNonNull(bVar); c cVar = (c) dataSource; boolean c2 = cVar.c(); synchronized (bVar) { if (dataSource == bVar.i) { DataSource dataSource2 = bVar.j; if (dataSource != dataSource2) { if (dataSource2 != null) { if (!c2) { dataSource2 = null; if (dataSource2 != null) { dataSource2.close(); } } } bVar.j = dataSource; if (dataSource2 != null) { } } } } if (dataSource == bVar.p()) { bVar.m(null, cVar.c(), cVar.a); } } else if (((c) dataSource).c()) { b.o(b.this, dataSource); } } @Override // c.f.e.f public void onProgressUpdate(DataSource dataSource) { b.this.l(Math.max(b.this.getProgress(), ((c) dataSource).getProgress())); } } public b() { if (!q()) { k(new RuntimeException("No data source supplier or supplier returned null."), null); } } public static void o(b bVar, DataSource dataSource) { boolean z2; synchronized (bVar) { if (!bVar.i()) { if (dataSource == bVar.i) { bVar.i = null; z2 = true; } } z2 = false; } if (z2) { if (!(dataSource == bVar.p() || dataSource == null)) { dataSource.close(); } if (!bVar.q()) { bVar.k(dataSource.d(), dataSource.a()); } } } @Override // c.f.e.c, com.facebook.datasource.DataSource public synchronized boolean b() { DataSource p; p = p(); return p != null && p.b(); } @Override // c.f.e.c, com.facebook.datasource.DataSource public boolean close() { DataSource dataSource; DataSource dataSource2; synchronized (this) { if (!super.close()) { return false; } dataSource = this.i; this.i = null; dataSource2 = this.j; this.j = null; } if (dataSource2 != null) { dataSource2.close(); } if (dataSource == null) { return true; } dataSource.close(); return true; } @Override // c.f.e.c, com.facebook.datasource.DataSource public synchronized T getResult() { DataSource p; p = p(); return p != null ? p.getResult() : null; } public final synchronized DataSource p() { return this.j; } public final boolean q() { Supplier> supplier; boolean z2; synchronized (this) { if (i() || this.h >= g.this.a.size()) { supplier = null; } else { List>> list = g.this.a; int i = this.h; this.h = i + 1; supplier = list.get(i); } } DataSource dataSource = supplier != null ? supplier.get() : null; synchronized (this) { if (i()) { z2 = false; } else { this.i = dataSource; z2 = true; } } if (!z2 || dataSource == null) { if (dataSource != null) { dataSource.close(); } return false; } dataSource.f(new a(null), c.f.d.b.a.i); return true; } } public g(List>> list) { AnimatableValueParser.l(!list.isEmpty(), "List of suppliers is empty!"); this.a = list; } public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof g)) { return false; } return AnimatableValueParser.i0(this.a, ((g) obj).a); } @Override // com.facebook.common.internal.Supplier public Object get() { return new b(); } public int hashCode() { return this.a.hashCode(); } public String toString() { i F2 = AnimatableValueParser.F2(this); F2.c("list", this.a); return F2.toString(); } }