Fix random NullPointerException in NotificationActionsPreference

pull/5944/head
Stypox 2021-03-28 22:31:03 +02:00
rodzic 3e8cba745a
commit 5d6a568308
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4BDF1B40A49FDD23
1 zmienionych plików z 17 dodań i 14 usunięć

Wyświetl plik

@ -17,6 +17,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.DrawableCompat;
@ -41,9 +42,8 @@ public class NotificationActionsPreference extends Preference {
} }
private NotificationSlot[] notificationSlots; @Nullable private NotificationSlot[] notificationSlots = null;
@Nullable private List<Integer> compactSlots = null;
private List<Integer> compactSlots;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Lifecycle // Lifecycle
@ -85,19 +85,22 @@ public class NotificationActionsPreference extends Preference {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private void saveChanges() { private void saveChanges() {
final SharedPreferences.Editor editor = getSharedPreferences().edit(); if (compactSlots != null && notificationSlots != null) {
final SharedPreferences.Editor editor = getSharedPreferences().edit();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
editor.putInt(getContext().getString(NotificationConstants.SLOT_COMPACT_PREF_KEYS[i]), editor.putInt(getContext().getString(
(i < compactSlots.size() ? compactSlots.get(i) : -1)); NotificationConstants.SLOT_COMPACT_PREF_KEYS[i]),
(i < compactSlots.size() ? compactSlots.get(i) : -1));
}
for (int i = 0; i < 5; i++) {
editor.putInt(getContext().getString(NotificationConstants.SLOT_PREF_KEYS[i]),
notificationSlots[i].selectedAction);
}
editor.apply();
} }
for (int i = 0; i < 5; i++) {
editor.putInt(getContext().getString(NotificationConstants.SLOT_PREF_KEYS[i]),
notificationSlots[i].selectedAction);
}
editor.apply();
} }