Merge pull request #5944 from Stypox/fix-search-menu

Fix some random NullPointerExceptions
This commit is contained in:
Stypox 2021-03-31 15:21:13 +02:00 committed by GitHub
commit 43f85408be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 21 deletions

View File

@ -423,7 +423,9 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
@Override @Override
public void setTitle(final String title) { public void setTitle(final String title) {
super.setTitle(title); super.setTitle(title);
headerBinding.playlistTitleView.setText(title); if (headerBinding != null) {
headerBinding.playlistTitleView.setText(title);
}
} }
private void onBookmarkClicked() { private void onBookmarkClicked() {

View File

@ -139,7 +139,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
@State @State
boolean wasSearchFocused = false; boolean wasSearchFocused = false;
private Map<Integer, String> menuItemToFilterName; @Nullable private Map<Integer, String> menuItemToFilterName = null;
private StreamingService service; private StreamingService service;
private Page nextPage; private Page nextPage;
private boolean isSuggestionsEnabled = true; private boolean isSuggestionsEnabled = true;
@ -455,11 +455,12 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
} }
@Override @Override
public boolean onOptionsItemSelected(final MenuItem item) { public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
final List<String> cf = new ArrayList<>(1); if (menuItemToFilterName != null) {
cf.add(menuItemToFilterName.get(item.getItemId())); final List<String> cf = new ArrayList<>(1);
changeContentFilter(item, cf); cf.add(menuItemToFilterName.get(item.getItemId()));
changeContentFilter(item, cf);
}
return true; return true;
} }

View File

@ -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();
} }