1717import android .widget .Toast ;
1818
1919import androidx .annotation .NonNull ;
20+ import androidx .annotation .Nullable ;
2021import androidx .appcompat .app .AlertDialog ;
2122import androidx .appcompat .content .res .AppCompatResources ;
2223import androidx .core .graphics .drawable .DrawableCompat ;
@@ -41,9 +42,8 @@ public NotificationActionsPreference(final Context context, final AttributeSet a
4142 }
4243
4344
44- private NotificationSlot [] notificationSlots ;
45-
46- private List <Integer > compactSlots ;
45+ @ Nullable private NotificationSlot [] notificationSlots = null ;
46+ @ Nullable private List <Integer > compactSlots = null ;
4747
4848 ////////////////////////////////////////////////////////////////////////////
4949 // Lifecycle
@@ -85,19 +85,22 @@ private void setupActions(@NonNull final View view) {
8585 ////////////////////////////////////////////////////////////////////////////
8686
8787 private void saveChanges () {
88- final SharedPreferences .Editor editor = getSharedPreferences ().edit ();
88+ if (compactSlots != null && notificationSlots != null ) {
89+ final SharedPreferences .Editor editor = getSharedPreferences ().edit ();
8990
90- for (int i = 0 ; i < 3 ; i ++) {
91- editor .putInt (getContext ().getString (NotificationConstants .SLOT_COMPACT_PREF_KEYS [i ]),
92- (i < compactSlots .size () ? compactSlots .get (i ) : -1 ));
93- }
91+ for (int i = 0 ; i < 3 ; i ++) {
92+ editor .putInt (getContext ().getString (
93+ NotificationConstants .SLOT_COMPACT_PREF_KEYS [i ]),
94+ (i < compactSlots .size () ? compactSlots .get (i ) : -1 ));
95+ }
9496
95- for (int i = 0 ; i < 5 ; i ++) {
96- editor .putInt (getContext ().getString (NotificationConstants .SLOT_PREF_KEYS [i ]),
97- notificationSlots [i ].selectedAction );
98- }
97+ for (int i = 0 ; i < 5 ; i ++) {
98+ editor .putInt (getContext ().getString (NotificationConstants .SLOT_PREF_KEYS [i ]),
99+ notificationSlots [i ].selectedAction );
100+ }
99101
100- editor .apply ();
102+ editor .apply ();
103+ }
101104 }
102105
103106
0 commit comments