77
88package org.nsh07.pomodoro.ui.timerScreen
99
10- import android.app.Activity
11- import android.content.Context
12- import android.content.ContextWrapper
13- import android.os.Build
14- import android.view.WindowManager
10+ import androidx.activity.compose.LocalActivity
1511import androidx.compose.foundation.clickable
1612import androidx.compose.foundation.layout.Column
1713import androidx.compose.foundation.layout.Spacer
@@ -32,7 +28,6 @@ import androidx.compose.runtime.Composable
3228import androidx.compose.runtime.DisposableEffect
3329import androidx.compose.ui.Alignment
3430import androidx.compose.ui.Modifier
35- import androidx.compose.ui.platform.LocalContext
3631import androidx.compose.ui.res.painterResource
3732import androidx.compose.ui.res.stringResource
3833import androidx.compose.ui.unit.dp
@@ -44,35 +39,18 @@ fun AlarmDialog(
4439 modifier : Modifier = Modifier ,
4540 stopAlarm : () -> Unit
4641) {
47- val context = LocalContext .current
48- val activity = context.findActivity()
42+ val activity = LocalActivity .current
4943
5044 // Set lockscreen flags when dialog appears, remove when it disappears
5145 DisposableEffect (Unit ) {
5246 // Show over lockscreen
53- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O_MR1 ) {
54- activity?.setShowWhenLocked(true )
55- activity?.setTurnScreenOn(true )
56- } else {
57- @Suppress(" DEPRECATION" )
58- activity?.window?.addFlags(
59- WindowManager .LayoutParams .FLAG_SHOW_WHEN_LOCKED or
60- WindowManager .LayoutParams .FLAG_TURN_SCREEN_ON
61- )
62- }
47+ activity?.setShowWhenLocked(true )
48+ activity?.setTurnScreenOn(true )
6349
6450 onDispose {
6551 // Remove lockscreen flags when dialog is dismissed
66- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O_MR1 ) {
67- activity?.setShowWhenLocked(false )
68- activity?.setTurnScreenOn(false )
69- } else {
70- @Suppress(" DEPRECATION" )
71- activity?.window?.clearFlags(
72- WindowManager .LayoutParams .FLAG_SHOW_WHEN_LOCKED or
73- WindowManager .LayoutParams .FLAG_TURN_SCREEN_ON
74- )
75- }
52+ activity?.setShowWhenLocked(false )
53+ activity?.setTurnScreenOn(false )
7654 }
7755 }
7856
@@ -116,12 +94,3 @@ fun AlarmDialog(
11694 }
11795}
11896
119- // Add this helper function at the file level (outside the composable)
120- fun Context.findActivity (): Activity ? {
121- var context = this
122- while (context is ContextWrapper ) {
123- if (context is Activity ) return context
124- context = context.baseContext
125- }
126- return null
127- }
0 commit comments