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:
2026-05-30 22:15:51 +02:00
parent 23079649c5
commit 1879827f4b
12 changed files with 54 additions and 15 deletions
@@ -35,17 +35,16 @@ class MainActivity : AppCompatActivity() {
/* Main class variables */
private lateinit var appBarConfiguration: AppBarConfiguration
// Check if the device running the app is an Android TV instance
private val isAndroidTV: Boolean by lazy {
packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
}
// request notification permission (for Android 13+)
private val permissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted ->
if (isGranted) {
NotificationSys.showNotification(
this,
R.string.app_name,
R.string.notification_test_content
)
} else {
if (!isGranted) {
Snackbar.make(
findViewById(android.R.id.content),
R.string.snackbar_failed_permission_notification,
@@ -95,7 +94,7 @@ class MainActivity : AppCompatActivity() {
supportActionBar?.hide()
// TV-specific loading logic: Hide the overlay once the app is ready
if (packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
if (isAndroidTV) {
Handler(Looper.getMainLooper()).postDelayed({
hideLoadingOverlay()
}, 1200)
@@ -107,14 +106,8 @@ class MainActivity : AppCompatActivity() {
PreferencesHelper.registerPreferenceChangeListener(sharedPreferenceChangeListener)
// request permissions
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (!isAndroidTV && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
} else {
NotificationSys.showNotification(
this,
R.string.app_name,
R.string.notification_test_content
)
}
}
@@ -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)
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">App-tema</string>
<string name="pref_update_station_images_summary">Download nyeste stationsbilleder.</string>
<string name="pref_update_station_images_title">Opdater stationsbilleder</string>
<string name="pref_test_notification_title">Testmeddelelse</string>
<string name="pref_test_notification_summary">Test om meddelelsessystemet virker.</string>
<!-- App-genveje -->
<string name="shortcut_last_station_disabled_message">Genvej til seneste station er deaktiveret.</string>
<string name="shortcut_last_station_long_label">Afspil seneste station</string>
+2
View File
@@ -95,6 +95,8 @@
<string name="pref_theme_selection_title">App-Design</string>
<string name="pref_update_station_images_summary">Die neueste Version aller Senderbilder herunterladen.</string>
<string name="pref_update_station_images_title">Senderbilder aktualisieren</string>
<string name="pref_test_notification_title">Test-Benachrichtigung</string>
<string name="pref_test_notification_summary">Testen, ob das Benachrichtigungssystem funktioniert.</string>
<!-- Sample Text -->
<!-- App Shortcuts -->
<string name="shortcut_last_station_disabled_message">Verknüpfung für Wiedergabe des letzten Senders deaktiviert.</string>
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">Θέμα Εφαρμογής</string>
<string name="pref_update_station_images_summary">Κατεβάστε την τελευταία έκδοση των εικόνων όλων των σταθμών.</string>
<string name="pref_update_station_images_title">Ενημέρωση Εικόνων Σταθμών</string>
<string name="pref_test_notification_title">Δοκιμαστική Ειδοποίηση</string>
<string name="pref_test_notification_summary">Έλεγχος αν το σύστημα ειδοποιήσεων λειτουργεί.</string>
<!-- Sample Text -->
<!-- App Shortcuts -->
<string name="shortcut_last_station_disabled_message">Η συντόμευση για την αναπαραγωγή του τελευταίου σταθμού έχει απενεργοποιηθεί.</string>
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">Thème de lapplication</string>
<string name="pref_update_station_images_summary">Télécharger la dernière version de toutes les images des stations.</string>
<string name="pref_update_station_images_title">Mettre à jour les images des stations</string>
<string name="pref_test_notification_title">Notification de test</string>
<string name="pref_test_notification_summary">Tester si le système de notification fonctionne.</string>
<!-- Raccourcis de l'app -->
<string name="shortcut_last_station_disabled_message">Raccourci pour lire la dernière station désactivé.</string>
<string name="shortcut_last_station_long_label">Lire la dernière station</string>
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">アプリテーマ</string>
<string name="pref_update_station_images_summary">すべての局画像を最新に更新します。</string>
<string name="pref_update_station_images_title">局画像を更新</string>
<string name="pref_test_notification_title">テスト通知</string>
<string name="pref_test_notification_summary">通知システムが動作するかテストします。</string>
<!-- ショートカット -->
<string name="shortcut_last_station_disabled_message">最後に再生した局のショートカットは無効になっています。</string>
<string name="shortcut_last_station_long_label">最後の局を再生</string>
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">App Thema</string>
<string name="pref_update_station_images_summary">Download de laatste versie van alle zenderafbeeldingen.</string>
<string name="pref_update_station_images_title">Update Zenderafbeeldingen</string>
<string name="pref_test_notification_title">Testmelding</string>
<string name="pref_test_notification_summary">Test of het meldingsysteem werkt.</string>
<!-- Sample Text -->
<!-- App Shortcuts -->
<string name="shortcut_last_station_disabled_message">Snelkoppeling voor het afspelen van de laatste zender uitgeschakeld.</string>
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">Motyw aplikacji</string>
<string name="pref_update_station_images_summary">Pobierz najnowszą wersję wszystkich obrazów stacji w swojej kolekcji.</string>
<string name="pref_update_station_images_title">Aktualizuj zdjęcia stacji</string>
<string name="pref_test_notification_title">Testowe powiadomienie</string>
<string name="pref_test_notification_summary">Sprawdź, czy system powiadomień działa.</string>
<!-- Sample Text -->
<!-- App Shortcuts -->
<string name="shortcut_last_station_disabled_message">Skrót do odtwarzania ostatniej stacji jest wyłączony.</string>
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">Тема приложения</string>
<string name="pref_update_station_images_summary">Скачать последнюю версию всех изображений станций.</string>
<string name="pref_update_station_images_title">Обновить изображения станций</string>
<string name="pref_test_notification_title">Тест уведомления</string>
<string name="pref_test_notification_summary">Проверить, работает ли система уведомлений.</string>
<!-- Sample Text -->
<!-- App Shortcuts -->
<string name="shortcut_last_station_disabled_message">Ярлык для воспроизведения последней станции отключён.</string>
+2
View File
@@ -86,6 +86,8 @@
<string name="pref_theme_selection_title">Тема застосунку</string>
<string name="pref_update_station_images_summary">Завантажити останню версію всіх зображень станцій.</string>
<string name="pref_update_station_images_title">Оновити зображення станцій</string>
<string name="pref_test_notification_title">Тестове сповіщення</string>
<string name="pref_test_notification_summary">Перевірити, чи працює система сповіщень.</string>
<!-- Sample Text -->
<!-- App Shortcuts -->
<string name="shortcut_last_station_disabled_message">Ярлик для відтворення останньої станції вимкнено.</string>
+2
View File
@@ -146,6 +146,8 @@
<string name="pref_theme_selection_title">App Theme</string>
<string name="pref_update_station_images_summary">Download latest version of all station images.</string>
<string name="pref_update_station_images_title">Update Station Images</string>
<string name="pref_test_notification_title">Test Notification</string>
<string name="pref_test_notification_summary">Test whether the notification system works.</string>
<!-- Sample Text -->
<string name="sample_text_sleep_timer_remaining_time" translatable="false">00:00</string>