Merge pull request #9696 from Stypox/fix-pref-npe

Fix NPEs after OnSharedPreferenceChangeListener changes
This commit is contained in:
Tobi 2023-01-17 13:01:09 +01:00 committed by GitHub
commit d758e50634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -36,7 +36,6 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
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.content.edit import androidx.core.content.edit
@ -122,7 +121,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
groupName = arguments?.getString(KEY_GROUP_NAME) ?: "" groupName = arguments?.getString(KEY_GROUP_NAME) ?: ""
onSettingsChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> onSettingsChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
if (key.equals(getString(R.string.list_view_mode_key))) { if (getString(R.string.list_view_mode_key).equals(key)) {
updateListViewModeOnResume = true updateListViewModeOnResume = true
} }
} }
@ -500,7 +499,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
private fun handleFeedNotAvailable( private fun handleFeedNotAvailable(
subscriptionEntity: SubscriptionEntity, subscriptionEntity: SubscriptionEntity,
@Nullable cause: Throwable?, cause: Throwable?,
nextItemsErrors: List<Throwable> nextItemsErrors: List<Throwable>
) { ) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())

View File

@ -27,14 +27,14 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
updateSeekOptions(); updateSeekOptions();
listener = (sharedPreferences, s) -> { listener = (sharedPreferences, key) -> {
// on M and above, if user chooses to minimise to popup player on exit // on M and above, if user chooses to minimise to popup player on exit
// and the app doesn't have display over other apps permission, // and the app doesn't have display over other apps permission,
// show a snackbar to let the user give permission // show a snackbar to let the user give permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& s.equals(getString(R.string.minimize_on_exit_key))) { && getString(R.string.minimize_on_exit_key).equals(key)) {
final String newSetting = sharedPreferences.getString(s, null); final String newSetting = sharedPreferences.getString(key, null);
if (newSetting != null if (newSetting != null
&& newSetting.equals(getString(R.string.minimize_on_exit_popup_key)) && newSetting.equals(getString(R.string.minimize_on_exit_popup_key))
&& !Settings.canDrawOverlays(getContext())) { && !Settings.canDrawOverlays(getContext())) {
@ -46,7 +46,7 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
.show(); .show();
} }
} else if (s.equals(getString(R.string.use_inexact_seek_key))) { } else if (getString(R.string.use_inexact_seek_key).equals(key)) {
updateSeekOptions(); updateSeekOptions();
} }
}; };

View File

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

View File

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