File tree Expand file tree Collapse file tree 2 files changed +9
-12
lines changed
lib/java/com/google/android/material Expand file tree Collapse file tree 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(
266266 for (int i = 0 ; i < badgeDrawables .size (); i ++) {
267267 int key = badgeDrawables .keyAt (i );
268268 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 );
273270 }
274271 return badgeStates ;
275272 }
@@ -291,10 +288,10 @@ public static SparseArray<BadgeDrawable> createBadgeDrawablesFromSavedStates(
291288 for (int i = 0 ; i < badgeStates .size (); i ++) {
292289 int key = badgeStates .keyAt (i );
293290 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 );
296294 }
297- BadgeDrawable badgeDrawable = BadgeDrawable .createFromSavedState (context , savedState );
298295 badgeDrawables .put (key , badgeDrawable );
299296 }
300297 return badgeDrawables ;
Original file line number Diff line number Diff line change @@ -869,7 +869,10 @@ void restoreBadgeDrawables(SparseArray<BadgeDrawable> badgeDrawables) {
869869 }
870870 if (buttons != null ) {
871871 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+ }
873876 }
874877 }
875878 }
@@ -903,14 +906,11 @@ BadgeDrawable getOrCreateBadge(int menuItemId) {
903906
904907 void removeBadge (int menuItemId ) {
905908 validateMenuItemId (menuItemId );
906- BadgeDrawable badgeDrawable = badgeDrawables .get (menuItemId );
907909 NavigationBarItemView itemView = findItemView (menuItemId );
908910 if (itemView != null ) {
909911 itemView .removeBadge ();
910912 }
911- if (badgeDrawable != null ) {
912- badgeDrawables .remove (menuItemId );
913- }
913+ badgeDrawables .put (menuItemId , null );
914914 }
915915
916916 private void setBadgeIfNeeded (@ NonNull NavigationBarItemView child ) {
You can’t perform that action at this time.
0 commit comments