mirror of
https://github.com/Michatec/Radio.git
synced 2026-06-03 13:50:27 +02:00
feat(ui): add test notification preference and optimize Android TV logic
Introduce a "Test Notification" preference in the settings menu to allow users to verify the notification system. This preference is automatically hidden on Android TV devices to maintain a clean UI. Additionally, refactor notification permission handling to skip requests on Android TV and improve the internal check for Leanback support using a lazy property. Updated string resources for the new preference across all supported languages.
This commit is contained in:
@@ -22,6 +22,8 @@ import com.michatec.radio.dialogs.PresetSelectionDialog
|
||||
import com.michatec.radio.dialogs.ThemeSelectionDialog
|
||||
import com.michatec.radio.dialogs.YesNoDialog
|
||||
import com.michatec.radio.helpers.*
|
||||
import com.michatec.radio.NotificationSys
|
||||
import android.content.pm.PackageManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -38,6 +40,11 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||
/* Define log tag */
|
||||
private val TAG: String = SettingsFragment::class.java.simpleName
|
||||
|
||||
// Check if the device running the app is an Android TV instance
|
||||
private val isAndroidTV: Boolean by lazy {
|
||||
packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
|
||||
}
|
||||
|
||||
/* Overrides onViewCreated from PreferenceFragmentCompat */
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
@@ -309,6 +316,21 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
|
||||
// set up "Test Notification" preference
|
||||
val preferenceTestNotification = Preference(context)
|
||||
preferenceTestNotification.title = getString(R.string.pref_test_notification_title)
|
||||
preferenceTestNotification.setIcon(R.drawable.ic_notification_app_icon_white_24dp)
|
||||
preferenceTestNotification.summary = getString(R.string.pref_test_notification_summary)
|
||||
preferenceTestNotification.setOnPreferenceClickListener {
|
||||
// show test notification
|
||||
NotificationSys.showNotification(
|
||||
context,
|
||||
getString(R.string.pref_test_notification_title),
|
||||
getString(R.string.notification_test_content)
|
||||
)
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
|
||||
// set up "Security" preference
|
||||
val preferenceSecurity = Preference(context)
|
||||
preferenceSecurity.title = getString(R.string.pref_security_title)
|
||||
@@ -364,6 +386,10 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||
preferenceCategoryGeneral.addPreference(preferenceThemeSelection)
|
||||
preferenceCategoryGeneral.addPreference(preferenceLanguageSelection)
|
||||
|
||||
if (!isAndroidTV) {
|
||||
preferenceCategoryGeneral.addPreference(preferenceTestNotification)
|
||||
}
|
||||
|
||||
screen.addPreference(preferenceCategoryAudioEffects)
|
||||
preferenceCategoryAudioEffects.addPreference(preferenceBassBoost)
|
||||
preferenceCategoryAudioEffects.addPreference(preferenceReverb)
|
||||
|
||||
Reference in New Issue
Block a user