#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.splash.SplashRoute
|
||||||
import be.ugent.sel.studeez.screens.tasks.SubjectRoute
|
import be.ugent.sel.studeez.screens.tasks.SubjectRoute
|
||||||
import be.ugent.sel.studeez.screens.tasks.TaskRoute
|
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_overview.TimerOverviewRoute
|
||||||
import be.ugent.sel.studeez.screens.timer_selection.TimerSelectionRoute
|
import be.ugent.sel.studeez.screens.timer_selection.TimerSelectionRoute
|
||||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
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) {
|
composable(StudeezDestinations.TASKS_SCREEN) {
|
||||||
TaskRoute(
|
TaskRoute(
|
||||||
goBack = goBack,
|
goBack = goBack,
|
||||||
|
|
|
@ -10,7 +10,10 @@ object StudeezDestinations {
|
||||||
const val TIMER_SELECTION_SCREEN = "timer_selection"
|
const val TIMER_SELECTION_SCREEN = "timer_selection"
|
||||||
const val SESSION_SCREEN = "session"
|
const val SESSION_SCREEN = "session"
|
||||||
const val SESSION_RECAP = "session_recap"
|
const val SESSION_RECAP = "session_recap"
|
||||||
|
|
||||||
const val SUBJECT_SCREEN = "subjects"
|
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 TASKS_SCREEN = "tasks"
|
||||||
|
|
||||||
// const val SESSIONS_SCREEN = "sessions"
|
// const val SESSIONS_SCREEN = "sessions"
|
||||||
|
|
|
@ -30,7 +30,7 @@ fun SubjectRoute(
|
||||||
SubjectScreen(
|
SubjectScreen(
|
||||||
drawerActions = drawerActions,
|
drawerActions = drawerActions,
|
||||||
navigationBarActions = navigationBarActions,
|
navigationBarActions = navigationBarActions,
|
||||||
addSubject = { viewModel.addSubject() },
|
addSubject = { viewModel.addSubject(open) },
|
||||||
getSubjects = viewModel::getSubjects,
|
getSubjects = viewModel::getSubjects,
|
||||||
onViewSubject = { viewModel.onViewSubject(it, open) },
|
onViewSubject = { viewModel.onViewSubject(it, open) },
|
||||||
)
|
)
|
||||||
|
@ -55,19 +55,6 @@ fun SubjectScreen(
|
||||||
modifier = Modifier.padding(top = 5.dp)
|
modifier = Modifier.padding(top = 5.dp)
|
||||||
) {
|
) {
|
||||||
LazyColumn {
|
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) {
|
items(subjects.value) {
|
||||||
SubjectEntry(
|
SubjectEntry(
|
||||||
subject = it,
|
subject = it,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package be.ugent.sel.studeez.screens.tasks
|
package be.ugent.sel.studeez.screens.tasks
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import be.ugent.sel.studeez.data.SelectedSubject
|
import be.ugent.sel.studeez.data.SelectedSubject
|
||||||
import be.ugent.sel.studeez.data.local.models.task.Subject
|
import be.ugent.sel.studeez.data.local.models.task.Subject
|
||||||
import be.ugent.sel.studeez.domain.LogService
|
import be.ugent.sel.studeez.domain.LogService
|
||||||
|
@ -17,14 +16,8 @@ class SubjectViewModel @Inject constructor(
|
||||||
private val selectedSubject: SelectedSubject,
|
private val selectedSubject: SelectedSubject,
|
||||||
logService: LogService,
|
logService: LogService,
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
fun addSubject() {
|
fun addSubject(open: (String) -> Unit) {
|
||||||
subjectDAO.saveSubject(
|
open(StudeezDestinations.ADD_SUBJECT_FORM)
|
||||||
Subject(
|
|
||||||
name = "Test Subject",
|
|
||||||
time = 0,
|
|
||||||
argb_color = 0xFFF44336,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSubjects(): Flow<List<Subject>> {
|
fun getSubjects(): Flow<List<Subject>> {
|
||||||
|
@ -32,7 +25,6 @@ class SubjectViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onViewSubject(subject: Subject, open: (String) -> Unit) {
|
fun onViewSubject(subject: Subject, open: (String) -> Unit) {
|
||||||
Log.v("MYLOG", subject.id)
|
|
||||||
selectedSubject.set(subject)
|
selectedSubject.set(subject)
|
||||||
open(StudeezDestinations.TASKS_SCREEN)
|
open(StudeezDestinations.TASKS_SCREEN)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,9 @@ data class TaskActions(
|
||||||
val addTask: () -> Unit,
|
val addTask: () -> Unit,
|
||||||
val getSubject: () -> Subject,
|
val getSubject: () -> Subject,
|
||||||
val getTasks: () -> Flow<List<Task>>,
|
val getTasks: () -> Flow<List<Task>>,
|
||||||
val deleteSubject: () -> Unit,
|
|
||||||
val deleteTask: (Task) -> Unit,
|
val deleteTask: (Task) -> Unit,
|
||||||
val onCheckTask: (Task, Boolean) -> Unit,
|
val onCheckTask: (Task, Boolean) -> Unit,
|
||||||
|
val editSubject: () -> Unit,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getTaskActions(viewModel: TaskViewModel, open: (String) -> Unit): TaskActions {
|
fun getTaskActions(viewModel: TaskViewModel, open: (String) -> Unit): TaskActions {
|
||||||
|
@ -41,9 +41,9 @@ fun getTaskActions(viewModel: TaskViewModel, open: (String) -> Unit): TaskAction
|
||||||
addTask = viewModel::addTask,
|
addTask = viewModel::addTask,
|
||||||
getTasks = viewModel::getTasks,
|
getTasks = viewModel::getTasks,
|
||||||
getSubject = viewModel::getSelectedSubject,
|
getSubject = viewModel::getSelectedSubject,
|
||||||
deleteSubject = { viewModel.deleteSubject(open) },
|
|
||||||
deleteTask = viewModel::deleteTask,
|
deleteTask = viewModel::deleteTask,
|
||||||
onCheckTask = { task, isChecked -> viewModel.toggleTaskCompleted(task, isChecked) },
|
onCheckTask = { task, isChecked -> viewModel.toggleTaskCompleted(task, isChecked) },
|
||||||
|
editSubject = { viewModel.editSubject(open) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ fun TaskScreen(
|
||||||
SecondaryScreenTemplate(
|
SecondaryScreenTemplate(
|
||||||
title = taskActions.getSubject().name,
|
title = taskActions.getSubject().name,
|
||||||
popUp = goBack,
|
popUp = goBack,
|
||||||
barAction = { EditAction {} } // TODO implement
|
barAction = { EditAction(onClick = taskActions.editSubject) }
|
||||||
) {
|
) {
|
||||||
val tasks = taskActions.getTasks().collectAsState(initial = emptyList())
|
val tasks = taskActions.getTasks().collectAsState(initial = emptyList())
|
||||||
Column(
|
Column(
|
||||||
|
@ -83,15 +83,6 @@ fun TaskScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NewTaskSubjectButton(onClick = taskActions.addTask, R.string.new_task)
|
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") },
|
{ Subject(name = "Test Subject") },
|
||||||
{ flowOf() },
|
{ flowOf() },
|
||||||
{},
|
{},
|
||||||
{},
|
|
||||||
{ _, _ -> run {} },
|
{ _, _ -> run {} },
|
||||||
|
{},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -43,4 +43,8 @@ class TaskViewModel @Inject constructor(
|
||||||
fun toggleTaskCompleted(task: Task, completed: Boolean) {
|
fun toggleTaskCompleted(task: Task, completed: Boolean) {
|
||||||
taskDAO.toggleTaskCompleted(task, completed)
|
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.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import be.ugent.sel.studeez.R
|
import be.ugent.sel.studeez.R
|
||||||
|
@ -29,6 +30,8 @@ fun SubjectAddRoute(
|
||||||
goBack = goBack,
|
goBack = goBack,
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
onConfirm = { viewModel.onCreate(open) },
|
onConfirm = { viewModel.onCreate(open) },
|
||||||
|
onNameChange = viewModel::onNameChange,
|
||||||
|
onColorChange = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +47,10 @@ fun SubjectEditRoute(
|
||||||
goBack = goBack,
|
goBack = goBack,
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
onConfirm = { viewModel.onEdit(open) },
|
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,
|
goBack: () -> Unit,
|
||||||
uiState: SubjectFormUiState,
|
uiState: SubjectFormUiState,
|
||||||
onConfirm: () -> Unit,
|
onConfirm: () -> Unit,
|
||||||
|
onNameChange: (String) -> Unit,
|
||||||
|
onColorChange: (Color) -> Unit,
|
||||||
extraButton: @Composable () -> Unit = {},
|
extraButton: @Composable () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
SecondaryScreenTemplate(
|
SecondaryScreenTemplate(
|
||||||
|
@ -65,7 +72,7 @@ fun SubjectForm(
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
value = uiState.name,
|
value = uiState.name,
|
||||||
onValueChange = {},
|
onValueChange = onNameChange,
|
||||||
placeholder = { Text(stringResource(id = R.string.username)) },
|
placeholder = { Text(stringResource(id = R.string.username)) },
|
||||||
modifier = Modifier.fieldModifier(),
|
modifier = Modifier.fieldModifier(),
|
||||||
)
|
)
|
||||||
|
@ -87,6 +94,8 @@ fun AddSubjectFormPreview() {
|
||||||
goBack = {},
|
goBack = {},
|
||||||
uiState = SubjectFormUiState(),
|
uiState = SubjectFormUiState(),
|
||||||
onConfirm = {},
|
onConfirm = {},
|
||||||
|
onNameChange = {},
|
||||||
|
onColorChange = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +109,8 @@ fun EditSubjectFormPreview() {
|
||||||
name = "Test Subject",
|
name = "Test Subject",
|
||||||
),
|
),
|
||||||
onConfirm = {},
|
onConfirm = {},
|
||||||
|
onNameChange = {},
|
||||||
|
onColorChange = {},
|
||||||
) {
|
) {
|
||||||
DeleteButton {}
|
DeleteButton {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,9 @@ class SubjectFormViewModel @Inject constructor(
|
||||||
uiState.value = uiState.value.copy(color = newValue)
|
uiState.value = uiState.value.copy(color = newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDelete() {
|
fun onDelete(open: (String) -> Unit) {
|
||||||
subjectDAO.deleteSubject(selectedSubject())
|
subjectDAO.deleteSubject(selectedSubject())
|
||||||
|
open(StudeezDestinations.SUBJECT_SCREEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCreate(open: (String) -> Unit) {
|
fun onCreate(open: (String) -> Unit) {
|
||||||
|
@ -48,6 +49,7 @@ class SubjectFormViewModel @Inject constructor(
|
||||||
selectedSubject.set(newSubject)
|
selectedSubject.set(newSubject)
|
||||||
// TODO open newly created subject
|
// TODO open newly created subject
|
||||||
// open(StudeezDestinations.TASKS_SCREEN)
|
// open(StudeezDestinations.TASKS_SCREEN)
|
||||||
|
open(StudeezDestinations.SUBJECT_SCREEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onEdit(open: (String) -> Unit) {
|
fun onEdit(open: (String) -> Unit) {
|
||||||
|
|
Reference in a new issue