From 61ab0722efdb4a4106a0d64a64060fe3bd42a957 Mon Sep 17 00:00:00 2001 From: Hyuns66 Date: Mon, 9 Sep 2024 19:09:07 +0900 Subject: [PATCH] Fix: add resourceId existence checking method Previously, the existence of a resourceId was determined based on whether it was a positive number. However, since resourceId can also be negative, I improved this by checking the flag in the `fileds` variable to determine whether resourceId exists. --- .../glide/request/BaseRequestOptions.java | 15 +++++++++++++++ .../com/bumptech/glide/request/SingleRequest.java | 7 ++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java b/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java index 072bc63cc8..a3822e08fa 100644 --- a/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java +++ b/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java @@ -1363,11 +1363,21 @@ public final int getErrorId() { return errorId; } + @SuppressWarnings("WeakerAccess") + public final boolean hasErrorId() { + return isSet(ERROR_ID); + } + @SuppressWarnings("WeakerAccess") public final int getPlaceholderId() { return placeholderId; } + @SuppressWarnings("WeakerAccess") + public final boolean hasPlaceholderId() { + return isSet(PLACEHOLDER_ID); + } + @SuppressWarnings("WeakerAccess") @Nullable public final Drawable getPlaceholderDrawable() { @@ -1379,6 +1389,11 @@ public final int getFallbackId() { return fallbackId; } + @SuppressWarnings("WeakerAccess") + public final boolean hasFallbackId() { + return isSet(FALLBACK_ID); + } + @SuppressWarnings("WeakerAccess") @Nullable public final Drawable getFallbackDrawable() { diff --git a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java index 211936b20e..b658115a54 100644 --- a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java +++ b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java @@ -4,6 +4,7 @@ import android.content.res.Resources.Theme; import android.graphics.drawable.Drawable; import android.util.Log; + import androidx.annotation.DrawableRes; import androidx.annotation.GuardedBy; import androidx.annotation.NonNull; @@ -387,7 +388,7 @@ public boolean isAnyResourceSet() { private Drawable getErrorDrawable() { if (errorDrawable == null) { errorDrawable = requestOptions.getErrorPlaceholder(); - if (errorDrawable == null && requestOptions.getErrorId() > 0) { + if (errorDrawable == null && requestOptions.hasErrorId()) { errorDrawable = loadDrawable(requestOptions.getErrorId()); } } @@ -398,7 +399,7 @@ private Drawable getErrorDrawable() { private Drawable getPlaceholderDrawable() { if (placeholderDrawable == null) { placeholderDrawable = requestOptions.getPlaceholderDrawable(); - if (placeholderDrawable == null && requestOptions.getPlaceholderId() > 0) { + if (placeholderDrawable == null && requestOptions.hasPlaceholderId()) { placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId()); } } @@ -409,7 +410,7 @@ private Drawable getPlaceholderDrawable() { private Drawable getFallbackDrawable() { if (fallbackDrawable == null) { fallbackDrawable = requestOptions.getFallbackDrawable(); - if (fallbackDrawable == null && requestOptions.getFallbackId() > 0) { + if (fallbackDrawable == null && requestOptions.hasFallbackId()) { fallbackDrawable = loadDrawable(requestOptions.getFallbackId()); } }