#26 timer can be displayed

This commit is contained in:
Lukas Barragan Torres 2023-04-18 10:40:05 +02:00
parent e3e3eaf1fa
commit b2d010ff3f

View file

@ -7,40 +7,39 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import be.ugent.sel.studeez.R import be.ugent.sel.studeez.R
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.resources
import be.ugent.sel.studeez.screens.timers.TimerSelectionViewModel
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.seconds
@Composable @Composable
fun SessionScreen( fun SessionScreen(
open: (String) -> Unit, open: (String) -> Unit,
openAndPopUp: (String, String) -> Unit, openAndPopUp: (String, String) -> Unit,
) { ) {
PrimaryScreenTemplate( SecondaryScreenTemplate(
title = resources().getString(R.string.start_session), title = resources().getString(R.string.start_session),
open = open, popUp = {},
openAndPopUp = openAndPopUp content = { Timer() }
) { )
Timer()
}
} }
@Composable @Composable
fun Timer(viewModel: TimerSelectionViewModel = hiltViewModel()) { fun Timer(viewModel: SessionViewModel = hiltViewModel()) {
var tikker by remember { mutableStateOf(false) }
LaunchedEffect(tikker) {
delay(1000) var ticker by remember { mutableStateOf(false) }
viewModel.sessionTimer!!.tick() LaunchedEffect(ticker) {
tikker = !tikker delay(1.seconds)
viewModel.getTimer().tick()
ticker = !ticker
} }
val hms = viewModel.sessionTimer!!.getHoursMinutesSeconds() val hms = viewModel.getTimer().getHoursMinutesSeconds()
Column { Column {
Text( Text(
text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}", text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}",
@ -50,7 +49,7 @@ fun Timer(viewModel: TimerSelectionViewModel = hiltViewModel()) {
fontSize = 80.sp fontSize = 80.sp
) )
Text( Text(
text = viewModel.sessionTimer!!.getViewString(), text = viewModel.getTimer().getViewString(),
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
fontWeight = FontWeight.Light, fontWeight = FontWeight.Light,