Skip to content

Commit 43f8540

Browse files
authored
Merge pull request #5944 from Stypox/fix-search-menu
Fix some random NullPointerExceptions
2 parents 5739caa + 5d6a568 commit 43f8540

3 files changed

Lines changed: 26 additions & 20 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ public void onComplete() { }
423423
@Override
424424
public void setTitle(final String title) {
425425
super.setTitle(title);
426-
headerBinding.playlistTitleView.setText(title);
426+
if (headerBinding != null) {
427+
headerBinding.playlistTitleView.setText(title);
428+
}
427429
}
428430

429431
private void onBookmarkClicked() {

app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
139139
@State
140140
boolean wasSearchFocused = false;
141141

142-
private Map<Integer, String> menuItemToFilterName;
142+
@Nullable private Map<Integer, String> menuItemToFilterName = null;
143143
private StreamingService service;
144144
private Page nextPage;
145145
private boolean isSuggestionsEnabled = true;
@@ -455,11 +455,12 @@ public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
455455
}
456456

457457
@Override
458-
public boolean onOptionsItemSelected(final MenuItem item) {
459-
final List<String> cf = new ArrayList<>(1);
460-
cf.add(menuItemToFilterName.get(item.getItemId()));
461-
changeContentFilter(item, cf);
462-
458+
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
459+
if (menuItemToFilterName != null) {
460+
final List<String> cf = new ArrayList<>(1);
461+
cf.add(menuItemToFilterName.get(item.getItemId()));
462+
changeContentFilter(item, cf);
463+
}
463464
return true;
464465
}
465466

app/src/main/java/org/schabi/newpipe/settings/custom/NotificationActionsPreference.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.widget.Toast;
1818

1919
import androidx.annotation.NonNull;
20+
import androidx.annotation.Nullable;
2021
import androidx.appcompat.app.AlertDialog;
2122
import androidx.appcompat.content.res.AppCompatResources;
2223
import 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

Comments
 (0)