From 1879827f4be3171346d085f0da04c3cb53b64121 Mon Sep 17 00:00:00 2001 From: Michatec Date: Sat, 30 May 2026 22:15:51 +0200 Subject: [PATCH] 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. --- .../java/com/michatec/radio/MainActivity.kt | 23 ++++++---------- .../com/michatec/radio/SettingsFragment.kt | 26 +++++++++++++++++++ app/src/main/res/values-da/strings.xml | 2 ++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-el/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-ja/strings.xml | 2 ++ app/src/main/res/values-nl/strings.xml | 2 ++ app/src/main/res/values-pl/strings.xml | 2 ++ app/src/main/res/values-ru/strings.xml | 2 ++ app/src/main/res/values-uk/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 12 files changed, 54 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/michatec/radio/MainActivity.kt b/app/src/main/java/com/michatec/radio/MainActivity.kt index 4b654f7..7e9dfa7 100644 --- a/app/src/main/java/com/michatec/radio/MainActivity.kt +++ b/app/src/main/java/com/michatec/radio/MainActivity.kt @@ -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 - ) } } diff --git a/app/src/main/java/com/michatec/radio/SettingsFragment.kt b/app/src/main/java/com/michatec/radio/SettingsFragment.kt index 6388b75..cdccf66 100644 --- a/app/src/main/java/com/michatec/radio/SettingsFragment.kt +++ b/app/src/main/java/com/michatec/radio/SettingsFragment.kt @@ -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) diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 2b3892c..2fcebfe 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -86,6 +86,8 @@ App-tema Download nyeste stationsbilleder. Opdater stationsbilleder + Testmeddelelse + Test om meddelelsessystemet virker. Genvej til seneste station er deaktiveret. Afspil seneste station diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a781afc..1771d47 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -95,6 +95,8 @@ App-Design Die neueste Version aller Senderbilder herunterladen. Senderbilder aktualisieren + Test-Benachrichtigung + Testen, ob das Benachrichtigungssystem funktioniert. Verknüpfung für Wiedergabe des letzten Senders deaktiviert. diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 7a0f42e..978abcd 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -86,6 +86,8 @@ Θέμα Εφαρμογής Κατεβάστε την τελευταία έκδοση των εικόνων όλων των σταθμών. Ενημέρωση Εικόνων Σταθμών + Δοκιμαστική Ειδοποίηση + Έλεγχος αν το σύστημα ειδοποιήσεων λειτουργεί. Η συντόμευση για την αναπαραγωγή του τελευταίου σταθμού έχει απενεργοποιηθεί. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5f3677b..4f7ec8d 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -86,6 +86,8 @@ Thème de lapplication Télécharger la dernière version de toutes les images des stations. Mettre à jour les images des stations + Notification de test + Tester si le système de notification fonctionne. Raccourci pour lire la dernière station désactivé. Lire la dernière station diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 5d1d514..26e6542 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -86,6 +86,8 @@ アプリテーマ すべての局画像を最新に更新します。 局画像を更新 + テスト通知 + 通知システムが動作するかテストします。 最後に再生した局のショートカットは無効になっています。 最後の局を再生 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 945e38f..55cb525 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -86,6 +86,8 @@ App Thema Download de laatste versie van alle zenderafbeeldingen. Update Zenderafbeeldingen + Testmelding + Test of het meldingsysteem werkt. Snelkoppeling voor het afspelen van de laatste zender uitgeschakeld. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 7372ad4..ef16cd9 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -86,6 +86,8 @@ Motyw aplikacji Pobierz najnowszą wersję wszystkich obrazów stacji w swojej kolekcji. Aktualizuj zdjęcia stacji + Testowe powiadomienie + Sprawdź, czy system powiadomień działa. Skrót do odtwarzania ostatniej stacji jest wyłączony. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index c12c8af..656e660 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -86,6 +86,8 @@ Тема приложения Скачать последнюю версию всех изображений станций. Обновить изображения станций + Тест уведомления + Проверить, работает ли система уведомлений. Ярлык для воспроизведения последней станции отключён. diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 84a6ccf..beea9f2 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -86,6 +86,8 @@ Тема застосунку Завантажити останню версію всіх зображень станцій. Оновити зображення станцій + Тестове сповіщення + Перевірити, чи працює система сповіщень. Ярлик для відтворення останньої станції вимкнено. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3141e9a..6170666 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -146,6 +146,8 @@ App Theme Download latest version of all station images. Update Station Images + Test Notification + Test whether the notification system works. 00:00