File tree Expand file tree Collapse file tree 4 files changed +44
-8
lines changed
library/src/main/java/com/bumptech/glide Expand file tree Collapse file tree 4 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -359,15 +359,11 @@ public <Y extends Target<TranscodeType>> Y into(@NonNull Y target) {
359
359
Request request = buildRequest (target );
360
360
361
361
Request previous = target .getRequest ();
362
- // When request was failed or cancelled, be sure to use the updated model as it can contains
363
- // unexposed data that could help the request to succeed on restart.
364
- // See https://github.com/bumptech/glide/issues/2270
365
- if (request .isEquivalentTo (previous )
366
- && (Preconditions .checkNotNull (previous ).isComplete ()
367
- || Preconditions .checkNotNull (previous ).isRunning ())) {
362
+ if (request .isEquivalentTo (previous )) {
368
363
request .recycle ();
369
364
// If the request is completed, beginning again will ensure the result is re-delivered,
370
- // triggering RequestListeners and Targets. If the request is already
365
+ // triggering RequestListeners and Targets. If the request is failed, beginning again will
366
+ // restart the request, giving it another chance to complete. If the request is already
371
367
// running, we can let it continue running without interruption.
372
368
if (!Preconditions .checkNotNull (previous ).isRunning ()) {
373
369
previous .begin ();
Original file line number Diff line number Diff line change
1
+ package com .bumptech .glide .load .model ;
2
+
3
+ /**
4
+ * An optional interface that models can implement to enhance control over Glide behaviors.
5
+ */
6
+ public interface Model {
7
+
8
+ /**
9
+ * Returns {@code true} if this model produces the same image using the same mechanism
10
+ * (server, authentication, source etc) as the given model.
11
+ * <p>
12
+ * Models must also implement {@link #equals(Object other)} and {@link #hashCode()}
13
+ * to ensure that caching functions correctly.
14
+ * If this object returns {@code true} from this method for a given Model,
15
+ * it must also be equal to and have the same hash code as the given model.
16
+ * <p>
17
+ * However, this model may be equal to and have the same hash code as a given model
18
+ * but still return {@code false} from this method.
19
+ * This method optionally allows you to differentiate between Models that load the same image
20
+ * via multiple different means.
21
+ * For example one Model might load the image from server A and another model might load
22
+ * the same image from server B.
23
+ * The models must be equal to each other with the same hash code because they load
24
+ * the same image. However two requests made with the different models are not exactly the
25
+ * same because the way the image is loaded will differ.
26
+ */
27
+ boolean isEquivalentTo (Object other );
28
+ }
Original file line number Diff line number Diff line change @@ -578,7 +578,7 @@ public boolean isEquivalentTo(Request o) {
578
578
SingleRequest that = (SingleRequest ) o ;
579
579
return overrideWidth == that .overrideWidth
580
580
&& overrideHeight == that .overrideHeight
581
- && Util .bothNullOrEqual (model , that .model )
581
+ && Util .bothModelsNullEquivalentOrEquals (model , that .model )
582
582
&& transcodeClass .equals (that .transcodeClass )
583
583
&& requestOptions .equals (that .requestOptions )
584
584
&& priority == that .priority ;
Original file line number Diff line number Diff line change 4
4
import android .graphics .Bitmap ;
5
5
import android .os .Build ;
6
6
import android .os .Looper ;
7
+
8
+ import com .bumptech .glide .load .model .Model ;
7
9
import com .bumptech .glide .request .target .Target ;
8
10
import java .util .ArrayDeque ;
9
11
import java .util .ArrayList ;
@@ -190,6 +192,16 @@ public static boolean bothNullOrEqual(Object a, Object b) {
190
192
return a == null ? b == null : a .equals (b );
191
193
}
192
194
195
+ public static boolean bothModelsNullEquivalentOrEquals (Object a , Object b ) {
196
+ if (a == null ) {
197
+ return b == null ;
198
+ }
199
+ if (a instanceof Model ) {
200
+ return ((Model ) a ).isEquivalentTo (b );
201
+ }
202
+ return a .equals (b );
203
+ }
204
+
193
205
public static int hashCode (int value ) {
194
206
return hashCode (value , HASH_ACCUMULATOR );
195
207
}
You can’t perform that action at this time.
0 commit comments