feat(timer): reduce timer update frequency in AOD mode
This commit is contained in:
@@ -74,7 +74,10 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
AppScreen(
|
AppScreen(
|
||||||
timerViewModel = timerViewModel,
|
timerViewModel = timerViewModel,
|
||||||
isAODEnabled = preferencesState.aodEnabled
|
isAODEnabled = preferencesState.aodEnabled,
|
||||||
|
setTimerFrequency = {
|
||||||
|
appContainer.appTimerRepository.timerFrequency = it
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
package org.nsh07.pomodoro.ui
|
||||||
@@ -76,6 +86,7 @@ import kotlin.random.Random
|
|||||||
fun SharedTransitionScope.AlwaysOnDisplay(
|
fun SharedTransitionScope.AlwaysOnDisplay(
|
||||||
timerState: TimerState,
|
timerState: TimerState,
|
||||||
progress: () -> Float,
|
progress: () -> Float,
|
||||||
|
setTimerFrequency: (Float) -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
var sharedElementTransitionComplete by remember { mutableStateOf(false) }
|
var sharedElementTransitionComplete by remember { mutableStateOf(false) }
|
||||||
@@ -89,6 +100,7 @@ fun SharedTransitionScope.AlwaysOnDisplay(
|
|||||||
val insetsController = remember { WindowCompat.getInsetsController(window, view) }
|
val insetsController = remember { WindowCompat.getInsetsController(window, view) }
|
||||||
|
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
|
setTimerFrequency(1f)
|
||||||
window.addFlags(
|
window.addFlags(
|
||||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
|
||||||
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||||
@@ -102,6 +114,7 @@ fun SharedTransitionScope.AlwaysOnDisplay(
|
|||||||
}
|
}
|
||||||
|
|
||||||
onDispose {
|
onDispose {
|
||||||
|
setTimerFrequency(10f)
|
||||||
window.clearFlags(
|
window.clearFlags(
|
||||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
|
||||||
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||||
@@ -263,7 +276,8 @@ private fun AlwaysOnDisplayPreview() {
|
|||||||
SharedTransitionLayout {
|
SharedTransitionLayout {
|
||||||
AlwaysOnDisplay(
|
AlwaysOnDisplay(
|
||||||
timerState = timerState,
|
timerState = timerState,
|
||||||
progress = progress
|
progress = progress,
|
||||||
|
setTimerFrequency = {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerViewModel
|
|||||||
fun AppScreen(
|
fun AppScreen(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
timerViewModel: TimerViewModel = viewModel(factory = TimerViewModel.Factory),
|
timerViewModel: TimerViewModel = viewModel(factory = TimerViewModel.Factory),
|
||||||
isAODEnabled: Boolean
|
isAODEnabled: Boolean,
|
||||||
|
setTimerFrequency: (Float) -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
@@ -204,6 +205,7 @@ fun AppScreen(
|
|||||||
AlwaysOnDisplay(
|
AlwaysOnDisplay(
|
||||||
timerState = uiState,
|
timerState = uiState,
|
||||||
progress = { progress },
|
progress = { progress },
|
||||||
|
setTimerFrequency = setTimerFrequency,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.then(
|
.then(
|
||||||
if (isAODEnabled) Modifier.clickable {
|
if (isAODEnabled) Modifier.clickable {
|
||||||
|
|||||||
Reference in New Issue
Block a user