Skip to content

Commit 5f23a12

Browse files
committed
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.
1 parent a7351b0 commit 5f23a12

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java

+15
Original file line numberDiff line numberDiff line change
@@ -1363,11 +1363,21 @@ public final int getErrorId() {
13631363
return errorId;
13641364
}
13651365

1366+
@SuppressWarnings("WeakerAccess")
1367+
public final boolean hasErrorId() {
1368+
return isSet(ERROR_ID);
1369+
}
1370+
13661371
@SuppressWarnings("WeakerAccess")
13671372
public final int getPlaceholderId() {
13681373
return placeholderId;
13691374
}
13701375

1376+
@SuppressWarnings("WeakerAccess")
1377+
public final boolean hasPlaceholderId() {
1378+
return isSet(PLACEHOLDER_ID);
1379+
}
1380+
13711381
@SuppressWarnings("WeakerAccess")
13721382
@Nullable
13731383
public final Drawable getPlaceholderDrawable() {
@@ -1379,6 +1389,11 @@ public final int getFallbackId() {
13791389
return fallbackId;
13801390
}
13811391

1392+
@SuppressWarnings("WeakerAccess")
1393+
public final boolean hasFallbackId() {
1394+
return isSet(FALLBACK_ID);
1395+
}
1396+
13821397
@SuppressWarnings("WeakerAccess")
13831398
@Nullable
13841399
public final Drawable getFallbackDrawable() {

library/src/main/java/com/bumptech/glide/request/SingleRequest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public boolean isAnyResourceSet() {
387387
private Drawable getErrorDrawable() {
388388
if (errorDrawable == null) {
389389
errorDrawable = requestOptions.getErrorPlaceholder();
390-
if (errorDrawable == null && requestOptions.getErrorId() > 0) {
390+
if (errorDrawable == null && requestOptions.hasErrorId()) {
391391
errorDrawable = loadDrawable(requestOptions.getErrorId());
392392
}
393393
}
@@ -398,7 +398,7 @@ private Drawable getErrorDrawable() {
398398
private Drawable getPlaceholderDrawable() {
399399
if (placeholderDrawable == null) {
400400
placeholderDrawable = requestOptions.getPlaceholderDrawable();
401-
if (placeholderDrawable == null && requestOptions.getPlaceholderId() > 0) {
401+
if (placeholderDrawable == null && requestOptions.hasPlaceholderId()) {
402402
placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId());
403403
}
404404
}
@@ -409,7 +409,7 @@ private Drawable getPlaceholderDrawable() {
409409
private Drawable getFallbackDrawable() {
410410
if (fallbackDrawable == null) {
411411
fallbackDrawable = requestOptions.getFallbackDrawable();
412-
if (fallbackDrawable == null && requestOptions.getFallbackId() > 0) {
412+
if (fallbackDrawable == null && requestOptions.hasFallbackId()) {
413413
fallbackDrawable = loadDrawable(requestOptions.getFallbackId());
414414
}
415415
}

0 commit comments

Comments
 (0)