removed own add screenn (niet dat van Rune) + minor refactor
This commit is contained in:
parent
61b3c87142
commit
7934154af9
4 changed files with 2 additions and 75 deletions
|
@ -1,44 +0,0 @@
|
||||||
package be.ugent.sel.studeez.screens.timer_add
|
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
|
||||||
import be.ugent.sel.studeez.screens.timer_edit.GetTimerEditScreen
|
|
||||||
import be.ugent.sel.studeez.screens.timer_edit.TimerEditViewModel
|
|
||||||
import be.ugent.sel.studeez.screens.timer_edit.editScreens.AbstractTimerEditScreen
|
|
||||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
|
||||||
|
|
||||||
data class TimerEditActions(
|
|
||||||
val getTimerInfo: () -> TimerInfo,
|
|
||||||
val saveTimer: (TimerInfo, () -> Unit) -> Unit
|
|
||||||
)
|
|
||||||
|
|
||||||
fun getTimerEditActions(
|
|
||||||
viewModel: TimerEditViewModel,
|
|
||||||
open: (String) -> Unit
|
|
||||||
): TimerEditActions {
|
|
||||||
return TimerEditActions(
|
|
||||||
getTimerInfo = viewModel::getTimerInfo,
|
|
||||||
saveTimer = viewModel::saveTimer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun TimerEditRoute(
|
|
||||||
open: (String) -> Unit,
|
|
||||||
popUp: () -> Unit,
|
|
||||||
viewModel: TimerEditViewModel,
|
|
||||||
) {
|
|
||||||
|
|
||||||
val timerEditActions = getTimerEditActions(viewModel, open)
|
|
||||||
|
|
||||||
SecondaryScreenTemplate(title = "Edit Timer", popUp = popUp) {
|
|
||||||
|
|
||||||
val timerEditScreen = timerEditActions.getTimerInfo().accept(GetTimerEditScreen())
|
|
||||||
timerEditScreen { timerInfo ->
|
|
||||||
timerEditActions.saveTimer(timerInfo, popUp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package be.ugent.sel.studeez.screens.timer_add
|
|
||||||
|
|
||||||
import be.ugent.sel.studeez.data.EditTimerState
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
|
||||||
import be.ugent.sel.studeez.domain.LogService
|
|
||||||
import be.ugent.sel.studeez.domain.TimerDAO
|
|
||||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltViewModel
|
|
||||||
class TimerAddViewModel @Inject constructor(
|
|
||||||
private val editTimerState: EditTimerState,
|
|
||||||
private val timerDAO: TimerDAO,
|
|
||||||
logService: LogService
|
|
||||||
) : StudeezViewModel(logService) {
|
|
||||||
|
|
||||||
private val timerInfo: TimerInfo = editTimerState.timerInfo
|
|
||||||
|
|
||||||
fun getTimerInfo(): TimerInfo {
|
|
||||||
return timerInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveTimer(timerInfo: TimerInfo, goBack: () -> Unit) {
|
|
||||||
timerDAO.updateTimer(timerInfo)
|
|
||||||
goBack()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -34,7 +34,8 @@ fun TimerTypeSelectScreen(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
TimerType.values().forEach { timerType ->
|
TimerType.values().forEach { timerType ->
|
||||||
Button(onClick = { viewModel.onTimerTypeChosen(defaultTimerInfo[timerType]!!, open) }) {
|
val default: TimerInfo = defaultTimerInfo.getValue(timerType)
|
||||||
|
Button(onClick = { viewModel.onTimerTypeChosen(default, open) }) {
|
||||||
Text(text = timerType.name)
|
Text(text = timerType.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import javax.inject.Inject
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class TimerTypeSelectViewModel @Inject constructor(
|
class TimerTypeSelectViewModel @Inject constructor(
|
||||||
private val editTimerState: EditTimerState,
|
private val editTimerState: EditTimerState,
|
||||||
private val timerDAO: TimerDAO,
|
|
||||||
logService: LogService
|
logService: LogService
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
|
|
Reference in a new issue