feat(system): update dnd status while running the timer
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
package org.nsh07.pomodoro.service
|
package org.nsh07.pomodoro.service
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.NotificationManager
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
@@ -106,6 +107,7 @@ class TimerService : Service() {
|
|||||||
runBlocking {
|
runBlocking {
|
||||||
job.cancel()
|
job.cancel()
|
||||||
saveTimeToDb()
|
saveTimeToDb()
|
||||||
|
setDoNotDisturb(false)
|
||||||
notificationManager.cancel(1)
|
notificationManager.cancel(1)
|
||||||
alarm?.release()
|
alarm?.release()
|
||||||
}
|
}
|
||||||
@@ -140,6 +142,7 @@ class TimerService : Service() {
|
|||||||
updateProgressSegments()
|
updateProgressSegments()
|
||||||
|
|
||||||
if (timerState.value.timerRunning) {
|
if (timerState.value.timerRunning) {
|
||||||
|
setDoNotDisturb(false)
|
||||||
notificationBuilder.clearActions().addTimerActions(
|
notificationBuilder.clearActions().addTimerActions(
|
||||||
this, R.drawable.play, getString(R.string.start)
|
this, R.drawable.play, getString(R.string.start)
|
||||||
)
|
)
|
||||||
@@ -149,6 +152,8 @@ class TimerService : Service() {
|
|||||||
}
|
}
|
||||||
pauseTime = SystemClock.elapsedRealtime()
|
pauseTime = SystemClock.elapsedRealtime()
|
||||||
} else {
|
} else {
|
||||||
|
if (timerState.value.timerMode == TimerMode.FOCUS) setDoNotDisturb(true)
|
||||||
|
else setDoNotDisturb(false)
|
||||||
notificationBuilder.clearActions().addTimerActions(
|
notificationBuilder.clearActions().addTimerActions(
|
||||||
this, R.drawable.pause, getString(R.string.stop)
|
this, R.drawable.pause, getString(R.string.stop)
|
||||||
)
|
)
|
||||||
@@ -337,6 +342,7 @@ class TimerService : Service() {
|
|||||||
cycles = (cycles + 1) % (timerRepository.sessionLength * 2)
|
cycles = (cycles + 1) % (timerRepository.sessionLength * 2)
|
||||||
|
|
||||||
if (cycles % 2 == 0) {
|
if (cycles % 2 == 0) {
|
||||||
|
if (timerState.value.timerRunning) setDoNotDisturb(true)
|
||||||
time = timerRepository.focusTime
|
time = timerRepository.focusTime
|
||||||
_timerState.update { currentState ->
|
_timerState.update { currentState ->
|
||||||
currentState.copy(
|
currentState.copy(
|
||||||
@@ -354,6 +360,7 @@ class TimerService : Service() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (timerState.value.timerRunning) setDoNotDisturb(false)
|
||||||
val long = cycles == (timerRepository.sessionLength * 2) - 1
|
val long = cycles == (timerRepository.sessionLength * 2) - 1
|
||||||
time = if (long) timerRepository.longBreakTime else timerRepository.shortBreakTime
|
time = if (long) timerRepository.longBreakTime else timerRepository.shortBreakTime
|
||||||
|
|
||||||
@@ -441,7 +448,15 @@ class TimerService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAlarmTone() {
|
private fun setDoNotDisturb(doNotDisturb: Boolean) {
|
||||||
|
if (notificationManagerService.isNotificationPolicyAccessGranted()) {
|
||||||
|
if (doNotDisturb) {
|
||||||
|
notificationManagerService.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALARMS)
|
||||||
|
} else notificationManagerService.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateAlarmTone() {
|
||||||
alarm?.release()
|
alarm?.release()
|
||||||
alarm = initializeMediaPlayer()
|
alarm = initializeMediaPlayer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2025 Nishant Mishra
|
* Copyright (c) 2025 Nishant Mishra
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* This file is part of Tomato - a minimalist pomodoro timer for Android.
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
*
|
||||||
|
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||||
|
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Tomato.
|
||||||
|
* If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.nsh07.pomodoro.ui.timerScreen
|
package org.nsh07.pomodoro.ui.timerScreen
|
||||||
@@ -92,6 +102,7 @@ import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerAction
|
|||||||
import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerMode
|
import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerMode
|
||||||
import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerState
|
import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerState
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun SharedTransitionScope.TimerScreen(
|
fun SharedTransitionScope.TimerScreen(
|
||||||
|
|||||||
Reference in New Issue
Block a user