From a18d56e4d054b8aca23b134664b6f64329bf706c Mon Sep 17 00:00:00 2001 From: Nishant Mishra Date: Sat, 25 Oct 2025 13:19:08 +0530 Subject: [PATCH] feat(system): update dnd status while running the timer --- .../org/nsh07/pomodoro/service/TimerService.kt | 17 ++++++++++++++++- .../pomodoro/ui/timerScreen/TimerScreen.kt | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) 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 d1ff85f..0501044 100644 --- a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt +++ b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt @@ -18,6 +18,7 @@ package org.nsh07.pomodoro.service import android.annotation.SuppressLint +import android.app.NotificationManager import android.app.Service import android.content.Intent import android.media.AudioAttributes @@ -106,6 +107,7 @@ class TimerService : Service() { runBlocking { job.cancel() saveTimeToDb() + setDoNotDisturb(false) notificationManager.cancel(1) alarm?.release() } @@ -140,6 +142,7 @@ class TimerService : Service() { updateProgressSegments() if (timerState.value.timerRunning) { + setDoNotDisturb(false) notificationBuilder.clearActions().addTimerActions( this, R.drawable.play, getString(R.string.start) ) @@ -149,6 +152,8 @@ class TimerService : Service() { } pauseTime = SystemClock.elapsedRealtime() } else { + if (timerState.value.timerMode == TimerMode.FOCUS) setDoNotDisturb(true) + else setDoNotDisturb(false) notificationBuilder.clearActions().addTimerActions( this, R.drawable.pause, getString(R.string.stop) ) @@ -337,6 +342,7 @@ class TimerService : Service() { cycles = (cycles + 1) % (timerRepository.sessionLength * 2) if (cycles % 2 == 0) { + if (timerState.value.timerRunning) setDoNotDisturb(true) time = timerRepository.focusTime _timerState.update { currentState -> currentState.copy( @@ -354,6 +360,7 @@ class TimerService : Service() { ) } } else { + if (timerState.value.timerRunning) setDoNotDisturb(false) val long = cycles == (timerRepository.sessionLength * 2) - 1 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 = initializeMediaPlayer() } diff --git a/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/TimerScreen.kt b/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/TimerScreen.kt index 68b9094..ee77820 100644 --- a/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/TimerScreen.kt +++ b/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/TimerScreen.kt @@ -1,8 +1,18 @@ /* * Copyright (c) 2025 Nishant Mishra * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This file is part of Tomato - a minimalist pomodoro timer for Android. + * + * 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 . */ 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.TimerState + @OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class) @Composable fun SharedTransitionScope.TimerScreen(