That fuck shit the fascists are using
at master 78 lines 2.4 kB view raw
1package org.tm.archive.glide; 2 3import androidx.annotation.NonNull; 4import androidx.annotation.Nullable; 5 6import com.bumptech.glide.load.Options; 7import com.bumptech.glide.load.model.GlideUrl; 8import com.bumptech.glide.load.model.ModelLoader; 9import com.bumptech.glide.load.model.ModelLoaderFactory; 10import com.bumptech.glide.load.model.MultiModelLoaderFactory; 11 12import org.tm.archive.net.ContentProxySelector; 13import org.tm.archive.net.StandardUserAgentInterceptor; 14import org.tm.archive.push.SignalServiceNetworkAccess; 15 16import java.io.InputStream; 17 18import okhttp3.OkHttpClient; 19 20/** 21 * A simple model loader for fetching media over http/https using OkHttp. 22 */ 23public class OkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> { 24 25 private final OkHttpClient client; 26 27 private OkHttpUrlLoader(OkHttpClient client) { 28 this.client = client; 29 } 30 31 @Override 32 public @Nullable LoadData<InputStream> buildLoadData(@NonNull GlideUrl glideUrl, int width, int height, @NonNull Options options) { 33 return new LoadData<>(glideUrl, new OkHttpStreamFetcher(client, glideUrl)); 34 } 35 36 @Override 37 public boolean handles(@NonNull GlideUrl glideUrl) { 38 return true; 39 } 40 41 public static class Factory implements ModelLoaderFactory<GlideUrl, InputStream> { 42 private static volatile OkHttpClient internalClient; 43 private OkHttpClient client; 44 45 private static OkHttpClient getInternalClient() { 46 if (internalClient == null) { 47 synchronized (Factory.class) { 48 if (internalClient == null) { 49 internalClient = new OkHttpClient.Builder() 50 .proxySelector(new ContentProxySelector()) 51 .addInterceptor(new StandardUserAgentInterceptor()) 52 .dns(SignalServiceNetworkAccess.DNS) 53 .build(); 54 } 55 } 56 } 57 return internalClient; 58 } 59 60 public Factory() { 61 this(getInternalClient()); 62 } 63 64 private Factory(OkHttpClient client) { 65 this.client = client; 66 } 67 68 @Override 69 public @NonNull ModelLoader<GlideUrl, InputStream> build(@NonNull MultiModelLoaderFactory multiFactory) { 70 return new OkHttpUrlLoader(client); 71 } 72 73 @Override 74 public void teardown() { 75 // Do nothing, this instance doesn't own the client. 76 } 77 } 78}