diff --git a/app/src/main/java/com/aatorque/prefs/SettingsFragment.kt b/app/src/main/java/com/aatorque/prefs/SettingsFragment.kt index 43c8fae0..71f57f7c 100644 --- a/app/src/main/java/com/aatorque/prefs/SettingsFragment.kt +++ b/app/src/main/java/com/aatorque/prefs/SettingsFragment.kt @@ -1,7 +1,9 @@ package com.aatorque.prefs import android.content.Intent +import android.os.Build import android.os.Bundle +import android.provider.Settings import android.text.InputType import androidx.lifecycle.lifecycleScope import androidx.preference.CheckBoxPreference @@ -123,8 +125,17 @@ class SettingsFragment : PreferenceFragmentCompat() { } mediaBgPref.setOnPreferenceChangeListener { preference, newValue -> updateDatastorePref { - if (newValue as Boolean && !NotiService.isNotificationAccessEnabled) { - startActivity(Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")) + if (newValue as Boolean && !NotiService.isNotificationAccessEnabled(requireContext())) { + startActivity( + Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS").apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + putExtra( + Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, + NotiService::class.java.canonicalName + ) + } + } + ) } it.setAlbumArt(newValue) } @@ -148,6 +159,7 @@ class SettingsFragment : PreferenceFragmentCompat() { } return@setOnPreferenceChangeListener true } + blurArtPref.isVisible = Build.VERSION.SDK_INT >= 31 numScreensPref.setOnBindEditTextListener { it.inputType = InputType.TYPE_CLASS_NUMBER @@ -161,7 +173,8 @@ class SettingsFragment : PreferenceFragmentCompat() { centerGaugeLargePref.isChecked = it.centerGaugeLarge rotaryInputPref.isChecked = it.rotaryInput minMaxBelowPref.isChecked = it.minMaxBelow - mediaBgPref.isChecked = it.albumArt + mediaBgPref.isChecked = + it.albumArt && NotiService.isNotificationAccessEnabled(requireContext()) opacityPref.value = if (it.opacity == 0) 100 else it.opacity blurArtPref.value = it.blurArt darkenArtPref.value = it.darkenArt diff --git a/app/src/main/java/com/aatorque/stats/DashboardFragment.kt b/app/src/main/java/com/aatorque/stats/DashboardFragment.kt index c10f7339..68944aa6 100644 --- a/app/src/main/java/com/aatorque/stats/DashboardFragment.kt +++ b/app/src/main/java/com/aatorque/stats/DashboardFragment.kt @@ -118,13 +118,18 @@ open class DashboardFragment : AlbumArt() { albumArtReady.countDown() albumBlurEffect = if ( - it.blurArt != 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + it.blurArt != 0 && Build.VERSION.SDK_INT >= 31 ) { val blurFloat = it.blurArt.toFloat() - RenderEffect.createBlurEffect( - blurFloat, blurFloat, - Shader.TileMode.MIRROR - ) + try { + RenderEffect.createBlurEffect( + blurFloat, blurFloat, + Shader.TileMode.MIRROR + ) + } catch (e: NoClassDefFoundError) { + Timber.i("Version check failed to prevent error ${Build.VERSION.SDK_INT} >= ${Build.VERSION_CODES.S}") + null + } } else null albumColorFilter = if (it.darkenArt != 0) { PorterDuffColorFilter( diff --git a/app/src/main/java/com/aatorque/stats/NotiService.kt b/app/src/main/java/com/aatorque/stats/NotiService.kt index 3ce78483..b6e943fa 100644 --- a/app/src/main/java/com/aatorque/stats/NotiService.kt +++ b/app/src/main/java/com/aatorque/stats/NotiService.kt @@ -1,17 +1,14 @@ package com.aatorque.stats +import android.content.Context import android.service.notification.NotificationListenerService +import androidx.core.app.NotificationManagerCompat class NotiService : NotificationListenerService() { companion object { - var isNotificationAccessEnabled = false - } - - override fun onListenerConnected() { - isNotificationAccessEnabled = true - } - - override fun onListenerDisconnected() { - isNotificationAccessEnabled = false + fun isNotificationAccessEnabled(context: Context): Boolean { + return NotificationManagerCompat.getEnabledListenerPackages(context) + .contains(BuildConfig.APPLICATION_ID) + } } } \ No newline at end of file