*EditScreen -> *FormScreen

This commit is contained in:
lbarraga 2023-05-05 00:01:01 +02:00
parent 165fe4ca86
commit 86c7a0e6a8
11 changed files with 90 additions and 125 deletions

View file

@ -1,40 +0,0 @@
package be.ugent.sel.studeez.screens.timer_add
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import be.ugent.sel.studeez.R
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
data class TimerEditActions(
val getTimerInfo: () -> TimerInfo,
val saveTimer: (TimerInfo) -> Unit
)
fun getTimerAddActions(
viewModel: TimerEditViewModel,
goBack: () -> Unit
): TimerEditActions {
return TimerEditActions(
getTimerInfo = viewModel::getTimerInfo,
saveTimer = { timerInfo -> viewModel.saveTimer(timerInfo, goBack) }
)
}
@Composable
fun TimerAddRoute(
open: (String) -> Unit,
popUp: () -> Unit,
viewModel: TimerEditViewModel,
) {
val timerEditActions = getTimerAddActions(viewModel, goBack = popUp)
SecondaryScreenTemplate(title = stringResource(id = R.string.edit_timer), popUp = popUp) {
val timerEditScreen = timerEditActions.getTimerInfo().accept(GetTimerEditScreen())
timerEditScreen { timerEditActions.saveTimer(it) }
}
}

View file

@ -1,63 +0,0 @@
package be.ugent.sel.studeez.screens.timer_edit
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
import be.ugent.sel.studeez.R.string as AppText
data class TimerEditActions(
val getTimerInfo: () -> TimerInfo,
val editTimer: (TimerInfo, () -> Unit) -> Unit
)
fun getTimerEditActions(
viewModel: TimerEditViewModel,
open: (String) -> Unit
): TimerEditActions {
return TimerEditActions(
getTimerInfo = viewModel::getTimerInfo,
editTimer = viewModel::editTimer
)
}
@Composable
fun TimerEditRoute(
open: (String) -> Unit,
popUp: () -> Unit,
viewModel: TimerEditViewModel,
) {
val timerEditActions = getTimerEditActions(viewModel, open)
SecondaryScreenTemplate(title = stringResource(id = AppText.edit_timer), popUp = popUp) {
val timerEditScreen = timerEditActions.getTimerInfo().accept(GetTimerEditScreen())
timerEditScreen { timerInfo ->
timerEditActions.editTimer(timerInfo, popUp)
}
}
}

View file

@ -1,13 +1,13 @@
package be.ugent.sel.studeez.screens.timer_edit package be.ugent.sel.studeez.screens.timer_form.timer_edit
import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo
import be.ugent.sel.studeez.data.local.models.timer_info.EndlessTimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.EndlessTimerInfo
import be.ugent.sel.studeez.data.local.models.timer_info.PomodoroTimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.PomodoroTimerInfo
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfoVisitor import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfoVisitor
import be.ugent.sel.studeez.screens.timer_edit.editScreens.AbstractTimerEditScreen import be.ugent.sel.studeez.screens.timer_form.form_screens.AbstractTimerEditScreen
import be.ugent.sel.studeez.screens.timer_edit.editScreens.BreakTimerEditScreen import be.ugent.sel.studeez.screens.timer_form.form_screens.BreakTimerEditScreen
import be.ugent.sel.studeez.screens.timer_edit.editScreens.CustomTimerEditScreen import be.ugent.sel.studeez.screens.timer_form.form_screens.CustomTimerEditScreen
import be.ugent.sel.studeez.screens.timer_edit.editScreens.EndlessTimerEditScreen import be.ugent.sel.studeez.screens.timer_form.form_screens.EndlessTimerEditScreen
class GetTimerEditScreen: TimerInfoVisitor<AbstractTimerEditScreen> { class GetTimerEditScreen: TimerInfoVisitor<AbstractTimerEditScreen> {

View file

@ -0,0 +1,68 @@
package be.ugent.sel.studeez.screens.timer_form.timer_edit
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
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_form.GetTimerFormScreen
import be.ugent.sel.studeez.screens.timer_form.TimerFormViewModel
import java.util.Timer
import be.ugent.sel.studeez.R.string as AppText
@Composable
fun TimerAddRoute(
popUp: () -> Unit,
viewModel: TimerFormViewModel
) {
TimerFormScreen(popUp = popUp, getTimerInfo = viewModel::getTimerInfo, AppText.add_timer) {
viewModel.saveTimer(it, goBack = popUp)
}
}
@Composable
fun TimerEditRoute(
popUp: () -> Unit,
viewModel: TimerFormViewModel
) {
TimerFormScreen(popUp = popUp, getTimerInfo = viewModel::getTimerInfo, AppText.edit_timer) {
viewModel.editTimer(it, goBack = popUp)
}
}
@Composable
fun TimerFormScreen(
popUp: () -> Unit,
getTimerInfo: () -> TimerInfo,
@StringRes label: Int,
onConfirmClick: (TimerInfo) -> Unit
) {
val timerEditScreen = getTimerInfo().accept(GetTimerFormScreen())
SecondaryScreenTemplate(title = stringResource(id = label), popUp = popUp) {
timerEditScreen(onConfirmClick)
}
}

View file

@ -1,4 +1,4 @@
package be.ugent.sel.studeez.screens.timer_edit package be.ugent.sel.studeez.screens.timer_form.timer_edit
import be.ugent.sel.studeez.data.EditTimerState import be.ugent.sel.studeez.data.EditTimerState
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo

View file

@ -1,4 +1,4 @@
package be.ugent.sel.studeez.screens.timer_edit.editScreens package be.ugent.sel.studeez.screens.timer_form.form_screens
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@ -16,7 +16,7 @@ import be.ugent.sel.studeez.common.ext.basicButton
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.R.string as AppText import be.ugent.sel.studeez.R.string as AppText
abstract class AbstractTimerEditScreen(private val timerInfo: TimerInfo) { abstract class AbstractTimerFormScreen(private val timerInfo: TimerInfo) {
@Composable @Composable
operator fun invoke(onSaveClick: (TimerInfo) -> Unit) { operator fun invoke(onSaveClick: (TimerInfo) -> Unit) {

View file

@ -1,4 +1,4 @@
package be.ugent.sel.studeez.screens.timer_edit.editScreens package be.ugent.sel.studeez.screens.timer_form.form_screens
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
@ -11,9 +11,9 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme
import be.ugent.sel.studeez.R.string as AppText import be.ugent.sel.studeez.R.string as AppText
class BreakTimerEditScreen( class BreakTimerFormScreen(
private val breakTimerInfo: PomodoroTimerInfo private val breakTimerInfo: PomodoroTimerInfo
): AbstractTimerEditScreen(breakTimerInfo) { ): AbstractTimerFormScreen(breakTimerInfo) {
@Composable @Composable
override fun ExtraFields() { override fun ExtraFields() {
@ -50,6 +50,6 @@ fun BreakEditScreenPreview() {
5 5
) )
StudeezTheme { StudeezTheme {
BreakTimerEditScreen(pomodoroTimerInfo).invoke(onSaveClick = {}) BreakTimerFormScreen(pomodoroTimerInfo).invoke(onSaveClick = {})
} }
} }

View file

@ -1,4 +1,4 @@
package be.ugent.sel.studeez.screens.timer_edit.editScreens package be.ugent.sel.studeez.screens.timer_form.form_screens
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -7,9 +7,9 @@ import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo
import be.ugent.sel.studeez.ui.theme.StudeezTheme import be.ugent.sel.studeez.ui.theme.StudeezTheme
import be.ugent.sel.studeez.R.string as AppText import be.ugent.sel.studeez.R.string as AppText
class CustomTimerEditScreen( class CustomTimerFormScreen(
private val customTimerInfo: CustomTimerInfo private val customTimerInfo: CustomTimerInfo
): AbstractTimerEditScreen(customTimerInfo) { ): AbstractTimerFormScreen(customTimerInfo) {
@Composable @Composable
override fun ExtraFields() { override fun ExtraFields() {
@ -29,6 +29,6 @@ class CustomTimerEditScreen(
fun CustomEditScreenPreview() { fun CustomEditScreenPreview() {
val customTimerInfo = CustomTimerInfo("custom", "my description", 25) val customTimerInfo = CustomTimerInfo("custom", "my description", 25)
StudeezTheme { StudeezTheme {
CustomTimerEditScreen(customTimerInfo).invoke(onSaveClick = {}) CustomTimerFormScreen(customTimerInfo).invoke(onSaveClick = {})
} }
} }

View file

@ -1,13 +1,13 @@
package be.ugent.sel.studeez.screens.timer_edit.editScreens package be.ugent.sel.studeez.screens.timer_form.form_screens
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import be.ugent.sel.studeez.data.local.models.timer_info.EndlessTimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.EndlessTimerInfo
import be.ugent.sel.studeez.ui.theme.StudeezTheme import be.ugent.sel.studeez.ui.theme.StudeezTheme
class EndlessTimerEditScreen( class EndlessTimerFormScreen(
endlessTimerInfo: EndlessTimerInfo endlessTimerInfo: EndlessTimerInfo
): AbstractTimerEditScreen(endlessTimerInfo) { ): AbstractTimerFormScreen(endlessTimerInfo) {
} }
@Preview @Preview
@ -18,6 +18,6 @@ fun EndlessEditScreenPreview() {
"My endless timer description", "My endless timer description",
) )
StudeezTheme { StudeezTheme {
EndlessTimerEditScreen(endlessTimerInfo).invoke(onSaveClick = {}) EndlessTimerFormScreen(endlessTimerInfo).invoke(onSaveClick = {})
} }
} }

View file

@ -1,4 +1,4 @@
package be.ugent.sel.studeez.screens.timer_add package be.ugent.sel.studeez.screens.timer_form.timer_add
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth

View file

@ -1,4 +1,4 @@
package be.ugent.sel.studeez.screens.timer_add package be.ugent.sel.studeez.screens.timer_form.timer_add
import be.ugent.sel.studeez.data.EditTimerState import be.ugent.sel.studeez.data.EditTimerState
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo