Skip to content

Commit 8e47b11

Browse files
committed
fix:added the requried changes
1 parent 75d3029 commit 8e47b11

File tree

2 files changed

+9
-41
lines changed

2 files changed

+9
-41
lines changed

app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.nsh07.pomodoro.service
22

33
import android.annotation.SuppressLint
44
import android.app.Service
5-
import android.content.Context
65
import android.content.Intent
76
import android.media.AudioAttributes
87
import android.media.MediaPlayer
@@ -124,7 +123,7 @@ class TimerService : Service() {
124123
return super.onStartCommand(intent, flags, startId)
125124
}
126125

127-
@Suppress("DEPRECATION")
126+
128127
private fun toggleTimer() {
129128
updateProgressSegments()
130129

@@ -167,8 +166,8 @@ class TimerService : Service() {
167166
if (time < 0) {
168167
val powerManager = this@TimerService.getSystemService(POWER_SERVICE) as PowerManager
169168
wakeLock = powerManager.newWakeLock(
170-
PowerManager.FULL_WAKE_LOCK or
171-
PowerManager.ACQUIRE_CAUSES_WAKEUP or
169+
PowerManager.SCREEN_BRIGHT_WAKE_LOCK or
170+
PowerManager.ACQUIRE_CAUSES_WAKEUP or
172171
PowerManager.ON_AFTER_RELEASE,
173172
"PomodoroApp:AlarmWakeLock"
174173
)

app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77

88
package 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
1511
import androidx.compose.foundation.clickable
1612
import androidx.compose.foundation.layout.Column
1713
import androidx.compose.foundation.layout.Spacer
@@ -32,7 +28,6 @@ import androidx.compose.runtime.Composable
3228
import androidx.compose.runtime.DisposableEffect
3329
import androidx.compose.ui.Alignment
3430
import androidx.compose.ui.Modifier
35-
import androidx.compose.ui.platform.LocalContext
3631
import androidx.compose.ui.res.painterResource
3732
import androidx.compose.ui.res.stringResource
3833
import 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

Comments
 (0)