File tree 2 files changed +9
-12
lines changed
lib/java/com/google/android/material
2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -266,10 +266,7 @@ public static ParcelableSparseArray createParcelableBadgeStates(
266
266
for (int i = 0 ; i < badgeDrawables .size (); i ++) {
267
267
int key = badgeDrawables .keyAt (i );
268
268
BadgeDrawable badgeDrawable = badgeDrawables .valueAt (i );
269
- if (badgeDrawable == null ) {
270
- throw new IllegalArgumentException ("badgeDrawable cannot be null" );
271
- }
272
- badgeStates .put (key , badgeDrawable .getSavedState ());
269
+ badgeStates .put (key , badgeDrawable != null ? badgeDrawable .getSavedState () : null );
273
270
}
274
271
return badgeStates ;
275
272
}
@@ -291,10 +288,10 @@ public static SparseArray<BadgeDrawable> createBadgeDrawablesFromSavedStates(
291
288
for (int i = 0 ; i < badgeStates .size (); i ++) {
292
289
int key = badgeStates .keyAt (i );
293
290
BadgeState .State savedState = (BadgeState .State ) badgeStates .valueAt (i );
294
- if (savedState == null ) {
295
- throw new IllegalArgumentException ("BadgeDrawable's savedState cannot be null" );
291
+ BadgeDrawable badgeDrawable = null ;
292
+ if (savedState != null ) {
293
+ badgeDrawable = BadgeDrawable .createFromSavedState (context , savedState );
296
294
}
297
- BadgeDrawable badgeDrawable = BadgeDrawable .createFromSavedState (context , savedState );
298
295
badgeDrawables .put (key , badgeDrawable );
299
296
}
300
297
return badgeDrawables ;
Original file line number Diff line number Diff line change @@ -869,7 +869,10 @@ void restoreBadgeDrawables(SparseArray<BadgeDrawable> badgeDrawables) {
869
869
}
870
870
if (buttons != null ) {
871
871
for (NavigationBarItemView itemView : buttons ) {
872
- itemView .setBadge (this .badgeDrawables .get (itemView .getId ()));
872
+ BadgeDrawable badge = this .badgeDrawables .get (itemView .getId ());
873
+ if (badge != null ) {
874
+ itemView .setBadge (badge );
875
+ }
873
876
}
874
877
}
875
878
}
@@ -903,14 +906,11 @@ BadgeDrawable getOrCreateBadge(int menuItemId) {
903
906
904
907
void removeBadge (int menuItemId ) {
905
908
validateMenuItemId (menuItemId );
906
- BadgeDrawable badgeDrawable = badgeDrawables .get (menuItemId );
907
909
NavigationBarItemView itemView = findItemView (menuItemId );
908
910
if (itemView != null ) {
909
911
itemView .removeBadge ();
910
912
}
911
- if (badgeDrawable != null ) {
912
- badgeDrawables .remove (menuItemId );
913
- }
913
+ badgeDrawables .put (menuItemId , null );
914
914
}
915
915
916
916
private void setBadgeIfNeeded (@ NonNull NavigationBarItemView child ) {
You can’t perform that action at this time.
0 commit comments