From d1aacb5e116a94f70b7f5e4531ece93ab08a4cd4 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Wed, 18 Nov 2020 17:58:38 -0800 Subject: [PATCH] Add shortcut for starting an identical error request with a different model. PiperOrigin-RevId: 343195456 --- .../EmptyAppGlideModuleTest/GlideRequest.java | 7 ++++ .../MemoizeStaticMethod/GlideRequest.java | 7 ++++ .../OverrideExtend/GlideRequest.java | 7 ++++ .../GlideRequest.java | 7 ++++ .../OverrideReplace/GlideRequest.java | 7 ++++ .../SkipStaticMethod/GlideRequest.java | 7 ++++ .../StaticMethodName/GlideRequest.java | 7 ++++ .../GlideRequest.java | 7 ++++ .../com/bumptech/glide/RequestBuilder.java | 37 +++++++++++++++++++ 9 files changed, 93 insertions(+) diff --git a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java index f6b0062749..4dfbc05b4b 100644 --- a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java index 9c86b0097c..ecf5fa19c0 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java index 2c886219e6..7c77d801ea 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java @@ -475,6 +475,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java index 1d8c2cd55d..12f34f6506 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java @@ -475,6 +475,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java index 8daa6e164c..891a44ef46 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java @@ -475,6 +475,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java index 9c86b0097c..ecf5fa19c0 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java index 9c86b0097c..ecf5fa19c0 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java index 100a7f974b..2013c6f6cd 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest error(@Nullable RequestBuilder return (GlideRequest) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest error(Object o) { + return (GlideRequest) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/library/src/main/java/com/bumptech/glide/RequestBuilder.java b/library/src/main/java/com/bumptech/glide/RequestBuilder.java index 366478eb3a..880db65049 100644 --- a/library/src/main/java/com/bumptech/glide/RequestBuilder.java +++ b/library/src/main/java/com/bumptech/glide/RequestBuilder.java @@ -225,6 +225,43 @@ public RequestBuilder error(@Nullable RequestBuilderYou can only call this method on a {@code RequestBuilder} that has previously had {@code + * load()} called on it with a non-null model. . + * + *

Other than thumbnail and error {@code RequestBuilder}s, which are removed, all other options + * are retained from the primary request. However, order matters! Any options applied after + * this method is called will not be applied to the error {@code RequestBuilder}. We should move + */ + @NonNull + @CheckResult + public RequestBuilder error(Object model) { + if (model == null) { + return error((RequestBuilder) 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 cloneWithNullErrorAndThumbnail() { + return clone() + .error((RequestBuilder) null) + .thumbnail((RequestBuilder) 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