Skip to content

Commit 71f0a71

Browse files
wcshildjcmu
authored andcommitted
s/StringRes/PluralsRes
Add null check before trying to use the PluralsRes containing savedState.contentDescriptionQuantityStrings PiperOrigin-RevId: 246203433
1 parent 808e92c commit 71f0a71

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/java/com/google/android/material/badge/BadgeDrawable.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import androidx.annotation.ColorInt;
3939
import androidx.annotation.NonNull;
4040
import androidx.annotation.Nullable;
41+
import androidx.annotation.PluralsRes;
4142
import androidx.annotation.StringRes;
4243
import androidx.annotation.StyleRes;
4344
import androidx.annotation.StyleableRes;
@@ -133,7 +134,7 @@ public static final class SavedState implements Parcelable {
133134
private int number = BADGE_NUMBER_NONE;
134135
private int maxCharacterCount;
135136
private CharSequence contentDescriptionNumberless;
136-
@StringRes private int contentDescriptionQuantityStrings;
137+
@PluralsRes private int contentDescriptionQuantityStrings;
137138

138139
public SavedState(Context context) {
139140
// If the badge text color attribute was not explicitly set, use the text color specified in
@@ -497,10 +498,14 @@ public CharSequence getContentDescription(Context context) {
497498
return null;
498499
}
499500
if (hasNumber()) {
500-
return context
501-
.getResources()
502-
.getQuantityString(
503-
savedState.contentDescriptionQuantityStrings, getNumber(), getNumber());
501+
if (savedState.contentDescriptionQuantityStrings > 0) {
502+
return context
503+
.getResources()
504+
.getQuantityString(
505+
savedState.contentDescriptionQuantityStrings, getNumber(), getNumber());
506+
} else {
507+
return null;
508+
}
504509
} else {
505510
return savedState.contentDescriptionNumberless;
506511
}

0 commit comments

Comments
 (0)