Skip to content

Commit

Permalink
Fix: add resourceId existence checking method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hyuns66 committed Sep 27, 2024
1 parent a7351b0 commit 61ab072
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand All @@ -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());
}
}
Expand All @@ -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());
}
}
Expand Down

0 comments on commit 61ab072

Please sign in to comment.