Updated notifications screen
This commit is contained in:
1 parent
58b24e50ff
commit
0449a93b31
2 files changed
+3
-41
No files matched your search
+2
-40
@@ -54,39 +54,15 @@ fun NotificationScreen(
|
|||||||
onAgree: () -> Unit
|
onAgree: () -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val snackbarHostState = remember { SnackbarHostState() }
|
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.notification_animation))
|
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.notification_animation))
|
||||||
val progress by animateLottieCompositionAsState(
|
val progress by animateLottieCompositionAsState(
|
||||||
composition = composition,
|
composition = composition,
|
||||||
iterations = LottieConstants.IterateForever,
|
iterations = LottieConstants.IterateForever,
|
||||||
)
|
)
|
||||||
val askPermission = rememberSaveable { mutableStateOf(false) }
|
val askPermission = rememberSaveable { mutableStateOf(false) }
|
||||||
val askCount = rememberSaveable { mutableIntStateOf(0) }
|
|
||||||
|
|
||||||
val requestPermissionLauncher = rememberLauncherForActivityResult(
|
val requestPermissionLauncher = rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.RequestPermission()
|
contract = ActivityResultContracts.RequestPermission()
|
||||||
) { isGranted: Boolean ->
|
) { onAgree() }
|
||||||
if (isGranted) {
|
|
||||||
onAgree()
|
|
||||||
} else {
|
|
||||||
if (++askCount.intValue >= 2) {
|
|
||||||
snackbarHostState.currentSnackbarData?.dismiss()
|
|
||||||
onAgree()
|
|
||||||
}
|
|
||||||
scope.launch {
|
|
||||||
val result = snackbarHostState.showSnackbar(
|
|
||||||
message = context.getString(R.string.notification_permission_is_required_for_this_app_to_work_properly),
|
|
||||||
actionLabel = context.getString(R.string.allow),
|
|
||||||
duration = SnackbarDuration.Short,
|
|
||||||
)
|
|
||||||
when (result) {
|
|
||||||
SnackbarResult.Dismissed -> {}
|
|
||||||
SnackbarResult.ActionPerformed -> { askPermission.value = true }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleFabClick() {
|
fun handleFabClick() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
@@ -104,22 +80,10 @@ fun NotificationScreen(
|
|||||||
LaunchedEffect (askPermission.value) {
|
LaunchedEffect (askPermission.value) {
|
||||||
if (askPermission.value) {
|
if (askPermission.value) {
|
||||||
handleFabClick()
|
handleFabClick()
|
||||||
askPermission.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
snackbarHost = {
|
|
||||||
SnackbarHost(
|
|
||||||
hostState = snackbarHostState,
|
|
||||||
snackbar = { data ->
|
|
||||||
Snackbar(
|
|
||||||
snackbarData = data,
|
|
||||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp, vertical = 8.dp)),
|
|
||||||
shape = RoundedCornerShape(24.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) },
|
|
||||||
content = { it
|
content = { it
|
||||||
Column (modifier = Modifier.padding(32.dp)) {
|
Column (modifier = Modifier.padding(32.dp)) {
|
||||||
Spacer(modifier = Modifier.height(120.dp))
|
Spacer(modifier = Modifier.height(120.dp))
|
||||||
@@ -131,9 +95,7 @@ fun NotificationScreen(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxHeight(0.5f)
|
.fillMaxHeight(0.5f)
|
||||||
.align(Alignment.CenterHorizontally)
|
.align(Alignment.CenterHorizontally)
|
||||||
.semantics {
|
.semantics { contentDescription = context.getString(R.string.notification_bell_animation) },
|
||||||
contentDescription = context.getString(R.string.notification_bell_animation)
|
|
||||||
},
|
|
||||||
safeMode = true,
|
safeMode = true,
|
||||||
enableMergePaths = true
|
enableMergePaths = true
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<string name="continue_button">I\'m In</string>
|
<string name="continue_button">I\'m In</string>
|
||||||
<string name="notification_permission_is_required_for_this_app_to_work_properly">Notification permission is required for this app to work properly</string>
|
<string name="notification_permission_is_required_for_this_app_to_work_properly">Notification permission is required for this app to work properly</string>
|
||||||
<string name="allow">Allow</string>
|
<string name="allow">Allow</string>
|
||||||
<string name="notification_info_message">Notifications are recommended for this app to work properly. If not given, the system may terminate the app. You can mute notifications in the settings later.</string>
|
<string name="notification_info_message">Notifications can be enabled to show when the app is running in the background.</string>
|
||||||
<string name="set_as_lock_screen">Set as lock screen</string>
|
<string name="set_as_lock_screen">Set as lock screen</string>
|
||||||
<string name="lock_screen">Lock screen</string>
|
<string name="lock_screen">Lock screen</string>
|
||||||
<string name="home">Home screen</string>
|
<string name="home">Home screen</string>
|
||||||
|
|||||||
Reference in new issue
Block a user