Initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.bumptech.glide.integration.okhttp3;
|
||||
|
||||
import android.content.Context;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.GlideBuilder;
|
||||
import com.bumptech.glide.Registry;
|
||||
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
import com.bumptech.glide.module.GlideModule;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Deprecated
|
||||
/* loaded from: classes.dex */
|
||||
public class OkHttpGlideModule implements GlideModule {
|
||||
@Override // com.bumptech.glide.module.GlideModule
|
||||
public void applyOptions(Context context, GlideBuilder glideBuilder) {
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.module.GlideModule
|
||||
public void registerComponents(Context context, Glide glide, Registry registry) {
|
||||
registry.b(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
package com.bumptech.glide.integration.okhttp3;
|
||||
|
||||
import android.util.Log;
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.HttpException;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
import com.bumptech.glide.util.ContentLengthInputStream;
|
||||
import com.bumptech.glide.util.Preconditions;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class OkHttpStreamFetcher implements DataFetcher<InputStream>, Callback {
|
||||
private final Call.Factory a;
|
||||
private final GlideUrl b;
|
||||
private InputStream c;
|
||||
private ResponseBody d;
|
||||
private DataFetcher.DataCallback<? super InputStream> e;
|
||||
private volatile Call f;
|
||||
|
||||
public OkHttpStreamFetcher(Call.Factory factory, GlideUrl glideUrl) {
|
||||
this.a = factory;
|
||||
this.b = glideUrl;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.data.DataFetcher
|
||||
public void a(Priority priority, DataFetcher.DataCallback<? super InputStream> dataCallback) {
|
||||
Request.Builder url = new Request.Builder().url(this.b.c());
|
||||
for (Map.Entry<String, String> entry : this.b.b().entrySet()) {
|
||||
url.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
Request build = url.build();
|
||||
this.e = dataCallback;
|
||||
this.f = this.a.newCall(build);
|
||||
this.f.enqueue(this);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.data.DataFetcher
|
||||
public void b() {
|
||||
try {
|
||||
if (this.c != null) {
|
||||
this.c.close();
|
||||
}
|
||||
} catch (IOException unused) {
|
||||
}
|
||||
ResponseBody responseBody = this.d;
|
||||
if (responseBody != null) {
|
||||
responseBody.close();
|
||||
}
|
||||
this.e = null;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.data.DataFetcher
|
||||
public void cancel() {
|
||||
Call call = this.f;
|
||||
if (call != null) {
|
||||
call.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.data.DataFetcher
|
||||
public DataSource getDataSource() {
|
||||
return DataSource.REMOTE;
|
||||
}
|
||||
|
||||
@Override // okhttp3.Callback
|
||||
public void onFailure(Call call, IOException iOException) {
|
||||
if (Log.isLoggable("OkHttpFetcher", 3)) {
|
||||
Log.d("OkHttpFetcher", "OkHttp failed to obtain result", iOException);
|
||||
}
|
||||
this.e.a((Exception) iOException);
|
||||
}
|
||||
|
||||
@Override // okhttp3.Callback
|
||||
public void onResponse(Call call, Response response) {
|
||||
this.d = response.body();
|
||||
if (!response.isSuccessful()) {
|
||||
this.e.a((Exception) new HttpException(response.message(), response.code()));
|
||||
return;
|
||||
}
|
||||
ResponseBody responseBody = this.d;
|
||||
Preconditions.a(responseBody);
|
||||
this.c = ContentLengthInputStream.a(this.d.byteStream(), responseBody.contentLength());
|
||||
this.e.a((DataFetcher.DataCallback<? super InputStream>) this.c);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.data.DataFetcher
|
||||
public Class<InputStream> a() {
|
||||
return InputStream.class;
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
package com.bumptech.glide.integration.okhttp3;
|
||||
|
||||
import com.bumptech.glide.load.Options;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
import com.bumptech.glide.load.model.ModelLoader;
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||
import com.bumptech.glide.load.model.MultiModelLoaderFactory;
|
||||
import java.io.InputStream;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class OkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
|
||||
private final Call.Factory a;
|
||||
|
||||
public static class Factory implements ModelLoaderFactory<GlideUrl, InputStream> {
|
||||
private static volatile Call.Factory b;
|
||||
private final Call.Factory a;
|
||||
|
||||
public Factory() {
|
||||
this(b());
|
||||
}
|
||||
|
||||
private static Call.Factory b() {
|
||||
if (b == null) {
|
||||
synchronized (Factory.class) {
|
||||
if (b == null) {
|
||||
b = new OkHttpClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.model.ModelLoaderFactory
|
||||
public ModelLoader<GlideUrl, InputStream> a(MultiModelLoaderFactory multiModelLoaderFactory) {
|
||||
return new OkHttpUrlLoader(this.a);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.model.ModelLoaderFactory
|
||||
public void a() {
|
||||
}
|
||||
|
||||
public Factory(Call.Factory factory) {
|
||||
this.a = factory;
|
||||
}
|
||||
}
|
||||
|
||||
public OkHttpUrlLoader(Call.Factory factory) {
|
||||
this.a = factory;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.model.ModelLoader
|
||||
public boolean a(GlideUrl glideUrl) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.model.ModelLoader
|
||||
public ModelLoader.LoadData<InputStream> a(GlideUrl glideUrl, int i, int i2, Options options) {
|
||||
return new ModelLoader.LoadData<>(glideUrl, new OkHttpStreamFetcher(this.a, glideUrl));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user