diff --git a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt index 8408b6d..fc104ab 100644 --- a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt +++ b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt @@ -2,7 +2,6 @@ package org.nsh07.pomodoro.service import android.annotation.SuppressLint import android.app.Service -import android.content.Context import android.content.Intent import android.media.AudioAttributes import android.media.MediaPlayer @@ -124,7 +123,7 @@ class TimerService : Service() { return super.onStartCommand(intent, flags, startId) } - @Suppress("DEPRECATION") + private fun toggleTimer() { updateProgressSegments() @@ -167,8 +166,8 @@ class TimerService : Service() { if (time < 0) { val powerManager = this@TimerService.getSystemService(POWER_SERVICE) as PowerManager wakeLock = powerManager.newWakeLock( - PowerManager.FULL_WAKE_LOCK or - PowerManager.ACQUIRE_CAUSES_WAKEUP or + PowerManager.SCREEN_BRIGHT_WAKE_LOCK or + PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.ON_AFTER_RELEASE, "PomodoroApp:AlarmWakeLock" ) diff --git a/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt b/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt index d41c27e..ed39a73 100644 --- a/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt +++ b/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt @@ -7,11 +7,7 @@ package org.nsh07.pomodoro.ui.timerScreen -import android.app.Activity -import android.content.Context -import android.content.ContextWrapper -import android.os.Build -import android.view.WindowManager +import androidx.activity.compose.LocalActivity import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -32,7 +28,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -44,35 +39,18 @@ fun AlarmDialog( modifier: Modifier = Modifier, stopAlarm: () -> Unit ) { - val context = LocalContext.current - val activity = context.findActivity() + val activity = LocalActivity.current // Set lockscreen flags when dialog appears, remove when it disappears DisposableEffect(Unit) { // Show over lockscreen - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - activity?.setShowWhenLocked(true) - activity?.setTurnScreenOn(true) - } else { - @Suppress("DEPRECATION") - activity?.window?.addFlags( - WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or - WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON - ) - } + activity?.setShowWhenLocked(true) + activity?.setTurnScreenOn(true) onDispose { // Remove lockscreen flags when dialog is dismissed - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - activity?.setShowWhenLocked(false) - activity?.setTurnScreenOn(false) - } else { - @Suppress("DEPRECATION") - activity?.window?.clearFlags( - WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or - WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON - ) - } + activity?.setShowWhenLocked(false) + activity?.setTurnScreenOn(false) } } @@ -116,12 +94,3 @@ fun AlarmDialog( } } -// Add this helper function at the file level (outside the composable) -fun Context.findActivity(): Activity? { - var context = this - while (context is ContextWrapper) { - if (context is Activity) return context - context = context.baseContext - } - return null -} \ No newline at end of file