Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrlzy committed Oct 23, 2024
1 parent 9b843b7 commit fc7d732
Showing 1 changed file with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ fun PairAlertConditionScreen(navigator: DestinationsNavigator) {
viewModel(factory = DIManager.component.pairAlertVMFactory())

val ctx = LocalContext.current
val onScreenOpenNotificationPermissionLauncher = rememberNotificationPermissionOnScreenOpen(ctx)
val onScreenOpenNotificationPermissionLauncher = rememberNotificationPermissionLauncher(ctx)
val onNewPairNotificationPermissionLauncher =
rememberNotificationPermissionOnNewPair(
rememberNotificationPermissionLauncher(
ctx = ctx,
onGranted = viewModel::onNotificationPermissionGrantedOnNewPair,
)
Expand Down Expand Up @@ -411,36 +411,23 @@ private fun Empty(
}

@Composable
private fun rememberNotificationPermissionOnScreenOpen(ctx: Context) =
rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission(),
) { isGranted ->
if (isGranted.not()) {
toastNotificationPermissionExplanation(ctx)
}
}

@Composable
private fun rememberNotificationPermissionOnNewPair(
private fun rememberNotificationPermissionLauncher(
ctx: Context,
onGranted: () -> Unit,
onGranted: (() -> Unit)? = null,
) = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission(),
) { isGranted ->
if (isGranted) {
onGranted()
onGranted?.invoke()
} else {
toastNotificationPermissionExplanation(ctx)
Toast.makeText(
ctx,
ctx.getString(R.string.alert_post_notification_permission_explanation),
Toast.LENGTH_SHORT,
).show()
}
}

private fun toastNotificationPermissionExplanation(ctx: Context) =
Toast.makeText(
ctx,
ctx.getString(R.string.alert_post_notification_permission_explanation),
Toast.LENGTH_SHORT,
).show()

private val previewPairAlert =
PairAlert(
id = 0,
Expand Down

0 comments on commit fc7d732

Please sign in to comment.