@@ -3,8 +3,10 @@ package org.schabi.newpipe.settings
33import android.content.SharedPreferences
44import android.content.SharedPreferences.OnSharedPreferenceChangeListener
55import android.graphics.Color
6+ import android.os.Build
67import android.os.Bundle
78import androidx.preference.Preference
9+ import androidx.preference.SwitchPreference
810import com.google.android.material.snackbar.Snackbar
911import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
1012import io.reactivex.rxjava3.disposables.Disposable
@@ -21,15 +23,17 @@ import org.schabi.newpipe.local.subscription.SubscriptionManager
2123
2224class NotificationsSettingsFragment : BasePreferenceFragment (), OnSharedPreferenceChangeListener {
2325
26+ private var streamsNotificationsPreference: SwitchPreference ? = null
2427 private var notificationWarningSnackbar: Snackbar ? = null
2528 private var loader: Disposable ? = null
2629
2730 override fun onCreatePreferences (savedInstanceState : Bundle ? , rootKey : String? ) {
2831 addPreferencesFromResource(R .xml.notifications_settings)
32+ streamsNotificationsPreference =
33+ findPreference(getString(R .string.enable_streams_notifications))
2934
3035 // main check is done in onResume, but also do it here to prevent flickering
31- preferenceScreen.isEnabled =
32- NotificationHelper .areNotificationsEnabledOnDevice(requireContext())
36+ updateEnabledState(NotificationHelper .areNotificationsEnabledOnDevice(requireContext()))
3337 }
3438
3539 override fun onStart () {
@@ -68,7 +72,7 @@ class NotificationsSettingsFragment : BasePreferenceFragment(), OnSharedPreferen
6872 // If they are disabled, show a snackbar informing the user about that
6973 // while allowing them to open the device's app settings.
7074 val enabled = NotificationHelper .areNotificationsEnabledOnDevice(requireContext())
71- preferenceScreen.isEnabled = enabled // it is disabled by default, see the xml
75+ updateEnabledState( enabled)
7276 if (! enabled) {
7377 if (notificationWarningSnackbar == null ) {
7478 notificationWarningSnackbar = Snackbar .make(
@@ -109,6 +113,16 @@ class NotificationsSettingsFragment : BasePreferenceFragment(), OnSharedPreferen
109113 super .onPause()
110114 }
111115
116+ private fun updateEnabledState (enabled : Boolean ) {
117+ // On Android 13 player notifications are exempt from notification settings
118+ // so the preferences in app should always be available.
119+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
120+ streamsNotificationsPreference?.isEnabled = enabled
121+ } else {
122+ preferenceScreen.isEnabled = enabled
123+ }
124+ }
125+
112126 private fun updateSubscriptions (subscriptions : List <SubscriptionEntity >) {
113127 val notified = subscriptions.count { it.notificationMode != NotificationMode .DISABLED }
114128 val preference = findPreference<Preference >(getString(R .string.streams_notifications_channels_key))
0 commit comments