Skip to content

Commit

Permalink
Add shortcut for starting an identical error request with a different…
Browse files Browse the repository at this point in the history
… model.

PiperOrigin-RevId: 343195456
  • Loading branch information
sjudd authored and glide-copybara-robot committed Nov 19, 2020
1 parent b451065 commit d1aacb5
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType>
return (GlideRequest<TranscodeType>) super.error(builder);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> error(Object o) {
return (GlideRequest<TranscodeType>) super.error(o);
}

@Override
@NonNull
@CheckResult
Expand Down
37 changes: 37 additions & 0 deletions library/src/main/java/com/bumptech/glide/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,43 @@ public RequestBuilder<TranscodeType> error(@Nullable RequestBuilder<TranscodeTyp
return this;
}

/**
* Identical to calling {@link #error(RequestBuilder)} where the {@code RequestBuilder} is the
* result of calling {@link #clone()} and removing any existing thumbnail and error {@code
* RequestBuilders}
*
* <p>You can only call this method on a {@code RequestBuilder} that has previously had {@code
* load()} called on it with a non-null model. .
*
* <p>Other than thumbnail and error {@code RequestBuilder}s, which are removed, all other options
* are retained from the primary request. However, <b>order matters!</b> Any options applied after
* this method is called will not be applied to the error {@code RequestBuilder}. We should move
*/
@NonNull
@CheckResult
public RequestBuilder<TranscodeType> error(Object model) {
if (model == null) {
return error((RequestBuilder<TranscodeType>) null);
}
if (this.model == null) {
throw new IllegalArgumentException(
"Call this method after calling #load() with a non-null" + " model.");
}
if (!this.model.getClass().isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException(
"You can only call #error(Object) with the same type of"
+ " model that you provided to #load(). If you need to load a different type, use the"
+ " somewhat more verbose #error(RequestBuilder) method instead of this shortcut");
}
return error(cloneWithNullErrorAndThumbnail().load(model));
}

private RequestBuilder<TranscodeType> cloneWithNullErrorAndThumbnail() {
return clone()
.error((RequestBuilder<TranscodeType>) null)
.thumbnail((RequestBuilder<TranscodeType>) null);
}

/**
* Loads and displays the resource retrieved by the given thumbnail request if it finishes before
* this request. Best used for loading thumbnail resources that are smaller and will be loaded
Expand Down

0 comments on commit d1aacb5

Please sign in to comment.