Skip to content

Commit 742e4a7

Browse files
committed
fix: request notification permission on enable
1 parent 7948a5b commit 742e4a7

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
package to.bitkit.ui
44

5+
import android.Manifest
56
import android.content.Intent
7+
import android.os.Build
8+
import androidx.activity.compose.rememberLauncherForActivityResult
9+
import androidx.activity.result.contract.ActivityResultContracts
610
import androidx.compose.foundation.layout.Box
711
import androidx.compose.foundation.layout.fillMaxSize
812
import androidx.compose.material3.DrawerState
@@ -237,6 +241,12 @@ fun ContentView(
237241
val notificationsGranted by settingsViewModel.notificationsGranted.collectAsStateWithLifecycle()
238242
val walletExists = walletUiState.walletExists
239243

244+
val notificationPermissionLauncher = rememberLauncherForActivityResult(
245+
ActivityResultContracts.RequestPermission()
246+
) { granted ->
247+
settingsViewModel.setNotificationPreference(granted)
248+
}
249+
240250
// Effects on app entering fg (ON_START) / bg (ON_STOP)
241251
DisposableEffect(lifecycle) {
242252
val observer = LifecycleEventObserver { _, event ->
@@ -501,8 +511,12 @@ fun ContentView(
501511
},
502512
onEnable = {
503513
appViewModel.dismissTimedSheet()
504-
navController.navigateTo(Routes.BackgroundPaymentsSettings)
505514
settingsViewModel.setBgPaymentsIntroSeen(true)
515+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
516+
notificationPermissionLauncher.launch(
517+
Manifest.permission.POST_NOTIFICATIONS
518+
)
519+
}
506520
},
507521
)
508522
}
@@ -896,8 +910,10 @@ private fun NavGraphBuilder.home(
896910
val isRecoveryMode by walletViewModel.isRecoveryMode.collectAsStateWithLifecycle()
897911
val hazeState = rememberHazeState()
898912

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.
899915
RequestNotificationPermissions(
900-
showPermissionDialog = !isRecoveryMode,
916+
showPermissionDialog = false,
901917
onPermissionChange = { granted ->
902918
settingsViewModel.setNotificationPreference(granted)
903919
}

changelog.d/next/1004.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The system notification permission dialog is now only requested when you tap Enable on the background payments prompt, instead of appearing automatically on every app open.

0 commit comments

Comments
 (0)