Skip to content

Commit

Permalink
Merge pull request #218 from VishnuSanal/main
Browse files Browse the repository at this point in the history
fix: keep screen on while stopwatch in progress
  • Loading branch information
Bnyro authored Nov 20, 2023
2 parents 630d616 + ae5458d commit 9b15f2b
Showing 1 changed file with 19 additions and 1 deletion.
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
}
}
}

0 comments on commit 9b15f2b

Please sign in to comment.