Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions app/src/main/java/to/bitkit/ui/ContentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

package to.bitkit.ui

import android.Manifest
import android.content.Intent
import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.DrawerState
Expand Down Expand Up @@ -237,6 +241,12 @@ fun ContentView(
val notificationsGranted by settingsViewModel.notificationsGranted.collectAsStateWithLifecycle()
val walletExists = walletUiState.walletExists

val notificationPermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { granted ->
settingsViewModel.setNotificationPreference(granted)
}

// Effects on app entering fg (ON_START) / bg (ON_STOP)
DisposableEffect(lifecycle) {
val observer = LifecycleEventObserver { _, event ->
Expand Down Expand Up @@ -501,8 +511,16 @@ fun ContentView(
},
onEnable = {
appViewModel.dismissTimedSheet()
navController.navigateTo(Routes.BackgroundPaymentsSettings)
settingsViewModel.setBgPaymentsIntroSeen(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
notificationPermissionLauncher.launch(
Manifest.permission.POST_NOTIFICATIONS
)
} else {
// Pre-13 has no runtime permission dialog; open the
// in-app background payments settings instead.
navController.navigateTo(Routes.BackgroundPaymentsSettings)
}
Comment on lines +515 to +523

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this belongs to a reusable top level fn, not inline in a handler, especially because other entrypoints should be handled the same way…

},
)
}
Expand Down Expand Up @@ -896,8 +914,10 @@ private fun NavGraphBuilder.home(
val isRecoveryMode by walletViewModel.isRecoveryMode.collectAsStateWithLifecycle()
val hazeState = rememberHazeState()

// Only keep notification permission state in sync; the system dialog is requested
// from the background payments intro sheet, not automatically on the home screen.
RequestNotificationPermissions(
showPermissionDialog = !isRecoveryMode,
showPermissionDialog = false,
Comment thread
jvsena42 marked this conversation as resolved.
onPermissionChange = { granted ->
settingsViewModel.setNotificationPreference(granted)
}
Expand Down Expand Up @@ -1362,10 +1382,18 @@ private fun NavGraphBuilder.generalSettingsSubScreens(
}

composableWithDefaultTransitions<Routes.BackgroundPaymentsIntro> {
val notificationPermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { granted ->
settingsViewModel.setNotificationPreference(granted)
}
BackgroundPaymentsIntroScreen(
onBack = { navController.popBackStack() },
onLater = { navController.popBackStack() },
onEnable = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
navController.navigateTo(Routes.BackgroundPaymentsSettings)
},
)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/next/1004.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Loading