mirror of
https://github.com/Michatec/Radio.git
synced 2026-06-15 12:03:22 +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:
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user