Skip to content

Commit

Permalink
Merge pull request #4352 from dlew:dlew/deduplicate-http-uri-loaders
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 333128445
  • Loading branch information
glide-copybara-robot committed Sep 22, 2020
2 parents a3a3a65 + 8ab09c1 commit 50ebdbf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 47 deletions.
2 changes: 0 additions & 2 deletions library/src/main/java/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import com.bumptech.glide.load.model.UriLoader;
import com.bumptech.glide.load.model.UrlUriLoader;
import com.bumptech.glide.load.model.stream.HttpGlideUrlLoader;
import com.bumptech.glide.load.model.stream.HttpUriLoader;
import com.bumptech.glide.load.model.stream.MediaStoreImageThumbLoader;
import com.bumptech.glide.load.model.stream.MediaStoreVideoThumbLoader;
import com.bumptech.glide.load.model.stream.QMediaStoreUriLoader;
Expand Down Expand Up @@ -540,7 +539,6 @@ Uri.class, Bitmap.class, new ResourceBitmapDecoder(resourceDrawableDecoder, bitm
.append(String.class, ParcelFileDescriptor.class, new StringLoader.FileDescriptorFactory())
.append(
String.class, AssetFileDescriptor.class, new StringLoader.AssetFileDescriptorFactory())
.append(Uri.class, InputStream.class, new HttpUriLoader.Factory())
.append(Uri.class, InputStream.class, new AssetUriLoader.StreamFactory(context.getAssets()))
.append(
Uri.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
package com.bumptech.glide.load.model.stream;

import android.net.Uri;
import androidx.annotation.NonNull;
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 com.bumptech.glide.load.model.UrlUriLoader;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/** Loads {@link InputStream}s from http or https {@link Uri}s. */
public class HttpUriLoader implements ModelLoader<Uri, InputStream> {
private static final Set<String> SCHEMES =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("http", "https")));

private final ModelLoader<GlideUrl, InputStream> urlLoader;
/**
* Loads {@link InputStream}s from http or https {@link Uri}s.
*
* @deprecated Use {@link UrlUriLoader} instead
*/
@Deprecated
public class HttpUriLoader extends UrlUriLoader<InputStream> {

// Public API.
@SuppressWarnings("WeakerAccess")
public HttpUriLoader(ModelLoader<GlideUrl, InputStream> urlLoader) {
this.urlLoader = urlLoader;
}

@Override
public LoadData<InputStream> buildLoadData(
@NonNull Uri model, int width, int height, @NonNull Options options) {
return urlLoader.buildLoadData(new GlideUrl(model.toString()), width, height, options);
super(urlLoader);
}

@Override
public boolean handles(@NonNull Uri model) {
return SCHEMES.contains(model.getScheme());
}

/** Factory for loading {@link InputStream}s from http/https {@link Uri}s. */
public static class Factory implements ModelLoaderFactory<Uri, InputStream> {

@NonNull
@Override
public ModelLoader<Uri, InputStream> build(MultiModelLoaderFactory multiFactory) {
return new HttpUriLoader(multiFactory.build(GlideUrl.class, InputStream.class));
}

@Override
public void teardown() {
// Do nothing.
}
/**
* Factory for loading {@link InputStream}s from http/https {@link Uri}s.
*
* @deprecated Use {@link UrlUriLoader.StreamFactory} instead
*/
@Deprecated
public static class Factory extends StreamFactory {
// Defer to StreamFactory's implementation
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.bumptech.glide.load.model.stream;
package com.bumptech.glide.load.model;

import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;

import android.net.Uri;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.ModelLoader;
import java.io.InputStream;
import java.net.MalformedURLException;
import org.junit.Before;
Expand All @@ -20,18 +18,18 @@

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
public class HttpUriLoaderTest {
public class UrlUriLoaderTest {
private static final int IMAGE_SIDE = 100;
private static final Options OPTIONS = new Options();

@Mock private ModelLoader<GlideUrl, InputStream> urlLoader;
private HttpUriLoader loader;
private UrlUriLoader<InputStream> loader;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);

loader = new HttpUriLoader(urlLoader);
loader = new UrlUriLoader<>(urlLoader);
}

@Test
Expand Down

0 comments on commit 50ebdbf

Please sign in to comment.