461 lines
15 KiB
Java
461 lines
15 KiB
Java
package com.bumptech.glide.request;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.util.Log;
|
|
import androidx.core.util.Pools$Pool;
|
|
import com.bumptech.glide.GlideContext;
|
|
import com.bumptech.glide.Priority;
|
|
import com.bumptech.glide.load.DataSource;
|
|
import com.bumptech.glide.load.engine.Engine;
|
|
import com.bumptech.glide.load.engine.GlideException;
|
|
import com.bumptech.glide.load.engine.Resource;
|
|
import com.bumptech.glide.load.resource.drawable.DrawableDecoderCompat;
|
|
import com.bumptech.glide.request.target.SizeReadyCallback;
|
|
import com.bumptech.glide.request.target.Target;
|
|
import com.bumptech.glide.request.transition.TransitionFactory;
|
|
import com.bumptech.glide.util.LogTime;
|
|
import com.bumptech.glide.util.Util;
|
|
import com.bumptech.glide.util.pool.FactoryPools;
|
|
import com.bumptech.glide.util.pool.StateVerifier;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class SingleRequest<R> implements Request, SizeReadyCallback, ResourceCallback, FactoryPools.Poolable {
|
|
private static final Pools$Pool<SingleRequest<?>> B = FactoryPools.a(150, new FactoryPools.Factory<SingleRequest<?>>() { // from class: com.bumptech.glide.request.SingleRequest.1
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // com.bumptech.glide.util.pool.FactoryPools.Factory
|
|
public SingleRequest<?> a() {
|
|
return new SingleRequest<>();
|
|
}
|
|
});
|
|
private static final boolean C = Log.isLoggable("Request", 2);
|
|
private int A;
|
|
private boolean a;
|
|
private final String b;
|
|
private final StateVerifier c;
|
|
private RequestListener<R> d;
|
|
private RequestCoordinator e;
|
|
private Context f;
|
|
private GlideContext g;
|
|
private Object h;
|
|
private Class<R> i;
|
|
private RequestOptions j;
|
|
private int k;
|
|
private int l;
|
|
private Priority m;
|
|
private Target<R> n;
|
|
private RequestListener<R> o;
|
|
private Engine p;
|
|
private TransitionFactory<? super R> q;
|
|
private Resource<R> r;
|
|
private Engine.LoadStatus s;
|
|
private long t;
|
|
private Status u;
|
|
private Drawable v;
|
|
private Drawable x;
|
|
private Drawable y;
|
|
private int z;
|
|
|
|
private enum Status {
|
|
PENDING,
|
|
RUNNING,
|
|
WAITING_FOR_SIZE,
|
|
COMPLETE,
|
|
FAILED,
|
|
CANCELLED,
|
|
CLEARED,
|
|
PAUSED
|
|
}
|
|
|
|
SingleRequest() {
|
|
this.b = C ? String.valueOf(super.hashCode()) : null;
|
|
this.c = StateVerifier.b();
|
|
}
|
|
|
|
private void a(Context context, GlideContext glideContext, Object obj, Class<R> cls, RequestOptions requestOptions, int i, int i2, Priority priority, Target<R> target, RequestListener<R> requestListener, RequestListener<R> requestListener2, RequestCoordinator requestCoordinator, Engine engine, TransitionFactory<? super R> transitionFactory) {
|
|
this.f = context;
|
|
this.g = glideContext;
|
|
this.h = obj;
|
|
this.i = cls;
|
|
this.j = requestOptions;
|
|
this.k = i;
|
|
this.l = i2;
|
|
this.m = priority;
|
|
this.n = target;
|
|
this.d = requestListener;
|
|
this.o = requestListener2;
|
|
this.e = requestCoordinator;
|
|
this.p = engine;
|
|
this.q = transitionFactory;
|
|
this.u = Status.PENDING;
|
|
}
|
|
|
|
public static <R> SingleRequest<R> b(Context context, GlideContext glideContext, Object obj, Class<R> cls, RequestOptions requestOptions, int i, int i2, Priority priority, Target<R> target, RequestListener<R> requestListener, RequestListener<R> requestListener2, RequestCoordinator requestCoordinator, Engine engine, TransitionFactory<? super R> transitionFactory) {
|
|
SingleRequest<R> singleRequest = (SingleRequest) B.a();
|
|
if (singleRequest == null) {
|
|
singleRequest = new SingleRequest<>();
|
|
}
|
|
singleRequest.a(context, glideContext, obj, cls, requestOptions, i, i2, priority, target, requestListener, requestListener2, requestCoordinator, engine, transitionFactory);
|
|
return singleRequest;
|
|
}
|
|
|
|
private void h() {
|
|
if (this.a) {
|
|
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.");
|
|
}
|
|
}
|
|
|
|
private boolean i() {
|
|
RequestCoordinator requestCoordinator = this.e;
|
|
return requestCoordinator == null || requestCoordinator.f(this);
|
|
}
|
|
|
|
private boolean j() {
|
|
RequestCoordinator requestCoordinator = this.e;
|
|
return requestCoordinator == null || requestCoordinator.c(this);
|
|
}
|
|
|
|
private boolean k() {
|
|
RequestCoordinator requestCoordinator = this.e;
|
|
return requestCoordinator == null || requestCoordinator.d(this);
|
|
}
|
|
|
|
private Drawable l() {
|
|
if (this.v == null) {
|
|
this.v = this.j.l();
|
|
if (this.v == null && this.j.k() > 0) {
|
|
this.v = a(this.j.k());
|
|
}
|
|
}
|
|
return this.v;
|
|
}
|
|
|
|
private Drawable m() {
|
|
if (this.y == null) {
|
|
this.y = this.j.m();
|
|
if (this.y == null && this.j.n() > 0) {
|
|
this.y = a(this.j.n());
|
|
}
|
|
}
|
|
return this.y;
|
|
}
|
|
|
|
private Drawable n() {
|
|
if (this.x == null) {
|
|
this.x = this.j.s();
|
|
if (this.x == null && this.j.t() > 0) {
|
|
this.x = a(this.j.t());
|
|
}
|
|
}
|
|
return this.x;
|
|
}
|
|
|
|
private boolean o() {
|
|
RequestCoordinator requestCoordinator = this.e;
|
|
return requestCoordinator == null || !requestCoordinator.c();
|
|
}
|
|
|
|
private void p() {
|
|
RequestCoordinator requestCoordinator = this.e;
|
|
if (requestCoordinator != null) {
|
|
requestCoordinator.b(this);
|
|
}
|
|
}
|
|
|
|
private void q() {
|
|
RequestCoordinator requestCoordinator = this.e;
|
|
if (requestCoordinator != null) {
|
|
requestCoordinator.e(this);
|
|
}
|
|
}
|
|
|
|
private void r() {
|
|
if (j()) {
|
|
Drawable m = this.h == null ? m() : null;
|
|
if (m == null) {
|
|
m = l();
|
|
}
|
|
if (m == null) {
|
|
m = n();
|
|
}
|
|
this.n.a(m);
|
|
}
|
|
}
|
|
|
|
@Override // com.bumptech.glide.util.pool.FactoryPools.Poolable
|
|
public StateVerifier c() {
|
|
return this.c;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public void clear() {
|
|
Util.b();
|
|
h();
|
|
this.c.a();
|
|
if (this.u == Status.CLEARED) {
|
|
return;
|
|
}
|
|
f();
|
|
Resource<R> resource = this.r;
|
|
if (resource != null) {
|
|
a((Resource<?>) resource);
|
|
}
|
|
if (i()) {
|
|
this.n.c(n());
|
|
}
|
|
this.u = Status.CLEARED;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public boolean d() {
|
|
return this.u == Status.FAILED;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public void e() {
|
|
h();
|
|
this.c.a();
|
|
this.t = LogTime.a();
|
|
if (this.h == null) {
|
|
if (Util.b(this.k, this.l)) {
|
|
this.z = this.k;
|
|
this.A = this.l;
|
|
}
|
|
a(new GlideException("Received null model"), m() == null ? 5 : 3);
|
|
return;
|
|
}
|
|
Status status = this.u;
|
|
if (status == Status.RUNNING) {
|
|
throw new IllegalArgumentException("Cannot restart a running request");
|
|
}
|
|
if (status == Status.COMPLETE) {
|
|
a((Resource<?>) this.r, DataSource.MEMORY_CACHE);
|
|
return;
|
|
}
|
|
this.u = Status.WAITING_FOR_SIZE;
|
|
if (Util.b(this.k, this.l)) {
|
|
a(this.k, this.l);
|
|
} else {
|
|
this.n.b(this);
|
|
}
|
|
Status status2 = this.u;
|
|
if ((status2 == Status.RUNNING || status2 == Status.WAITING_FOR_SIZE) && j()) {
|
|
this.n.b(n());
|
|
}
|
|
if (C) {
|
|
a("finished run method in " + LogTime.a(this.t));
|
|
}
|
|
}
|
|
|
|
void f() {
|
|
h();
|
|
this.c.a();
|
|
this.n.a((SizeReadyCallback) this);
|
|
this.u = Status.CANCELLED;
|
|
Engine.LoadStatus loadStatus = this.s;
|
|
if (loadStatus != null) {
|
|
loadStatus.a();
|
|
this.s = null;
|
|
}
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public boolean g() {
|
|
return this.u == Status.COMPLETE;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public boolean isCancelled() {
|
|
Status status = this.u;
|
|
return status == Status.CANCELLED || status == Status.CLEARED;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public boolean isRunning() {
|
|
Status status = this.u;
|
|
return status == Status.RUNNING || status == Status.WAITING_FOR_SIZE;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public void pause() {
|
|
clear();
|
|
this.u = Status.PAUSED;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public boolean b() {
|
|
return g();
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public void a() {
|
|
h();
|
|
this.f = null;
|
|
this.g = null;
|
|
this.h = null;
|
|
this.i = null;
|
|
this.j = null;
|
|
this.k = -1;
|
|
this.l = -1;
|
|
this.n = null;
|
|
this.o = null;
|
|
this.d = null;
|
|
this.e = null;
|
|
this.q = null;
|
|
this.s = null;
|
|
this.v = null;
|
|
this.x = null;
|
|
this.y = null;
|
|
this.z = -1;
|
|
this.A = -1;
|
|
B.a(this);
|
|
}
|
|
|
|
private void a(Resource<?> resource) {
|
|
this.p.b(resource);
|
|
this.r = null;
|
|
}
|
|
|
|
private Drawable a(int i) {
|
|
return DrawableDecoderCompat.a(this.g, i, this.j.y() != null ? this.j.y() : this.f.getTheme());
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.target.SizeReadyCallback
|
|
public void a(int i, int i2) {
|
|
this.c.a();
|
|
if (C) {
|
|
a("Got onSizeReady in " + LogTime.a(this.t));
|
|
}
|
|
if (this.u != Status.WAITING_FOR_SIZE) {
|
|
return;
|
|
}
|
|
this.u = Status.RUNNING;
|
|
float x = this.j.x();
|
|
this.z = a(i, x);
|
|
this.A = a(i2, x);
|
|
if (C) {
|
|
a("finished setup for calling load in " + LogTime.a(this.t));
|
|
}
|
|
this.s = this.p.a(this.g, this.h, this.j.w(), this.z, this.A, this.j.v(), this.i, this.m, this.j.j(), this.j.z(), this.j.G(), this.j.E(), this.j.p(), this.j.C(), this.j.B(), this.j.A(), this.j.o(), this);
|
|
if (this.u != Status.RUNNING) {
|
|
this.s = null;
|
|
}
|
|
if (C) {
|
|
a("finished onSizeReady in " + LogTime.a(this.t));
|
|
}
|
|
}
|
|
|
|
private static int a(int i, float f) {
|
|
return i == Integer.MIN_VALUE ? i : Math.round(f * i);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.bumptech.glide.request.ResourceCallback
|
|
public void a(Resource<?> resource, DataSource dataSource) {
|
|
this.c.a();
|
|
this.s = null;
|
|
if (resource == null) {
|
|
a(new GlideException("Expected to receive a Resource<R> with an object of " + this.i + " inside, but instead got null."));
|
|
return;
|
|
}
|
|
Object obj = resource.get();
|
|
if (obj != null && this.i.isAssignableFrom(obj.getClass())) {
|
|
if (!k()) {
|
|
a(resource);
|
|
this.u = Status.COMPLETE;
|
|
return;
|
|
} else {
|
|
a(resource, obj, dataSource);
|
|
return;
|
|
}
|
|
}
|
|
a(resource);
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Expected to receive an object of ");
|
|
sb.append(this.i);
|
|
sb.append(" but instead got ");
|
|
sb.append(obj != null ? obj.getClass() : "");
|
|
sb.append("{");
|
|
sb.append(obj);
|
|
sb.append("} inside Resource{");
|
|
sb.append(resource);
|
|
sb.append("}.");
|
|
sb.append(obj == null ? " To indicate failure return a null Resource object, rather than a Resource object containing null data." : "");
|
|
a(new GlideException(sb.toString()));
|
|
}
|
|
|
|
private void a(Resource<R> resource, R r, DataSource dataSource) {
|
|
boolean o = o();
|
|
this.u = Status.COMPLETE;
|
|
this.r = resource;
|
|
if (this.g.d() <= 3) {
|
|
Log.d("Glide", "Finished loading " + r.getClass().getSimpleName() + " from " + dataSource + " for " + this.h + " with size [" + this.z + "x" + this.A + "] in " + LogTime.a(this.t) + " ms");
|
|
}
|
|
this.a = true;
|
|
try {
|
|
if ((this.o == null || !this.o.a(r, this.h, this.n, dataSource, o)) && (this.d == null || !this.d.a(r, this.h, this.n, dataSource, o))) {
|
|
this.n.a(r, this.q.a(dataSource, o));
|
|
}
|
|
this.a = false;
|
|
q();
|
|
} catch (Throwable th) {
|
|
this.a = false;
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.ResourceCallback
|
|
public void a(GlideException glideException) {
|
|
a(glideException, 5);
|
|
}
|
|
|
|
private void a(GlideException glideException, int i) {
|
|
this.c.a();
|
|
int d = this.g.d();
|
|
if (d <= i) {
|
|
Log.w("Glide", "Load failed for " + this.h + " with size [" + this.z + "x" + this.A + "]", glideException);
|
|
if (d <= 4) {
|
|
glideException.logRootCauses("Glide");
|
|
}
|
|
}
|
|
this.s = null;
|
|
this.u = Status.FAILED;
|
|
this.a = true;
|
|
try {
|
|
if ((this.o == null || !this.o.a(glideException, this.h, this.n, o())) && (this.d == null || !this.d.a(glideException, this.h, this.n, o()))) {
|
|
r();
|
|
}
|
|
this.a = false;
|
|
p();
|
|
} catch (Throwable th) {
|
|
this.a = false;
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.Request
|
|
public boolean a(Request request) {
|
|
if (!(request instanceof SingleRequest)) {
|
|
return false;
|
|
}
|
|
SingleRequest singleRequest = (SingleRequest) request;
|
|
if (this.k != singleRequest.k || this.l != singleRequest.l || !Util.a(this.h, singleRequest.h) || !this.i.equals(singleRequest.i) || !this.j.equals(singleRequest.j) || this.m != singleRequest.m) {
|
|
return false;
|
|
}
|
|
RequestListener<R> requestListener = this.o;
|
|
RequestListener<R> requestListener2 = singleRequest.o;
|
|
if (requestListener != null) {
|
|
if (requestListener2 == null) {
|
|
return false;
|
|
}
|
|
} else if (requestListener2 != null) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void a(String str) {
|
|
Log.v("Request", str + " this: " + this.b);
|
|
}
|
|
}
|