Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep screen on while stopwatch in progress #218

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/src/main/java/com/bnyro/clock/ui/screens/StopwatchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import androidx.compose.material3.LargeFloatingActionButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.bnyro.clock.R
Expand All @@ -56,7 +58,9 @@ fun StopwatchScreen(onClickSettings: () -> Unit, stopwatchModel: StopwatchModel)
val timeStampsState = rememberLazyListState()
TopBarScaffold(title = stringResource(R.string.stopwatch), onClickSettings) { pv ->
Column(
modifier = Modifier.fillMaxSize().padding(pv),
modifier = Modifier
.fillMaxSize()
.padding(pv),
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
Expand Down Expand Up @@ -187,4 +191,18 @@ fun StopwatchScreen(onClickSettings: () -> Unit, stopwatchModel: StopwatchModel)
}
}
}
if (stopwatchModel.scheduledObject.state.value == WatchState.RUNNING)
KeepScreenOn()
}

//https://stackoverflow.com/a/71293123/9652621
@Composable
fun KeepScreenOn() {
val currentView = LocalView.current
DisposableEffect(Unit) {
currentView.keepScreenOn = true
onDispose {
currentView.keepScreenOn = false
}
}
}
Loading