#15 make form functional
This commit is contained in:
parent
831050f3f2
commit
fc1d12e214
8 changed files with 48 additions and 40 deletions
|
@ -42,6 +42,8 @@ import be.ugent.sel.studeez.screens.sign_up.SignUpRoute
|
|||
import be.ugent.sel.studeez.screens.splash.SplashRoute
|
||||
import be.ugent.sel.studeez.screens.tasks.SubjectRoute
|
||||
import be.ugent.sel.studeez.screens.tasks.TaskRoute
|
||||
import be.ugent.sel.studeez.screens.tasks.forms.SubjectAddRoute
|
||||
import be.ugent.sel.studeez.screens.tasks.forms.SubjectEditRoute
|
||||
import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewRoute
|
||||
import be.ugent.sel.studeez.screens.timer_selection.TimerSelectionRoute
|
||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||
|
@ -156,6 +158,22 @@ fun StudeezNavGraph(
|
|||
)
|
||||
}
|
||||
|
||||
composable(StudeezDestinations.ADD_SUBJECT_FORM) {
|
||||
SubjectAddRoute(
|
||||
goBack = goBack,
|
||||
open = open,
|
||||
viewModel = hiltViewModel(),
|
||||
)
|
||||
}
|
||||
|
||||
composable(StudeezDestinations.EDIT_SUBJECT_FORM) {
|
||||
SubjectEditRoute(
|
||||
goBack = goBack,
|
||||
open = open,
|
||||
viewModel = hiltViewModel(),
|
||||
)
|
||||
}
|
||||
|
||||
composable(StudeezDestinations.TASKS_SCREEN) {
|
||||
TaskRoute(
|
||||
goBack = goBack,
|
||||
|
|
|
@ -10,7 +10,10 @@ object StudeezDestinations {
|
|||
const val TIMER_SELECTION_SCREEN = "timer_selection"
|
||||
const val SESSION_SCREEN = "session"
|
||||
const val SESSION_RECAP = "session_recap"
|
||||
|
||||
const val SUBJECT_SCREEN = "subjects"
|
||||
const val ADD_SUBJECT_FORM = "add_subject"
|
||||
const val EDIT_SUBJECT_FORM = "edit_subject"
|
||||
const val TASKS_SCREEN = "tasks"
|
||||
|
||||
// const val SESSIONS_SCREEN = "sessions"
|
||||
|
|
|
@ -30,7 +30,7 @@ fun SubjectRoute(
|
|||
SubjectScreen(
|
||||
drawerActions = drawerActions,
|
||||
navigationBarActions = navigationBarActions,
|
||||
addSubject = { viewModel.addSubject() },
|
||||
addSubject = { viewModel.addSubject(open) },
|
||||
getSubjects = viewModel::getSubjects,
|
||||
onViewSubject = { viewModel.onViewSubject(it, open) },
|
||||
)
|
||||
|
@ -55,19 +55,6 @@ fun SubjectScreen(
|
|||
modifier = Modifier.padding(top = 5.dp)
|
||||
) {
|
||||
LazyColumn {
|
||||
// if (subjects.value.isNotEmpty()) {
|
||||
// item {
|
||||
// SubjectEntry(subject = subjects.value[0])
|
||||
// }
|
||||
// }
|
||||
// if (subjects.value.size > 1) {
|
||||
// items(subjects.value.subList(1, subjects.value.lastIndex + 1)) {
|
||||
// Column {
|
||||
// Divider(modifier = Modifier.padding(10.dp, 0.dp))
|
||||
// SubjectEntry(subject = it)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
items(subjects.value) {
|
||||
SubjectEntry(
|
||||
subject = it,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package be.ugent.sel.studeez.screens.tasks
|
||||
|
||||
import android.util.Log
|
||||
import be.ugent.sel.studeez.data.SelectedSubject
|
||||
import be.ugent.sel.studeez.data.local.models.task.Subject
|
||||
import be.ugent.sel.studeez.domain.LogService
|
||||
|
@ -17,14 +16,8 @@ class SubjectViewModel @Inject constructor(
|
|||
private val selectedSubject: SelectedSubject,
|
||||
logService: LogService,
|
||||
) : StudeezViewModel(logService) {
|
||||
fun addSubject() {
|
||||
subjectDAO.saveSubject(
|
||||
Subject(
|
||||
name = "Test Subject",
|
||||
time = 0,
|
||||
argb_color = 0xFFF44336,
|
||||
)
|
||||
)
|
||||
fun addSubject(open: (String) -> Unit) {
|
||||
open(StudeezDestinations.ADD_SUBJECT_FORM)
|
||||
}
|
||||
|
||||
fun getSubjects(): Flow<List<Subject>> {
|
||||
|
@ -32,7 +25,6 @@ class SubjectViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun onViewSubject(subject: Subject, open: (String) -> Unit) {
|
||||
Log.v("MYLOG", subject.id)
|
||||
selectedSubject.set(subject)
|
||||
open(StudeezDestinations.TASKS_SCREEN)
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ data class TaskActions(
|
|||
val addTask: () -> Unit,
|
||||
val getSubject: () -> Subject,
|
||||
val getTasks: () -> Flow<List<Task>>,
|
||||
val deleteSubject: () -> Unit,
|
||||
val deleteTask: (Task) -> Unit,
|
||||
val onCheckTask: (Task, Boolean) -> Unit,
|
||||
val editSubject: () -> Unit,
|
||||
)
|
||||
|
||||
fun getTaskActions(viewModel: TaskViewModel, open: (String) -> Unit): TaskActions {
|
||||
|
@ -41,9 +41,9 @@ fun getTaskActions(viewModel: TaskViewModel, open: (String) -> Unit): TaskAction
|
|||
addTask = viewModel::addTask,
|
||||
getTasks = viewModel::getTasks,
|
||||
getSubject = viewModel::getSelectedSubject,
|
||||
deleteSubject = { viewModel.deleteSubject(open) },
|
||||
deleteTask = viewModel::deleteTask,
|
||||
onCheckTask = { task, isChecked -> viewModel.toggleTaskCompleted(task, isChecked) },
|
||||
editSubject = { viewModel.editSubject(open) }
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ fun TaskScreen(
|
|||
SecondaryScreenTemplate(
|
||||
title = taskActions.getSubject().name,
|
||||
popUp = goBack,
|
||||
barAction = { EditAction {} } // TODO implement
|
||||
barAction = { EditAction(onClick = taskActions.editSubject) }
|
||||
) {
|
||||
val tasks = taskActions.getTasks().collectAsState(initial = emptyList())
|
||||
Column(
|
||||
|
@ -83,15 +83,6 @@ fun TaskScreen(
|
|||
}
|
||||
}
|
||||
NewTaskSubjectButton(onClick = taskActions.addTask, R.string.new_task)
|
||||
BasicButton(
|
||||
text = R.string.delete_subject,
|
||||
modifier = Modifier.basicButton(),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = Color.Red,
|
||||
contentColor = Color.White,
|
||||
),
|
||||
onClick = taskActions.deleteSubject,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,8 +110,8 @@ fun TaskScreenPreview() {
|
|||
{ Subject(name = "Test Subject") },
|
||||
{ flowOf() },
|
||||
{},
|
||||
{},
|
||||
{ _, _ -> run {} },
|
||||
{},
|
||||
)
|
||||
)
|
||||
}
|
|
@ -43,4 +43,8 @@ class TaskViewModel @Inject constructor(
|
|||
fun toggleTaskCompleted(task: Task, completed: Boolean) {
|
||||
taskDAO.toggleTaskCompleted(task, completed)
|
||||
}
|
||||
|
||||
fun editSubject(open: (String) -> Unit) {
|
||||
open(StudeezDestinations.EDIT_SUBJECT_FORM)
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import androidx.compose.material.Text
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import be.ugent.sel.studeez.R
|
||||
|
@ -29,6 +30,8 @@ fun SubjectAddRoute(
|
|||
goBack = goBack,
|
||||
uiState = uiState,
|
||||
onConfirm = { viewModel.onCreate(open) },
|
||||
onNameChange = viewModel::onNameChange,
|
||||
onColorChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -44,8 +47,10 @@ fun SubjectEditRoute(
|
|||
goBack = goBack,
|
||||
uiState = uiState,
|
||||
onConfirm = { viewModel.onEdit(open) },
|
||||
onNameChange = viewModel::onNameChange,
|
||||
onColorChange = {},
|
||||
) {
|
||||
DeleteButton(onClick = viewModel::onDelete)
|
||||
DeleteButton(onClick = { viewModel.onDelete(open) })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,6 +60,8 @@ fun SubjectForm(
|
|||
goBack: () -> Unit,
|
||||
uiState: SubjectFormUiState,
|
||||
onConfirm: () -> Unit,
|
||||
onNameChange: (String) -> Unit,
|
||||
onColorChange: (Color) -> Unit,
|
||||
extraButton: @Composable () -> Unit = {},
|
||||
) {
|
||||
SecondaryScreenTemplate(
|
||||
|
@ -65,7 +72,7 @@ fun SubjectForm(
|
|||
OutlinedTextField(
|
||||
singleLine = true,
|
||||
value = uiState.name,
|
||||
onValueChange = {},
|
||||
onValueChange = onNameChange,
|
||||
placeholder = { Text(stringResource(id = R.string.username)) },
|
||||
modifier = Modifier.fieldModifier(),
|
||||
)
|
||||
|
@ -87,6 +94,8 @@ fun AddSubjectFormPreview() {
|
|||
goBack = {},
|
||||
uiState = SubjectFormUiState(),
|
||||
onConfirm = {},
|
||||
onNameChange = {},
|
||||
onColorChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -100,6 +109,8 @@ fun EditSubjectFormPreview() {
|
|||
name = "Test Subject",
|
||||
),
|
||||
onConfirm = {},
|
||||
onNameChange = {},
|
||||
onColorChange = {},
|
||||
) {
|
||||
DeleteButton {}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,9 @@ class SubjectFormViewModel @Inject constructor(
|
|||
uiState.value = uiState.value.copy(color = newValue)
|
||||
}
|
||||
|
||||
fun onDelete() {
|
||||
fun onDelete(open: (String) -> Unit) {
|
||||
subjectDAO.deleteSubject(selectedSubject())
|
||||
open(StudeezDestinations.SUBJECT_SCREEN)
|
||||
}
|
||||
|
||||
fun onCreate(open: (String) -> Unit) {
|
||||
|
@ -48,6 +49,7 @@ class SubjectFormViewModel @Inject constructor(
|
|||
selectedSubject.set(newSubject)
|
||||
// TODO open newly created subject
|
||||
// open(StudeezDestinations.TASKS_SCREEN)
|
||||
open(StudeezDestinations.SUBJECT_SCREEN)
|
||||
}
|
||||
|
||||
fun onEdit(open: (String) -> Unit) {
|
||||
|
|
Reference in a new issue