werkende timers
This commit is contained in:
parent
199b4c2f6f
commit
ecea5746f4
7 changed files with 66 additions and 38 deletions
|
@ -26,6 +26,7 @@ import be.ugent.sel.studeez.screens.profile.ProfileScreen
|
||||||
import be.ugent.sel.studeez.screens.sign_up.SignUpScreen
|
import be.ugent.sel.studeez.screens.sign_up.SignUpScreen
|
||||||
import be.ugent.sel.studeez.screens.splash.SplashScreen
|
import be.ugent.sel.studeez.screens.splash.SplashScreen
|
||||||
import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewScreen
|
import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewScreen
|
||||||
|
import be.ugent.sel.studeez.screens.timers.TimerSelectionScreen
|
||||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
||||||
|
@ -130,4 +131,8 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) {
|
||||||
composable(StudeezDestinations.EDIT_PROFILE_SCREEN) {
|
composable(StudeezDestinations.EDIT_PROFILE_SCREEN) {
|
||||||
EditProfileScreen(goBack, openAndPopUp)
|
EditProfileScreen(goBack, openAndPopUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable(StudeezDestinations.TIMER_SELECTION_SCREEN) {
|
||||||
|
TimerSelectionScreen(open, openAndPopUp)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ object StudeezDestinations {
|
||||||
|
|
||||||
const val HOME_SCREEN = "home"
|
const val HOME_SCREEN = "home"
|
||||||
const val TIMER_OVERVIEW_SCREEN = "timer_overview"
|
const val TIMER_OVERVIEW_SCREEN = "timer_overview"
|
||||||
|
const val TIMER_SELECTION_SCREEN = "timer_selection"
|
||||||
const val SESSION_SCREEN = "session"
|
const val SESSION_SCREEN = "session"
|
||||||
// const val TASKS_SCREEN = "tasks"
|
// const val TASKS_SCREEN = "tasks"
|
||||||
// const val SESSIONS_SCREEN = "sessions"
|
// const val SESSIONS_SCREEN = "sessions"
|
||||||
|
|
|
@ -15,7 +15,7 @@ class HomeViewModel @Inject constructor(
|
||||||
logService: LogService
|
logService: LogService
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
fun onStartSessionClick(openAndPopUp: (String) -> Unit) {
|
fun onStartSessionClick(open: (String) -> Unit) {
|
||||||
openAndPopUp(StudeezDestinations.SESSION_SCREEN)
|
open(StudeezDestinations.TIMER_SELECTION_SCREEN)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,33 +14,33 @@ 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.resources
|
import be.ugent.sel.studeez.resources
|
||||||
|
import be.ugent.sel.studeez.screens.timers.TimerSelectionViewModel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SessionScreen(
|
fun SessionScreen(
|
||||||
open: (String) -> Unit,
|
open: (String) -> Unit,
|
||||||
openAndPopUp: (String, String) -> Unit,
|
openAndPopUp: (String, String) -> Unit,
|
||||||
viewModel: SessionViewModel = hiltViewModel()
|
|
||||||
) {
|
) {
|
||||||
PrimaryScreenTemplate(
|
PrimaryScreenTemplate(
|
||||||
title = resources().getString(R.string.start_session),
|
title = resources().getString(R.string.start_session),
|
||||||
open = open,
|
open = open,
|
||||||
openAndPopUp = openAndPopUp
|
openAndPopUp = openAndPopUp
|
||||||
) {
|
) {
|
||||||
Timer(viewModel)
|
Timer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun Timer(viewModel: SessionViewModel = hiltViewModel()) {
|
fun Timer(viewModel: TimerSelectionViewModel = hiltViewModel()) {
|
||||||
var tikker by remember { mutableStateOf(false) }
|
var tikker by remember { mutableStateOf(false) }
|
||||||
LaunchedEffect(tikker) {
|
LaunchedEffect(tikker) {
|
||||||
delay(1000)
|
delay(1000)
|
||||||
viewModel.getTimer().tick()
|
viewModel.sessionTimer!!.tick()
|
||||||
tikker = !tikker
|
tikker = !tikker
|
||||||
}
|
}
|
||||||
|
|
||||||
val hms = viewModel.getTimer().getHoursMinutesSeconds()
|
val hms = viewModel.sessionTimer!!.getHoursMinutesSeconds()
|
||||||
Column {
|
Column {
|
||||||
Text(
|
Text(
|
||||||
text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}",
|
text = "${hms.hours} : ${hms.minutes} : ${hms.seconds}",
|
||||||
|
@ -50,7 +50,7 @@ private fun Timer(viewModel: SessionViewModel = hiltViewModel()) {
|
||||||
fontSize = 80.sp
|
fontSize = 80.sp
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = viewModel.getTimer().getViewString(),
|
text = viewModel.sessionTimer!!.getViewString(),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
fontWeight = FontWeight.Light,
|
fontWeight = FontWeight.Light,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package be.ugent.sel.studeez.screens.timer_overview
|
package be.ugent.sel.studeez.screens.timer_overview
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
@ -46,12 +47,12 @@ fun TimerOverviewScreen(
|
||||||
) {
|
) {
|
||||||
// Default Timers, cannot be edited
|
// Default Timers, cannot be edited
|
||||||
items(viewModel.getDefaultTimers()) {
|
items(viewModel.getDefaultTimers()) {
|
||||||
TimerEntry(timerInfo = it, canEdit = false)
|
TimerEntry(timerInfo = it, canDisplay = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// User timers, can be edited
|
// User timers, can be edited
|
||||||
items(timers.value) {
|
items(timers.value) {
|
||||||
TimerEntry(timerInfo = it, true) { timerInfo ->
|
TimerEntry(timerInfo = it, true, R.string.edit) { timerInfo ->
|
||||||
viewModel.update(timerInfo)
|
viewModel.update(timerInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,12 @@ fun TimerOverviewScreen(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimerEntry(timerInfo: TimerInfo, canEdit: Boolean, update: (TimerInfo) -> Unit = {}) {
|
fun TimerEntry(
|
||||||
|
timerInfo: TimerInfo,
|
||||||
|
canDisplay: Boolean,
|
||||||
|
@StringRes buttonName: Int = -1,
|
||||||
|
buttonFunction: (TimerInfo) -> Unit = {}
|
||||||
|
) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
@ -83,9 +89,9 @@ fun TimerEntry(timerInfo: TimerInfo, canEdit: Boolean, update: (TimerInfo) -> Un
|
||||||
fontSize = 15.sp
|
fontSize = 15.sp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (canEdit) {
|
if (canDisplay) {
|
||||||
BasicButton(R.string.edit, Modifier.card()) {
|
BasicButton(buttonName, Modifier.card()) {
|
||||||
// TODO
|
buttonFunction(timerInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,26 +4,24 @@ import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
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.BasicButton
|
|
||||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
||||||
import be.ugent.sel.studeez.common.ext.basicButton
|
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
||||||
import be.ugent.sel.studeez.resources
|
import be.ugent.sel.studeez.resources
|
||||||
|
import be.ugent.sel.studeez.screens.session.Timer
|
||||||
import be.ugent.sel.studeez.screens.timer_overview.TimerEntry
|
import be.ugent.sel.studeez.screens.timer_overview.TimerEntry
|
||||||
import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewViewModel
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimerSelectScreen(
|
fun TimerSelectionScreen(
|
||||||
open: (String) -> Unit,
|
open: (String) -> Unit,
|
||||||
openAndPopUp: (String, String) -> Unit,
|
openAndPopUp: (String, String) -> Unit,
|
||||||
viewModel: TimerSelectViewModel = hiltViewModel()
|
viewModel: TimerSelectionViewModel = hiltViewModel()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val inSession by remember { viewModel.inSession }
|
||||||
val timers = viewModel.getAllTimers().collectAsState(initial = emptyList())
|
val timers = viewModel.getAllTimers().collectAsState(initial = emptyList())
|
||||||
|
|
||||||
PrimaryScreenTemplate(
|
PrimaryScreenTemplate(
|
||||||
|
@ -32,19 +30,28 @@ fun TimerSelectScreen(
|
||||||
openAndPopUp = openAndPopUp
|
openAndPopUp = openAndPopUp
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Column {
|
if (inSession) {
|
||||||
LazyColumn(
|
Timer(viewModel)
|
||||||
verticalArrangement = Arrangement.spacedBy(7.dp)
|
} else {
|
||||||
) {
|
TimerSelection(timers = timers, viewModel = viewModel)
|
||||||
|
|
||||||
// All timers
|
|
||||||
items(timers.value) {
|
|
||||||
TimerEntry(timerInfo = it, true) { timerInfo ->
|
|
||||||
viewModel.startSession()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TimerSelection(timers: State<List<TimerInfo>>, viewModel: TimerSelectionViewModel, ) {
|
||||||
|
LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) {
|
||||||
|
|
||||||
|
// All timers
|
||||||
|
items(timers.value) {
|
||||||
|
TimerEntry(
|
||||||
|
timerInfo = it,
|
||||||
|
canDisplay = true,
|
||||||
|
buttonName = R.string.start
|
||||||
|
) { timerInfo ->
|
||||||
|
viewModel.startSession(timerInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,10 @@
|
||||||
package be.ugent.sel.studeez.screens.timers
|
package be.ugent.sel.studeez.screens.timers
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
||||||
import be.ugent.sel.studeez.domain.LogService
|
import be.ugent.sel.studeez.domain.LogService
|
||||||
import be.ugent.sel.studeez.domain.TimerDAO
|
import be.ugent.sel.studeez.domain.TimerDAO
|
||||||
|
@ -9,16 +14,20 @@ import kotlinx.coroutines.flow.Flow
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class TimerSelectViewModel @Inject constructor(
|
class TimerSelectionViewModel @Inject constructor(
|
||||||
private val timerDAO: TimerDAO,
|
private val timerDAO: TimerDAO,
|
||||||
logService: LogService
|
logService: LogService
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
|
var inSession = mutableStateOf(false)
|
||||||
|
var sessionTimer: FunctionalTimer? = null
|
||||||
|
|
||||||
fun getAllTimers() : Flow<List<TimerInfo>> {
|
fun getAllTimers() : Flow<List<TimerInfo>> {
|
||||||
return timerDAO.getAllTimers()
|
return timerDAO.getAllTimers()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startSession() {
|
fun startSession(timerInfo: TimerInfo) {
|
||||||
|
inSession.value = true
|
||||||
|
sessionTimer = timerInfo.getFunctionalTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in a new issue