Merge pull request #121 from SELab1/create-task-from-fab
#67 create task from fab
This commit is contained in:
		
						commit
						9856a4514a
					
				
					 8 changed files with 175 additions and 28 deletions
				
			
		|  | @ -4,6 +4,7 @@ import be.ugent.sel.studeez.common.snackbar.SnackbarManager | ||||||
| import be.ugent.sel.studeez.domain.LogService | import be.ugent.sel.studeez.domain.LogService | ||||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN | import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN | ||||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN | import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN | ||||||
|  | import be.ugent.sel.studeez.navigation.StudeezDestinations.SELECT_SUBJECT | ||||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SESSIONS_SCREEN | import be.ugent.sel.studeez.navigation.StudeezDestinations.SESSIONS_SCREEN | ||||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SUBJECT_SCREEN | import be.ugent.sel.studeez.navigation.StudeezDestinations.SUBJECT_SCREEN | ||||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | import be.ugent.sel.studeez.screens.StudeezViewModel | ||||||
|  | @ -33,8 +34,7 @@ class NavigationBarViewModel @Inject constructor( | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun onAddTaskClick(open: (String) -> Unit) { |     fun onAddTaskClick(open: (String) -> Unit) { | ||||||
|         // TODO open(CREATE_TASK_SCREEN) |         open(SELECT_SUBJECT) | ||||||
|         SnackbarManager.showMessage(AppText.create_task_not_possible_yet) // TODO Remove |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun onAddFriendClick(open: (String) -> Unit) { |     fun onAddFriendClick(open: (String) -> Unit) { | ||||||
|  |  | ||||||
|  | @ -30,10 +30,10 @@ import be.ugent.sel.studeez.R.string as AppText | ||||||
| @Composable | @Composable | ||||||
| fun SubjectEntry( | fun SubjectEntry( | ||||||
|     subject: Subject, |     subject: Subject, | ||||||
|     onViewSubject: () -> Unit, |  | ||||||
|     getTaskCount: () -> Flow<Int>, |     getTaskCount: () -> Flow<Int>, | ||||||
|     getCompletedTaskCount: () -> Flow<Int>, |     getCompletedTaskCount: () -> Flow<Int>, | ||||||
|     getStudyTime: () -> Flow<Int>, |     getStudyTime: () -> Flow<Int>, | ||||||
|  |     selectButton: @Composable (RowScope) -> Unit, | ||||||
| ) { | ) { | ||||||
|     val studytime by getStudyTime().collectAsState(initial = 0) |     val studytime by getStudyTime().collectAsState(initial = 0) | ||||||
|     val taskCount by getTaskCount().collectAsState(initial = 0) |     val taskCount by getTaskCount().collectAsState(initial = 0) | ||||||
|  | @ -89,14 +89,7 @@ fun SubjectEntry( | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             StealthButton( |             selectButton(this) | ||||||
|                 text = AppText.view_tasks, |  | ||||||
|                 modifier = Modifier |  | ||||||
|                     .padding(start = 10.dp, end = 5.dp) |  | ||||||
|                     .weight(1f) |  | ||||||
|             ) { |  | ||||||
|                 onViewSubject() |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -109,11 +102,16 @@ fun SubjectEntryPreview() { | ||||||
|             name = "Test Subject", |             name = "Test Subject", | ||||||
|             argb_color = 0xFFFFD200, |             argb_color = 0xFFFFD200, | ||||||
|         ), |         ), | ||||||
|         onViewSubject = {}, |  | ||||||
|         getTaskCount = { flowOf() }, |         getTaskCount = { flowOf() }, | ||||||
|         getCompletedTaskCount = { flowOf() }, |         getCompletedTaskCount = { flowOf() }, | ||||||
|         getStudyTime = { flowOf() }, |         getStudyTime = { flowOf() }, | ||||||
|     ) |     ) { | ||||||
|  |         StealthButton( | ||||||
|  |             text = AppText.view_tasks, | ||||||
|  |             modifier = Modifier | ||||||
|  |                 .padding(start = 10.dp, end = 5.dp) | ||||||
|  |         ) {} | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @Preview | @Preview | ||||||
|  | @ -124,9 +122,8 @@ fun OverflowSubjectEntryPreview() { | ||||||
|             name = "Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", |             name = "Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", | ||||||
|             argb_color = 0xFFFFD200, |             argb_color = 0xFFFFD200, | ||||||
|         ), |         ), | ||||||
|         onViewSubject = {}, |  | ||||||
|         getTaskCount = { flowOf() }, |         getTaskCount = { flowOf() }, | ||||||
|         getCompletedTaskCount = { flowOf() }, |         getCompletedTaskCount = { flowOf() }, | ||||||
|         getStudyTime = { flowOf() }, |         getStudyTime = { flowOf() }, | ||||||
|     ) |     ) {} | ||||||
| } | } | ||||||
|  | @ -27,6 +27,7 @@ object StudeezDestinations { | ||||||
|     const val EDIT_SUBJECT_FORM = "edit_subject" |     const val EDIT_SUBJECT_FORM = "edit_subject" | ||||||
|     const val TASKS_SCREEN = "tasks" |     const val TASKS_SCREEN = "tasks" | ||||||
|     const val ADD_TASK_FORM = "add_task" |     const val ADD_TASK_FORM = "add_task" | ||||||
|  |     const val SELECT_SUBJECT = "select_subject" | ||||||
|     const val EDIT_TASK_FORM = "edit_task" |     const val EDIT_TASK_FORM = "edit_task" | ||||||
| 
 | 
 | ||||||
|     // Friends flow |     // Friends flow | ||||||
|  |  | ||||||
|  | @ -30,6 +30,7 @@ import be.ugent.sel.studeez.screens.splash.SplashRoute | ||||||
| import be.ugent.sel.studeez.screens.subjects.SubjectRoute | import be.ugent.sel.studeez.screens.subjects.SubjectRoute | ||||||
| import be.ugent.sel.studeez.screens.subjects.form.SubjectCreateRoute | import be.ugent.sel.studeez.screens.subjects.form.SubjectCreateRoute | ||||||
| import be.ugent.sel.studeez.screens.subjects.form.SubjectEditRoute | import be.ugent.sel.studeez.screens.subjects.form.SubjectEditRoute | ||||||
|  | import be.ugent.sel.studeez.screens.subjects.select.SubjectSelectionRoute | ||||||
| import be.ugent.sel.studeez.screens.tasks.TaskRoute | import be.ugent.sel.studeez.screens.tasks.TaskRoute | ||||||
| import be.ugent.sel.studeez.screens.tasks.form.TaskCreateRoute | import be.ugent.sel.studeez.screens.tasks.form.TaskCreateRoute | ||||||
| import be.ugent.sel.studeez.screens.tasks.form.TaskEditRoute | import be.ugent.sel.studeez.screens.tasks.form.TaskEditRoute | ||||||
|  | @ -68,7 +69,7 @@ fun StudeezNavGraph( | ||||||
|         // NavBar |         // NavBar | ||||||
|         composable(StudeezDestinations.HOME_SCREEN) { |         composable(StudeezDestinations.HOME_SCREEN) { | ||||||
|             HomeRoute( |             HomeRoute( | ||||||
|                 open, |                 open = open, | ||||||
|                 drawerActions = drawerActions, |                 drawerActions = drawerActions, | ||||||
|                 navigationBarActions = navigationBarActions, |                 navigationBarActions = navigationBarActions, | ||||||
|                 feedViewModel = hiltViewModel(), |                 feedViewModel = hiltViewModel(), | ||||||
|  | @ -85,6 +86,14 @@ fun StudeezNavGraph( | ||||||
|             ) |             ) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         composable(StudeezDestinations.SELECT_SUBJECT) { | ||||||
|  |             SubjectSelectionRoute( | ||||||
|  |                 open = { openAndPopUp(it, StudeezDestinations.SELECT_SUBJECT) }, | ||||||
|  |                 goBack = goBack, | ||||||
|  |                 viewModel = hiltViewModel(), | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         composable(StudeezDestinations.ADD_SUBJECT_FORM) { |         composable(StudeezDestinations.ADD_SUBJECT_FORM) { | ||||||
|             SubjectCreateRoute( |             SubjectCreateRoute( | ||||||
|                 goBack = goBack, |                 goBack = goBack, | ||||||
|  | @ -103,7 +112,7 @@ fun StudeezNavGraph( | ||||||
| 
 | 
 | ||||||
|         composable(StudeezDestinations.TASKS_SCREEN) { |         composable(StudeezDestinations.TASKS_SCREEN) { | ||||||
|             TaskRoute( |             TaskRoute( | ||||||
|                 goBack = goBack, |                 goBack = { openAndPopUp(StudeezDestinations.SUBJECT_SCREEN, StudeezDestinations.TASKS_SCREEN) }, | ||||||
|                 open = open, |                 open = open, | ||||||
|                 viewModel = hiltViewModel(), |                 viewModel = hiltViewModel(), | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|  | @ -15,10 +15,12 @@ import androidx.compose.ui.tooling.preview.Preview | ||||||
| import androidx.compose.ui.unit.dp | import androidx.compose.ui.unit.dp | ||||||
| import be.ugent.sel.studeez.common.composable.NewTaskSubjectButton | import be.ugent.sel.studeez.common.composable.NewTaskSubjectButton | ||||||
| import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate | import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate | ||||||
|  | import be.ugent.sel.studeez.common.composable.StealthButton | ||||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions | import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions | ||||||
| import be.ugent.sel.studeez.common.composable.tasks.SubjectEntry | import be.ugent.sel.studeez.common.composable.tasks.SubjectEntry | ||||||
| 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.navigation.StudeezDestinations | ||||||
| import kotlinx.coroutines.flow.Flow | import kotlinx.coroutines.flow.Flow | ||||||
| import kotlinx.coroutines.flow.flowOf | import kotlinx.coroutines.flow.flowOf | ||||||
| import be.ugent.sel.studeez.R.string as AppText | import be.ugent.sel.studeez.R.string as AppText | ||||||
|  | @ -35,11 +37,11 @@ fun SubjectRoute( | ||||||
|         drawerActions = drawerActions, |         drawerActions = drawerActions, | ||||||
|         navigationBarActions = navigationBarActions, |         navigationBarActions = navigationBarActions, | ||||||
|         onAddSubject = { viewModel.onAddSubject(open) }, |         onAddSubject = { viewModel.onAddSubject(open) }, | ||||||
|         onViewSubject = { viewModel.onViewSubject(it, open) }, |         onViewSubject = { viewModel.onSelectSubject(it) { open(StudeezDestinations.TASKS_SCREEN) } }, | ||||||
|         getTaskCount = viewModel::getTaskCount, |         getTaskCount = viewModel::getTaskCount, | ||||||
|         getCompletedTaskCount = viewModel::getCompletedTaskCount, |         getCompletedTaskCount = viewModel::getCompletedTaskCount, | ||||||
|         getStudyTime = viewModel::getStudyTime, |         getStudyTime = viewModel::getStudyTime, | ||||||
|         uiState, |         uiState = uiState, | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -76,14 +78,22 @@ fun SubjectScreen( | ||||||
|                 ) { |                 ) { | ||||||
|                     NewTaskSubjectButton(onClick = onAddSubject, AppText.new_subject) |                     NewTaskSubjectButton(onClick = onAddSubject, AppText.new_subject) | ||||||
|                     LazyColumn { |                     LazyColumn { | ||||||
|                         items(uiState.subjects) { |                         items(uiState.subjects) { subject -> | ||||||
|                             SubjectEntry( |                             SubjectEntry( | ||||||
|                                 subject = it, |                                 subject = subject, | ||||||
|                                 onViewSubject = { onViewSubject(it) }, |                                 getTaskCount = { getTaskCount(subject) }, | ||||||
|                                 getTaskCount = { getTaskCount(it) }, |                                 getCompletedTaskCount = { getCompletedTaskCount(subject) }, | ||||||
|                                 getCompletedTaskCount = { getCompletedTaskCount(it) }, |                                 getStudyTime = { getStudyTime(subject) }, | ||||||
|                                 getStudyTime = { getStudyTime(it) }, |                             ) { | ||||||
|                             ) |                                 StealthButton( | ||||||
|  |                                     text = AppText.view_tasks, | ||||||
|  |                                     modifier = Modifier | ||||||
|  |                                         .padding(start = 10.dp, end = 5.dp) | ||||||
|  |                                         .weight(1f) | ||||||
|  |                                 ) { | ||||||
|  |                                     onViewSubject(subject) | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  | @ -42,8 +42,8 @@ class SubjectViewModel @Inject constructor( | ||||||
|         return subjectDAO.getStudyTime(subject) |         return subjectDAO.getStudyTime(subject) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun onViewSubject(subject: Subject, open: (String) -> Unit) { |     fun onSelectSubject(subject: Subject, open: () -> Unit) { | ||||||
|         selectedSubject.set(subject) |         selectedSubject.set(subject) | ||||||
|         open(StudeezDestinations.TASKS_SCREEN) |         open() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -0,0 +1,128 @@ | ||||||
|  | package be.ugent.sel.studeez.screens.subjects.select | ||||||
|  | 
 | ||||||
|  | import androidx.compose.foundation.layout.* | ||||||
|  | import androidx.compose.foundation.lazy.LazyColumn | ||||||
|  | import androidx.compose.foundation.lazy.items | ||||||
|  | import androidx.compose.material.CircularProgressIndicator | ||||||
|  | import androidx.compose.material.MaterialTheme | ||||||
|  | import androidx.compose.runtime.Composable | ||||||
|  | import androidx.compose.runtime.collectAsState | ||||||
|  | import androidx.compose.runtime.getValue | ||||||
|  | import androidx.compose.ui.Alignment | ||||||
|  | import androidx.compose.ui.Modifier | ||||||
|  | import androidx.compose.ui.res.stringResource | ||||||
|  | import androidx.compose.ui.tooling.preview.Preview | ||||||
|  | import androidx.compose.ui.unit.dp | ||||||
|  | import be.ugent.sel.studeez.R | ||||||
|  | import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate | ||||||
|  | import be.ugent.sel.studeez.common.composable.StealthButton | ||||||
|  | import be.ugent.sel.studeez.common.composable.tasks.SubjectEntry | ||||||
|  | import be.ugent.sel.studeez.data.local.models.task.Subject | ||||||
|  | import be.ugent.sel.studeez.navigation.StudeezDestinations | ||||||
|  | import be.ugent.sel.studeez.screens.subjects.SubjectUiState | ||||||
|  | import be.ugent.sel.studeez.screens.subjects.SubjectViewModel | ||||||
|  | import kotlinx.coroutines.flow.Flow | ||||||
|  | import kotlinx.coroutines.flow.flowOf | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun SubjectSelectionRoute( | ||||||
|  |     open: (String) -> Unit, | ||||||
|  |     goBack: () -> Unit, | ||||||
|  |     viewModel: SubjectViewModel, | ||||||
|  | ) { | ||||||
|  |     val uiState by viewModel.uiState.collectAsState() | ||||||
|  |     SubjectSelectionScreen( | ||||||
|  |         onViewSubject = { viewModel.onSelectSubject(it) { open(StudeezDestinations.ADD_TASK_FORM) } }, | ||||||
|  |         getTaskCount = viewModel::getTaskCount, | ||||||
|  |         getCompletedTaskCount = viewModel::getCompletedTaskCount, | ||||||
|  |         getStudyTime = viewModel::getStudyTime, | ||||||
|  |         goBack = goBack, | ||||||
|  |         uiState = uiState, | ||||||
|  |     ) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun SubjectSelectionScreen( | ||||||
|  |     goBack: () -> Unit, | ||||||
|  |     onViewSubject: (Subject) -> Unit, | ||||||
|  |     getTaskCount: (Subject) -> Flow<Int>, | ||||||
|  |     getCompletedTaskCount: (Subject) -> Flow<Int>, | ||||||
|  |     getStudyTime: (Subject) -> Flow<Int>, | ||||||
|  |     uiState: SubjectUiState, | ||||||
|  | ) { | ||||||
|  |     SecondaryScreenTemplate( | ||||||
|  |         title = stringResource(R.string.select_subject_title), | ||||||
|  |         barAction = {}, | ||||||
|  |         popUp = goBack, | ||||||
|  |     ) { | ||||||
|  |         when (uiState) { | ||||||
|  |             SubjectUiState.Loading -> Column( | ||||||
|  |                 modifier = Modifier | ||||||
|  |                     .fillMaxWidth() | ||||||
|  |                     .fillMaxHeight(), | ||||||
|  |                 verticalArrangement = Arrangement.Center, | ||||||
|  |                 horizontalAlignment = Alignment.CenterHorizontally | ||||||
|  |             ) { | ||||||
|  |                 CircularProgressIndicator(color = MaterialTheme.colors.onBackground) | ||||||
|  |             } | ||||||
|  |             is SubjectUiState.Succes -> { | ||||||
|  |                 Column( | ||||||
|  |                     modifier = Modifier.padding(top = 5.dp) | ||||||
|  |                 ) { | ||||||
|  |                     LazyColumn { | ||||||
|  |                         items(uiState.subjects) { subject -> | ||||||
|  |                             SubjectEntry( | ||||||
|  |                                 subject = subject, | ||||||
|  |                                 getTaskCount = { getTaskCount(subject) }, | ||||||
|  |                                 getCompletedTaskCount = { getCompletedTaskCount(subject) }, | ||||||
|  |                                 getStudyTime = { getStudyTime(subject) }, | ||||||
|  |                             ) { | ||||||
|  |                                 StealthButton( | ||||||
|  |                                     text = R.string.select_subject, | ||||||
|  |                                     modifier = Modifier | ||||||
|  |                                         .padding(start = 4.dp, end = 4.dp) | ||||||
|  |                                         .weight(1f) | ||||||
|  |                                 ) { | ||||||
|  |                                     onViewSubject(subject) | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @Preview | ||||||
|  | @Composable | ||||||
|  | fun SubjectScreenPreview() { | ||||||
|  |     SubjectSelectionScreen( | ||||||
|  |         goBack = {}, | ||||||
|  |         onViewSubject = {}, | ||||||
|  |         getTaskCount = { flowOf() }, | ||||||
|  |         getCompletedTaskCount = { flowOf() }, | ||||||
|  |         getStudyTime = { flowOf() }, | ||||||
|  |         uiState = SubjectUiState.Succes( | ||||||
|  |             listOf( | ||||||
|  |                 Subject( | ||||||
|  |                     name = "Test Subject", | ||||||
|  |                     argb_color = 0xFFFFD200, | ||||||
|  |                 ) | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|  |     ) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @Preview | ||||||
|  | @Composable | ||||||
|  | fun SubjectScreenLoadingPreview() { | ||||||
|  |     SubjectSelectionScreen( | ||||||
|  |         goBack = {}, | ||||||
|  |         onViewSubject = {}, | ||||||
|  |         getTaskCount = { flowOf() }, | ||||||
|  |         getCompletedTaskCount = { flowOf() }, | ||||||
|  |         getStudyTime = { flowOf() }, | ||||||
|  |         uiState = SubjectUiState.Loading, | ||||||
|  |     ) | ||||||
|  | } | ||||||
|  | @ -40,6 +40,7 @@ | ||||||
|     <string name="tasks">Tasks</string> |     <string name="tasks">Tasks</string> | ||||||
|     <string name="task">Task</string> |     <string name="task">Task</string> | ||||||
|     <string name="my_subjects">My Subjects</string> |     <string name="my_subjects">My Subjects</string> | ||||||
|  |     <string name="select_subject_title">Select Subject</string> | ||||||
|     <string name="new_subject">New Subject</string> |     <string name="new_subject">New Subject</string> | ||||||
|     <string name="new_task">New Task</string> |     <string name="new_task">New Task</string> | ||||||
|     <string name="edit_subject">Edit Subject</string> |     <string name="edit_subject">Edit Subject</string> | ||||||
|  | @ -47,6 +48,7 @@ | ||||||
|     <string name="delete_subject">Delete Subject</string> |     <string name="delete_subject">Delete Subject</string> | ||||||
|     <string name="delete_task">Delete Task</string> |     <string name="delete_task">Delete Task</string> | ||||||
|     <string name="view_tasks">View</string> |     <string name="view_tasks">View</string> | ||||||
|  |     <string name="select_subject">Select</string> | ||||||
|     <string name="regenerate_color">Regenerate Color</string> |     <string name="regenerate_color">Regenerate Color</string> | ||||||
| 
 | 
 | ||||||
|     <!-- Sessions --> |     <!-- Sessions --> | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 brreynie
						brreynie