Skip to content

Commit 678a86e

Browse files
committed
feat(timer): reduce timer update frequency in AOD mode
1 parent b363f5f commit 678a86e

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

app/src/main/java/org/nsh07/pomodoro/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ class MainActivity : ComponentActivity() {
7474

7575
AppScreen(
7676
timerViewModel = timerViewModel,
77-
isAODEnabled = preferencesState.aodEnabled
77+
isAODEnabled = preferencesState.aodEnabled,
78+
setTimerFrequency = {
79+
appContainer.appTimerRepository.timerFrequency = it
80+
}
7881
)
7982
}
8083
}

app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
/*
22
* Copyright (c) 2025 Nishant Mishra
33
*
4-
* You should have received a copy of the GNU General Public License
5-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
4+
* This file is part of Tomato - a minimalist pomodoro timer for Android.
5+
*
6+
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
7+
* General Public License as published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
11+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12+
* Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with Tomato.
15+
* If not, see <https://www.gnu.org/licenses/>.
616
*/
717

818
package org.nsh07.pomodoro.ui
@@ -76,6 +86,7 @@ import kotlin.random.Random
7686
fun SharedTransitionScope.AlwaysOnDisplay(
7787
timerState: TimerState,
7888
progress: () -> Float,
89+
setTimerFrequency: (Float) -> Unit,
7990
modifier: Modifier = Modifier
8091
) {
8192
var sharedElementTransitionComplete by remember { mutableStateOf(false) }
@@ -89,6 +100,7 @@ fun SharedTransitionScope.AlwaysOnDisplay(
89100
val insetsController = remember { WindowCompat.getInsetsController(window, view) }
90101

91102
DisposableEffect(Unit) {
103+
setTimerFrequency(1f)
92104
window.addFlags(
93105
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
94106
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
@@ -102,6 +114,7 @@ fun SharedTransitionScope.AlwaysOnDisplay(
102114
}
103115

104116
onDispose {
117+
setTimerFrequency(10f)
105118
window.clearFlags(
106119
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
107120
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
@@ -263,7 +276,8 @@ private fun AlwaysOnDisplayPreview() {
263276
SharedTransitionLayout {
264277
AlwaysOnDisplay(
265278
timerState = timerState,
266-
progress = progress
279+
progress = progress,
280+
setTimerFrequency = {}
267281
)
268282
}
269283
}

app/src/main/java/org/nsh07/pomodoro/ui/AppScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerViewModel
6767
fun AppScreen(
6868
modifier: Modifier = Modifier,
6969
timerViewModel: TimerViewModel = viewModel(factory = TimerViewModel.Factory),
70-
isAODEnabled: Boolean
70+
isAODEnabled: Boolean,
71+
setTimerFrequency: (Float) -> Unit
7172
) {
7273
val context = LocalContext.current
7374

@@ -204,6 +205,7 @@ fun AppScreen(
204205
AlwaysOnDisplay(
205206
timerState = uiState,
206207
progress = { progress },
208+
setTimerFrequency = setTimerFrequency,
207209
modifier = Modifier
208210
.then(
209211
if (isAODEnabled) Modifier.clickable {

0 commit comments

Comments
 (0)