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 =
|
||||
(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);
|
||||
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);
|
||||
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);
|
||||
tabSettingsChanged = true;
|
||||
}
|
||||
|
|
|
@ -474,7 +474,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
|
|||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,11 +159,9 @@ public class RelatedItemsFragment extends BaseListInfoFragment<InfoItem, Related
|
|||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
||||
final String s) {
|
||||
if (headerBinding != null) {
|
||||
headerBinding.autoplaySwitch.setChecked(
|
||||
sharedPreferences.getBoolean(
|
||||
getString(R.string.auto_queue_key), false));
|
||||
final String key) {
|
||||
if (headerBinding != null && getString(R.string.auto_queue_key).equals(key)) {
|
||||
headerBinding.autoplaySwitch.setChecked(sharedPreferences.getBoolean(key, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
|||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public final class TabsManager {
|
|||
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener getPreferenceChangeListener() {
|
||||
return (sp, key) -> {
|
||||
if (key.equals(savedTabsKey)) {
|
||||
if (savedTabsKey.equals(key)) {
|
||||
if (savedTabsChangeListener != null) {
|
||||
savedTabsChangeListener.onTabsChanged();
|
||||
}
|
||||
|
|
|
@ -310,7 +310,7 @@ public class DownloadManagerService extends Service {
|
|||
}
|
||||
|
||||
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 {
|
||||
String value = prefs.getString(key, getString(R.string.downloads_maximum_retry_default));
|
||||
mManager.mPrefMaxRetry = value == null ? 0 : Integer.parseInt(value);
|
||||
|
@ -318,13 +318,13 @@ public class DownloadManagerService extends Service {
|
|||
mManager.mPrefMaxRetry = 0;
|
||||
}
|
||||
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);
|
||||
} 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);
|
||||
} 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();
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue