image-loader change mediaDecoders configuration logic
This commit is contained in:
parent
11d80786d4
commit
a77a973e8d
@ -12,7 +12,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -87,8 +86,6 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
|||||||
// image bounds (but we will need to cache inputStream in order to inspect and optimize
|
// image bounds (but we will need to cache inputStream in order to inspect and optimize
|
||||||
// input image...)
|
// input image...)
|
||||||
|
|
||||||
// todo, if not a link -> show placeholder
|
|
||||||
|
|
||||||
return executorService.submit(new Runnable() {
|
return executorService.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -190,18 +187,30 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
|||||||
// for this module (without implementations), but keep _all-in_ (fat) artifact with all of these.
|
// for this module (without implementations), but keep _all-in_ (fat) artifact with all of these.
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 2.0.0 add {@link NetworkSchemeHandler} directly
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
private OkHttpClient client;
|
private OkHttpClient client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 2.0.0 construct {@link MediaDecoder} and {@link SchemeHandler} appropriately
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
private Resources resources;
|
private Resources resources;
|
||||||
|
|
||||||
private ExecutorService executorService;
|
private ExecutorService executorService;
|
||||||
private Drawable errorDrawable;
|
private Drawable errorDrawable;
|
||||||
|
|
||||||
// @since 2.0.0
|
|
||||||
private final Map<String, SchemeHandler> schemeHandlers = new HashMap<>(3);
|
|
||||||
|
|
||||||
// @since 1.1.0
|
// @since 1.1.0
|
||||||
private final List<MediaDecoder> mediaDecoders = new ArrayList<>(3);
|
private final List<MediaDecoder> mediaDecoders = new ArrayList<>(3);
|
||||||
|
|
||||||
|
// @since 2.0.0
|
||||||
|
private final Map<String, SchemeHandler> schemeHandlers = new HashMap<>(3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 2.0.0 add {@link NetworkSchemeHandler} directly
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Builder client(@NonNull OkHttpClient client) {
|
public Builder client(@NonNull OkHttpClient client) {
|
||||||
@ -236,6 +245,7 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
|||||||
/**
|
/**
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder addSchemeHandler(@NonNull SchemeHandler schemeHandler) {
|
public Builder addSchemeHandler(@NonNull SchemeHandler schemeHandler) {
|
||||||
|
|
||||||
@ -252,20 +262,97 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #addMediaDecoder(MediaDecoder)
|
||||||
|
* @see #addMediaDecoders(MediaDecoder...)
|
||||||
|
* @see #addMediaDecoders(Iterable)
|
||||||
|
* @since 1.1.0
|
||||||
|
* @deprecated 2.0.0
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder mediaDecoders(@NonNull List<MediaDecoder> mediaDecoders) {
|
public Builder mediaDecoders(@NonNull List<MediaDecoder> mediaDecoders) {
|
||||||
this.mediaDecoders.clear();
|
|
||||||
this.mediaDecoders.addAll(mediaDecoders);
|
// previously it was clearing before adding
|
||||||
|
|
||||||
|
for (MediaDecoder mediaDecoder : mediaDecoders) {
|
||||||
|
this.mediaDecoders.add(requireNonNull(mediaDecoder));
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #addMediaDecoder(MediaDecoder)
|
||||||
|
* @see #addMediaDecoders(MediaDecoder...)
|
||||||
|
* @see #addMediaDecoders(Iterable)
|
||||||
|
* @since 1.1.0
|
||||||
|
* @deprecated 2.0.0
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@Deprecated
|
||||||
public Builder mediaDecoders(MediaDecoder... mediaDecoders) {
|
public Builder mediaDecoders(MediaDecoder... mediaDecoders) {
|
||||||
this.mediaDecoders.clear();
|
|
||||||
if (mediaDecoders != null
|
// previously it was clearing before adding
|
||||||
&& mediaDecoders.length > 0) {
|
|
||||||
Collections.addAll(this.mediaDecoders, mediaDecoders);
|
final int length = mediaDecoders != null
|
||||||
|
? mediaDecoders.length
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
if (length > 0) {
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
this.mediaDecoders.add(requireNonNull(mediaDecoders[i]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SvgMediaDecoder
|
||||||
|
* @see GifMediaDecoder
|
||||||
|
* @see ImageMediaDecoder
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public Builder addMediaDecoder(@NonNull MediaDecoder mediaDecoder) {
|
||||||
|
mediaDecoders.add(mediaDecoder);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SvgMediaDecoder
|
||||||
|
* @see GifMediaDecoder
|
||||||
|
* @see ImageMediaDecoder
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public Builder addMediaDecoders(@NonNull Iterable<MediaDecoder> mediaDecoders) {
|
||||||
|
for (MediaDecoder mediaDecoder : mediaDecoders) {
|
||||||
|
this.mediaDecoders.add(requireNonNull(mediaDecoder));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SvgMediaDecoder
|
||||||
|
* @see GifMediaDecoder
|
||||||
|
* @see ImageMediaDecoder
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public Builder addMediaDecoders(MediaDecoder... mediaDecoders) {
|
||||||
|
|
||||||
|
final int length = mediaDecoders != null
|
||||||
|
? mediaDecoders.length
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
if (length > 0) {
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
this.mediaDecoders.add(requireNonNull(mediaDecoders[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,11 +365,14 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (executorService == null) {
|
if (executorService == null) {
|
||||||
|
// @since 2.0.0 we are using newCachedThreadPool instead
|
||||||
|
// of `okHttpClient.dispatcher().executorService()`
|
||||||
executorService = Executors.newCachedThreadPool();
|
executorService = Executors.newCachedThreadPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @since 2.0.0
|
// @since 2.0.0
|
||||||
// put default scheme handlers (to mimic previous behavior)
|
// put default scheme handlers (to mimic previous behavior)
|
||||||
|
// remove in 3.0.0 with plugins
|
||||||
if (schemeHandlers.size() == 0) {
|
if (schemeHandlers.size() == 0) {
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
client = new OkHttpClient();
|
client = new OkHttpClient();
|
||||||
@ -293,6 +383,7 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add default media decoders if not specified
|
// add default media decoders if not specified
|
||||||
|
// remove in 3.0.0 with plugins
|
||||||
if (mediaDecoders.size() == 0) {
|
if (mediaDecoders.size() == 0) {
|
||||||
mediaDecoders.add(SvgMediaDecoder.create(resources));
|
mediaDecoders.add(SvgMediaDecoder.create(resources));
|
||||||
mediaDecoders.add(GifMediaDecoder.create(true));
|
mediaDecoders.add(GifMediaDecoder.create(true));
|
||||||
@ -302,4 +393,13 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
|||||||
return new AsyncDrawableLoader(this);
|
return new AsyncDrawableLoader(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @since 2.0.0
|
||||||
|
@NonNull
|
||||||
|
private static <T> T requireNonNull(@Nullable T t) {
|
||||||
|
if (t == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user