mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Fix NPEs after OnSharedPreferenceChangeListener changes
Apps targeting {@link android.os.Build.VERSION_CODES#R} on devices running OS versions {@link android.os.Build.VERSION_CODES#R Android R} or later, will receive a {@code null} value when preferences are cleared.
This commit is contained in:
parent
e4641cd427
commit
b9378a7c1f
@ -172,13 +172,13 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
private final SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener =
|
private final SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener =
|
||||||
(sharedPreferences, key) -> {
|
(sharedPreferences, key) -> {
|
||||||
if (key.equals(getString(R.string.show_comments_key))) {
|
if (getString(R.string.show_comments_key).equals(key)) {
|
||||||
showComments = sharedPreferences.getBoolean(key, true);
|
showComments = sharedPreferences.getBoolean(key, true);
|
||||||
tabSettingsChanged = true;
|
tabSettingsChanged = true;
|
||||||
} else if (key.equals(getString(R.string.show_next_video_key))) {
|
} else if (getString(R.string.show_next_video_key).equals(key)) {
|
||||||
showRelatedItems = sharedPreferences.getBoolean(key, true);
|
showRelatedItems = sharedPreferences.getBoolean(key, true);
|
||||||
tabSettingsChanged = true;
|
tabSettingsChanged = true;
|
||||||
} else if (key.equals(getString(R.string.show_description_key))) {
|
} else if (getString(R.string.show_description_key).equals(key)) {
|
||||||
showDescription = sharedPreferences.getBoolean(key, true);
|
showDescription = sharedPreferences.getBoolean(key, true);
|
||||||
tabSettingsChanged = true;
|
tabSettingsChanged = true;
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
||||||
final String key) {
|
final String key) {
|
||||||
if (key.equals(getString(R.string.list_view_mode_key))) {
|
if (getString(R.string.list_view_mode_key).equals(key)) {
|
||||||
updateFlags |= LIST_MODE_UPDATE_FLAG;
|
updateFlags |= LIST_MODE_UPDATE_FLAG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,11 +159,9 @@ public class RelatedItemsFragment extends BaseListInfoFragment<InfoItem, Related
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
||||||
final String s) {
|
final String key) {
|
||||||
if (headerBinding != null) {
|
if (headerBinding != null && getString(R.string.auto_queue_key).equals(key)) {
|
||||||
headerBinding.autoplaySwitch.setChecked(
|
headerBinding.autoplaySwitch.setChecked(sharedPreferences.getBoolean(key, false));
|
||||||
sharedPreferences.getBoolean(
|
|
||||||
getString(R.string.auto_queue_key), false));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
||||||
final String key) {
|
final String key) {
|
||||||
if (key.equals(getString(R.string.list_view_mode_key))) {
|
if (getString(R.string.list_view_mode_key).equals(key)) {
|
||||||
updateFlags |= LIST_MODE_UPDATE_FLAG;
|
updateFlags |= LIST_MODE_UPDATE_FLAG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public final class TabsManager {
|
|||||||
|
|
||||||
private SharedPreferences.OnSharedPreferenceChangeListener getPreferenceChangeListener() {
|
private SharedPreferences.OnSharedPreferenceChangeListener getPreferenceChangeListener() {
|
||||||
return (sp, key) -> {
|
return (sp, key) -> {
|
||||||
if (key.equals(savedTabsKey)) {
|
if (savedTabsKey.equals(key)) {
|
||||||
if (savedTabsChangeListener != null) {
|
if (savedTabsChangeListener != null) {
|
||||||
savedTabsChangeListener.onTabsChanged();
|
savedTabsChangeListener.onTabsChanged();
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ public class DownloadManagerService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handlePreferenceChange(SharedPreferences prefs, @NonNull String key) {
|
private void handlePreferenceChange(SharedPreferences prefs, @NonNull String key) {
|
||||||
if (key.equals(getString(R.string.downloads_maximum_retry))) {
|
if (getString(R.string.downloads_maximum_retry).equals(key)) {
|
||||||
try {
|
try {
|
||||||
String value = prefs.getString(key, getString(R.string.downloads_maximum_retry_default));
|
String value = prefs.getString(key, getString(R.string.downloads_maximum_retry_default));
|
||||||
mManager.mPrefMaxRetry = value == null ? 0 : Integer.parseInt(value);
|
mManager.mPrefMaxRetry = value == null ? 0 : Integer.parseInt(value);
|
||||||
@ -318,13 +318,13 @@ public class DownloadManagerService extends Service {
|
|||||||
mManager.mPrefMaxRetry = 0;
|
mManager.mPrefMaxRetry = 0;
|
||||||
}
|
}
|
||||||
mManager.updateMaximumAttempts();
|
mManager.updateMaximumAttempts();
|
||||||
} else if (key.equals(getString(R.string.downloads_cross_network))) {
|
} else if (getString(R.string.downloads_cross_network).equals(key)) {
|
||||||
mManager.mPrefMeteredDownloads = prefs.getBoolean(key, false);
|
mManager.mPrefMeteredDownloads = prefs.getBoolean(key, false);
|
||||||
} else if (key.equals(getString(R.string.downloads_queue_limit))) {
|
} else if (getString(R.string.downloads_queue_limit).equals(key)) {
|
||||||
mManager.mPrefQueueLimit = prefs.getBoolean(key, true);
|
mManager.mPrefQueueLimit = prefs.getBoolean(key, true);
|
||||||
} else if (key.equals(getString(R.string.download_path_video_key))) {
|
} else if (getString(R.string.download_path_video_key).equals(key)) {
|
||||||
mManager.mMainStorageVideo = loadMainVideoStorage();
|
mManager.mMainStorageVideo = loadMainVideoStorage();
|
||||||
} else if (key.equals(getString(R.string.download_path_audio_key))) {
|
} else if (getString(R.string.download_path_audio_key).equals(key)) {
|
||||||
mManager.mMainStorageAudio = loadMainAudioStorage();
|
mManager.mMainStorageAudio = loadMainAudioStorage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user