Skip to content

Commit 8a149b9

Browse files
committed
Add append methods for encoders and deprecate the register equivalents.
1 parent 01f5a3d commit 8a149b9

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

library/src/main/java/com/bumptech/glide/Registry.java

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,31 @@ public Registry() {
6767
*
6868
* <p>If multiple {@link Encoder}s are registered for the same type or super type, the
6969
* {@link Encoder} that is registered first will be used.
70+
*
71+
* @deprecated Use the equivalent {@link #append(Class, Class, ModelLoaderFactory)} method
72+
* instead.
7073
*/
74+
@Deprecated
7175
public <Data> Registry register(Class<Data> dataClass, Encoder<Data> encoder) {
76+
return append(dataClass, encoder);
77+
}
78+
79+
/**
80+
* Appends the given {@link Encoder} onto the list of available {@link Encoder}s so that it is
81+
* attempted after all earlier and default {@link Encoder}s for the given data class.
82+
*
83+
* <p>The {@link Encoder} will be used both for the exact data class and any subtypes. For
84+
* example, registering an {@link Encoder} for {@link java.io.InputStream} will result in the
85+
* {@link Encoder} being used for
86+
* {@link android.content.res.AssetFileDescriptor.AutoCloseInputStream},
87+
* {@link java.io.FileInputStream} and any other subclass.
88+
*
89+
* <p>If multiple {@link Encoder}s are registered for the same type or super type, the
90+
* {@link Encoder} that is registered first will be used.
91+
*
92+
* @see #prepend(Class, Encoder)
93+
*/
94+
public <Data> Registry append(Class<Data> dataClass, Encoder<Data> encoder) {
7295
encoderRegistry.append(dataClass, encoder);
7396
return this;
7497
}
@@ -81,6 +104,8 @@ public <Data> Registry register(Class<Data> dataClass, Encoder<Data> encoder) {
81104
* <p>This method allows you to replace the default {@link Encoder} because it ensures
82105
* the registered {@link Encoder} will run first. If multiple {@link Encoder}s are registered for
83106
* the same type or super type, the {@link Encoder} that is registered first will be used.
107+
*
108+
* @see #append(Class, Encoder)
84109
*/
85110
public <Data> Registry prepend(Class<Data> dataClass, Encoder<Data> encoder) {
86111
encoderRegistry.prepend(dataClass, encoder);
@@ -142,9 +167,9 @@ public <Data, TResource> Registry prepend(
142167
}
143168

144169
/**
145-
* Registers the given {@link ResourceEncoder} for the given resource class
146-
* ({@link android.graphics.Bitmap}, {@link com.bumptech.glide.load.resource.gif.GifDrawable}
147-
* etc).
170+
* Appends the given {@link ResourceEncoder} into the list of available {@link ResourceEncoder}s
171+
* so that it is attempted after all earlier and default {@link ResourceEncoder}s for the given
172+
* data type.
148173
*
149174
* <p>The {@link ResourceEncoder} will be used both for the exact resource class and any subtypes.
150175
* For example, registering an {@link ResourceEncoder} for
@@ -154,17 +179,38 @@ public <Data, TResource> Registry prepend(
154179
*
155180
* <p>If multiple {@link ResourceEncoder}s are registered for the same type or super type, the
156181
* {@link ResourceEncoder} that is registered first will be used.
182+
*
183+
* @deprecated Use the equivalent {@link #append(Class, ResourceEncoder)} method instead.
157184
*/
158-
public <TResource> Registry register(Class<TResource> resourceClass,
159-
ResourceEncoder<TResource> encoder) {
185+
@Deprecated
186+
public <TResource> Registry register(
187+
Class<TResource> resourceClass, ResourceEncoder<TResource> encoder) {
188+
return append(resourceClass, encoder);
189+
}
190+
191+
/**
192+
* Appends the given {@link ResourceEncoder} into the list of available {@link ResourceEncoder}s
193+
* so that it is attempted after all earlier and default {@link ResourceEncoder}s for the given
194+
* data type.
195+
*
196+
* <p>The {@link ResourceEncoder} will be used both for the exact resource class and any subtypes.
197+
* For example, registering an {@link ResourceEncoder} for
198+
* {@link android.graphics.drawable.Drawable} (not recommended) will result in the
199+
* {@link ResourceEncoder} being used for {@link android.graphics.drawable.BitmapDrawable} and
200+
* {@link com.bumptech.glide.load.resource.gif.GifDrawable} and any other subclass.
201+
*
202+
* <p>If multiple {@link ResourceEncoder}s are registered for the same type or super type, the
203+
* {@link ResourceEncoder} that is registered first will be used.
204+
*
205+
* @see #prepend(Class, ResourceEncoder)
206+
*/
207+
public <TResource> Registry append(
208+
Class<TResource> resourceClass, ResourceEncoder<TResource> encoder) {
160209
resourceEncoderRegistry.append(resourceClass, encoder);
161210
return this;
162211
}
163212

164213
/**
165-
* Registers a new {@link com.bumptech.glide.load.data.DataRewinder.Factory} to handle a
166-
* non-default data type that can be rewind to allow for efficient reads of file headers.
167-
*
168214
* Prepends the given {@link ResourceEncoder} into the list of available {@link ResourceEncoder}s
169215
* so that it is attempted before all later and default {@link ResourceEncoder}s for the given
170216
* data type.
@@ -173,9 +219,11 @@ public <TResource> Registry register(Class<TResource> resourceClass,
173219
* the registered {@link ResourceEncoder} will run first. If multiple {@link ResourceEncoder}s are
174220
* registered for the same type or super type, the {@link ResourceEncoder} that is registered
175221
* first will be used.
222+
*
223+
* @see #append(Class, ResourceEncoder)
176224
*/
177-
public <TResource> Registry prepend(Class<TResource> resourceClass,
178-
ResourceEncoder<TResource> encoder) {
225+
public <TResource> Registry prepend(
226+
Class<TResource> resourceClass, ResourceEncoder<TResource> encoder) {
179227
resourceEncoderRegistry.prepend(resourceClass, encoder);
180228
return this;
181229
}

0 commit comments

Comments
 (0)