-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4352 from dlew:dlew/deduplicate-http-uri-loaders
PiperOrigin-RevId: 333128445
- Loading branch information
Showing
3 changed files
with
21 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 17 additions & 39 deletions
56
library/src/main/java/com/bumptech/glide/load/model/stream/HttpUriLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters