diff --git a/app/src/main/java/org/mozilla/focus/autocomplete/AutocompleteSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/autocomplete/AutocompleteSettingsFragment.kt index a412d286a77..7bffb850a0d 100644 --- a/app/src/main/java/org/mozilla/focus/autocomplete/AutocompleteSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/autocomplete/AutocompleteSettingsFragment.kt @@ -45,13 +45,13 @@ class AutocompleteSettingsFragment : BaseSettingsFragment(), SharedPreferences.O showToolbar(getString(R.string.preference_subitem_autocomplete)) - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) } override fun onPause() { super.onPause() - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) } override fun onPreferenceTreeClick(preference: androidx.preference.Preference?): Boolean { diff --git a/app/src/main/java/org/mozilla/focus/search/SearchEnginePreference.kt b/app/src/main/java/org/mozilla/focus/search/SearchEnginePreference.kt index 4eee186462f..8f49543ffdf 100644 --- a/app/src/main/java/org/mozilla/focus/search/SearchEnginePreference.kt +++ b/app/src/main/java/org/mozilla/focus/search/SearchEnginePreference.kt @@ -29,12 +29,12 @@ class SearchEnginePreference : Preference, SharedPreferences.OnSharedPreferenceC override fun onAttached() { summary = defaultSearchEngineName - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) super.onAttached() } override fun onPrepareForRemoval() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) super.onPrepareForRemoval() } diff --git a/app/src/main/java/org/mozilla/focus/settings/SearchSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/SearchSettingsFragment.kt index 719405473a0..965dd082d99 100644 --- a/app/src/main/java/org/mozilla/focus/settings/SearchSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/SearchSettingsFragment.kt @@ -27,13 +27,13 @@ class SearchSettingsFragment : override fun onResume() { super.onResume() - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) showToolbar(getString(R.string.preference_category_search)) } override fun onPause() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) super.onPause() } diff --git a/app/src/main/java/org/mozilla/focus/settings/advanced/AdvancedSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/advanced/AdvancedSettingsFragment.kt index 68a857ffeaa..dd310c42f32 100644 --- a/app/src/main/java/org/mozilla/focus/settings/advanced/AdvancedSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/advanced/AdvancedSettingsFragment.kt @@ -34,13 +34,13 @@ class AdvancedSettingsFragment : override fun onResume() { super.onResume() - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) showToolbar(getString(R.string.preference_category_advanced)) } override fun onPause() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) super.onPause() } diff --git a/app/src/main/java/org/mozilla/focus/settings/advanced/SecretSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/advanced/SecretSettingsFragment.kt index cc9730109ae..e9a0c6f654e 100644 --- a/app/src/main/java/org/mozilla/focus/settings/advanced/SecretSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/advanced/SecretSettingsFragment.kt @@ -21,7 +21,7 @@ class SecretSettingsFragment : override fun onStart() { super.onStart() showToolbar(getString(R.string.preference_secret_settings)) - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/org/mozilla/focus/settings/privacy/PrivacySecuritySettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/privacy/PrivacySecuritySettingsFragment.kt index b2bd490c63c..138e158172a 100644 --- a/app/src/main/java/org/mozilla/focus/settings/privacy/PrivacySecuritySettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/privacy/PrivacySecuritySettingsFragment.kt @@ -31,7 +31,8 @@ class PrivacySecuritySettingsFragment : override fun onCreatePreferences(p0: Bundle?, p1: String?) { addPreferencesFromResource(R.xml.privacy_security_settings) - val biometricPreference: SwitchPreferenceCompat? = findPreference(getString(R.string.pref_key_biometric)) + val biometricPreference: SwitchPreferenceCompat? = + findPreference(getString(R.string.pref_key_biometric)) val appName = getString(R.string.app_name) biometricPreference?.summary = getString(R.string.preference_security_biometric_summary2, appName) @@ -72,14 +73,14 @@ class PrivacySecuritySettingsFragment : updateStealthToggleAvailability() updateExceptionSettingAvailability() - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) // Update title and icons when returning to fragments. showToolbar(getString(R.string.preference_privacy_and_security_header)) } override fun onPause() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) super.onPause() } @@ -113,23 +114,25 @@ class PrivacySecuritySettingsFragment : } private fun updateBiometricsToggleAvailability() { - val switch = preferenceScreen.findPreference(resources.getString(R.string.pref_key_biometric)) - as? SwitchPreferenceCompat + val switch = + preferenceScreen.findPreference(resources.getString(R.string.pref_key_biometric)) + as? SwitchPreferenceCompat if (!requireContext().canUseBiometricFeature()) { switch?.isChecked = false switch?.isEnabled = false preferenceManager.sharedPreferences - .edit() - .putBoolean(resources.getString(R.string.pref_key_biometric), false) - .apply() + ?.edit() + ?.putBoolean(resources.getString(R.string.pref_key_biometric), false) + ?.apply() } else { switch?.isEnabled = true } } private fun updateExceptionSettingAvailability() { - val exceptionsPreference: Preference? = findPreference(getString(R.string.pref_key_screen_exceptions)) + val exceptionsPreference: Preference? = + findPreference(getString(R.string.pref_key_screen_exceptions)) exceptionsPreference?.isEnabled = false requireComponents.trackingProtectionUseCases.fetchExceptions.invoke { exceptions -> @@ -199,17 +202,19 @@ class PrivacySecuritySettingsFragment : private fun updateStealthToggleAvailability() { val switch = preferenceScreen.findPreference(resources.getString(R.string.pref_key_secure)) as? SwitchPreferenceCompat - if (preferenceManager.sharedPreferences - .getBoolean( - resources.getString(R.string.pref_key_biometric), - false, - ) + + val sharedPreferences = preferenceManager.sharedPreferences + + if (sharedPreferences?.getBoolean( + resources.getString(R.string.pref_key_biometric), + false, + ) == true ) { - preferenceManager.sharedPreferences - .edit().putBoolean( - resources.getString(R.string.pref_key_secure), - true, - ).apply() + sharedPreferences + .edit() + .putBoolean(resources.getString(R.string.pref_key_secure), true) + .apply() + // Disable the stealth switch switch?.isChecked = true switch?.isEnabled = false