wrap SessionScreen in route
This commit is contained in:
parent
f1efad5120
commit
6bfa96bab7
3 changed files with 86 additions and 34 deletions
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
|
@ -1,4 +1,3 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
|
|
|
@ -29,6 +29,7 @@ import be.ugent.sel.studeez.screens.home.HomeRoute
|
||||||
import be.ugent.sel.studeez.screens.log_in.LoginRoute
|
import be.ugent.sel.studeez.screens.log_in.LoginRoute
|
||||||
import be.ugent.sel.studeez.screens.profile.EditProfileRoute
|
import be.ugent.sel.studeez.screens.profile.EditProfileRoute
|
||||||
import be.ugent.sel.studeez.screens.profile.ProfileRoute
|
import be.ugent.sel.studeez.screens.profile.ProfileRoute
|
||||||
|
import be.ugent.sel.studeez.screens.session.SessionRoute
|
||||||
import be.ugent.sel.studeez.screens.session.SessionScreen
|
import be.ugent.sel.studeez.screens.session.SessionScreen
|
||||||
import be.ugent.sel.studeez.screens.sign_up.SignUpRoute
|
import be.ugent.sel.studeez.screens.sign_up.SignUpRoute
|
||||||
import be.ugent.sel.studeez.screens.splash.SplashRoute
|
import be.ugent.sel.studeez.screens.splash.SplashRoute
|
||||||
|
@ -128,7 +129,7 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(StudeezDestinations.SESSION_SCREEN) {
|
composable(StudeezDestinations.SESSION_SCREEN) {
|
||||||
SessionScreen(open, openAndPopUp)
|
SessionRoute(open, viewModel = hiltViewModel())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Timers screen
|
// TODO Timers screen
|
||||||
|
|
|
@ -10,38 +10,61 @@ import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.Button
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.material.TextButton
|
import androidx.compose.material.TextButton
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
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.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
|
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
|
||||||
import be.ugent.sel.studeez.R
|
import be.ugent.sel.studeez.R
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer.StudyState
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer.StudyState
|
||||||
|
import be.ugent.sel.studeez.navigation.StudeezDestinations
|
||||||
import be.ugent.sel.studeez.resources
|
import be.ugent.sel.studeez.resources
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
var timerEnd = false
|
var timerEnd = false
|
||||||
|
|
||||||
|
data class SessionActions(
|
||||||
|
val getTimer: () -> FunctionalTimer,
|
||||||
|
val getTask: () -> String,
|
||||||
|
val prepareMediaPlayer: () -> Unit,
|
||||||
|
val releaseMediaPlayer: () -> Unit,
|
||||||
|
val play: () -> Unit,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getSessionActions(
|
||||||
|
viewModel: SessionViewModel,
|
||||||
|
mediaplayer: MediaPlayer,
|
||||||
|
): SessionActions {
|
||||||
|
return SessionActions(
|
||||||
|
getTimer = viewModel::getTimer,
|
||||||
|
getTask = viewModel::getTask,
|
||||||
|
prepareMediaPlayer = mediaplayer::prepare,
|
||||||
|
releaseMediaPlayer = mediaplayer::release,
|
||||||
|
play = mediaplayer::start,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SessionScreen(
|
fun SessionRoute(
|
||||||
open: (String) -> Unit,
|
open: (String) -> Unit,
|
||||||
openAndPopUp: (String, String) -> Unit,
|
viewModel: SessionViewModel,
|
||||||
viewModel: SessionViewModel = hiltViewModel()
|
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||||
|
@ -57,24 +80,34 @@ fun SessionScreen(
|
||||||
mediaplayer.setOnPreparedListener {
|
mediaplayer.setOnPreparedListener {
|
||||||
mediaplayer.start()
|
mediaplayer.start()
|
||||||
}
|
}
|
||||||
|
SessionScreen(
|
||||||
|
open = open,
|
||||||
|
sessionActions = getSessionActions(viewModel, mediaplayer),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SessionScreen(
|
||||||
|
open: (String) -> Unit,
|
||||||
|
sessionActions: SessionActions,
|
||||||
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(10.dp)
|
modifier = Modifier.padding(10.dp)
|
||||||
) {
|
) {
|
||||||
Timer(viewModel, mediaplayer)
|
Timer(
|
||||||
|
sessionActions = sessionActions,
|
||||||
|
)
|
||||||
Box(
|
Box(
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center, modifier = Modifier
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(50.dp)
|
.padding(50.dp)
|
||||||
) {
|
) {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
mediaplayer.release()
|
sessionActions.releaseMediaPlayer
|
||||||
open(StudeezDestinations.HOME_SCREEN)
|
open(StudeezDestinations.HOME_SCREEN)
|
||||||
// Vanaf hier ook naar report gaan als "end session" knop word ingedrukt
|
// Vanaf hier ook naar report gaan als "end session" knop word ingedrukt
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(horizontal = 20.dp)
|
.padding(horizontal = 20.dp)
|
||||||
.border(1.dp, Color.Red, RoundedCornerShape(32.dp))
|
.border(1.dp, Color.Red, RoundedCornerShape(32.dp))
|
||||||
|
@ -89,28 +122,37 @@ fun SessionScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Button(onClick = sessionActions.play) {
|
||||||
|
// Text(text = "Play")
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun Timer(viewModel: SessionViewModel = hiltViewModel(), mediaplayer: MediaPlayer) {
|
private fun Timer(
|
||||||
|
sessionActions: SessionActions,
|
||||||
|
) {
|
||||||
var tikker by remember { mutableStateOf(false) }
|
var tikker by remember { mutableStateOf(false) }
|
||||||
LaunchedEffect(tikker) {
|
LaunchedEffect(tikker) {
|
||||||
delay(1.seconds)
|
delay(1.seconds)
|
||||||
viewModel.getTimer().tick()
|
sessionActions.getTimer().tick()
|
||||||
tikker = !tikker
|
tikker = !tikker
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewModel.getTimer().hasCurrentCountdownEnded() && !viewModel.getTimer().hasEnded()) {
|
if (
|
||||||
mediaplayer.prepare()
|
sessionActions.getTimer().hasCurrentCountdownEnded() && !sessionActions.getTimer()
|
||||||
|
.hasEnded()
|
||||||
|
) {
|
||||||
|
sessionActions.prepareMediaPlayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!timerEnd && viewModel.getTimer().hasEnded()) {
|
if (!timerEnd && sessionActions.getTimer().hasEnded()) {
|
||||||
mediaplayer.prepare()
|
sessionActions.prepareMediaPlayer()
|
||||||
timerEnd = true // Placeholder, vanaf hier moet het report opgestart worden en de sessie afgesloten
|
timerEnd =
|
||||||
|
true // Placeholder, vanaf hier moet het report opgestart worden en de sessie afgesloten
|
||||||
}
|
}
|
||||||
|
|
||||||
val hms = viewModel.getTimer().getHoursMinutesSeconds()
|
val hms = sessionActions.getTimer().getHoursMinutesSeconds()
|
||||||
Column {
|
Column {
|
||||||
Text(
|
Text(
|
||||||
text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}",
|
text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}",
|
||||||
|
@ -121,13 +163,12 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel(), mediaplayer: Me
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontSize = 40.sp,
|
fontSize = 40.sp,
|
||||||
)
|
)
|
||||||
val stateString: String = when (viewModel.getTimer().view) {
|
val stateString: String = when (sessionActions.getTimer().view) {
|
||||||
StudyState.DONE -> resources().getString(R.string.state_done)
|
StudyState.DONE -> resources().getString(R.string.state_done)
|
||||||
StudyState.FOCUS -> resources().getString(R.string.state_focus)
|
StudyState.FOCUS -> resources().getString(R.string.state_focus)
|
||||||
StudyState.BREAK -> resources().getString(R.string.state_take_a_break)
|
StudyState.BREAK -> resources().getString(R.string.state_take_a_break)
|
||||||
StudyState.FOCUS_REMAINING ->
|
StudyState.FOCUS_REMAINING -> (sessionActions.getTimer() as FunctionalPomodoroTimer?)?.breaksRemaining?.let {
|
||||||
(viewModel.getTimer() as FunctionalPomodoroTimer?)?.breaksRemaining?.let {
|
resources().getQuantityString(R.plurals.state_focus_remaining, it, it)
|
||||||
resources().getQuantityString(R.plurals.state_focus_remaining, it, it)
|
|
||||||
}.toString()
|
}.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +181,7 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel(), mediaplayer: Me
|
||||||
)
|
)
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center, modifier = Modifier
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(50.dp)
|
.padding(50.dp)
|
||||||
) {
|
) {
|
||||||
|
@ -152,16 +192,28 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel(), mediaplayer: Me
|
||||||
.background(Color.Blue, RoundedCornerShape(32.dp))
|
.background(Color.Blue, RoundedCornerShape(32.dp))
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = viewModel.getTask(),
|
text = sessionActions.getTask(),
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
fontSize = 18.sp,
|
fontSize = 18.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier
|
modifier = Modifier.padding(vertical = 4.dp, horizontal = 20.dp)
|
||||||
.padding(vertical = 4.dp, horizontal = 20.dp)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun TimerPreview() {
|
||||||
|
Timer(sessionActions = SessionActions({ FunctionalEndlessTimer() }, { "Preview" }, {}, {}, {}))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun SessionPreview() {
|
||||||
|
SessionScreen(
|
||||||
|
open = {},
|
||||||
|
sessionActions = SessionActions({ FunctionalEndlessTimer() }, { "Preview" }, {}, {}, {})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Reference in a new issue