|
2 | 2 |
|
3 | 3 | package to.bitkit.ui |
4 | 4 |
|
| 5 | +import android.Manifest |
5 | 6 | import android.content.Intent |
| 7 | +import android.os.Build |
| 8 | +import androidx.activity.compose.rememberLauncherForActivityResult |
| 9 | +import androidx.activity.result.contract.ActivityResultContracts |
6 | 10 | import androidx.compose.foundation.layout.Box |
7 | 11 | import androidx.compose.foundation.layout.fillMaxSize |
8 | 12 | import androidx.compose.material3.DrawerState |
@@ -237,6 +241,12 @@ fun ContentView( |
237 | 241 | val notificationsGranted by settingsViewModel.notificationsGranted.collectAsStateWithLifecycle() |
238 | 242 | val walletExists = walletUiState.walletExists |
239 | 243 |
|
| 244 | + val notificationPermissionLauncher = rememberLauncherForActivityResult( |
| 245 | + ActivityResultContracts.RequestPermission() |
| 246 | + ) { granted -> |
| 247 | + settingsViewModel.setNotificationPreference(granted) |
| 248 | + } |
| 249 | + |
240 | 250 | // Effects on app entering fg (ON_START) / bg (ON_STOP) |
241 | 251 | DisposableEffect(lifecycle) { |
242 | 252 | val observer = LifecycleEventObserver { _, event -> |
@@ -501,8 +511,12 @@ fun ContentView( |
501 | 511 | }, |
502 | 512 | onEnable = { |
503 | 513 | appViewModel.dismissTimedSheet() |
504 | | - navController.navigateTo(Routes.BackgroundPaymentsSettings) |
505 | 514 | settingsViewModel.setBgPaymentsIntroSeen(true) |
| 515 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { |
| 516 | + notificationPermissionLauncher.launch( |
| 517 | + Manifest.permission.POST_NOTIFICATIONS |
| 518 | + ) |
| 519 | + } |
506 | 520 | }, |
507 | 521 | ) |
508 | 522 | } |
@@ -896,8 +910,10 @@ private fun NavGraphBuilder.home( |
896 | 910 | val isRecoveryMode by walletViewModel.isRecoveryMode.collectAsStateWithLifecycle() |
897 | 911 | val hazeState = rememberHazeState() |
898 | 912 |
|
| 913 | + // Only keep notification permission state in sync; the system dialog is requested |
| 914 | + // from the background payments intro sheet, not automatically on the home screen. |
899 | 915 | RequestNotificationPermissions( |
900 | | - showPermissionDialog = !isRecoveryMode, |
| 916 | + showPermissionDialog = false, |
901 | 917 | onPermissionChange = { granted -> |
902 | 918 | settingsViewModel.setNotificationPreference(granted) |
903 | 919 | } |
|
0 commit comments