wrap timerselection in route
This commit is contained in:
		
							parent
							
								
									480f085325
								
							
						
					
					
						commit
						08a33d1c9e
					
				
					 3 changed files with 57 additions and 35 deletions
				
			
		|  | @ -33,7 +33,6 @@ import be.ugent.sel.studeez.screens.session.SessionScreen | |||
| import be.ugent.sel.studeez.screens.sign_up.SignUpRoute | ||||
| import be.ugent.sel.studeez.screens.splash.SplashRoute | ||||
| import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewRoute | ||||
| import be.ugent.sel.studeez.screens.timer_selection.TimerSelectionScreen | ||||
| import be.ugent.sel.studeez.ui.theme.StudeezTheme | ||||
| import kotlinx.coroutines.CoroutineScope | ||||
| 
 | ||||
|  | @ -140,6 +139,6 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | |||
|     } | ||||
| 
 | ||||
|     composable(StudeezDestinations.TIMER_SELECTION_SCREEN) { | ||||
|         TimerSelectionScreen(open, openAndPopUp) | ||||
|         TimerOverviewRoute(open, openAndPopUp, viewModel = hiltViewModel()) | ||||
|     } | ||||
| } | ||||
|  | @ -91,7 +91,7 @@ fun TimerOverviewScreen( | |||
|                         timerInfo = it, | ||||
|                         true, | ||||
|                         R.string.edit, | ||||
|                         onEditClick = timerOverviewActions.onEditClick | ||||
|                         onButtonClick = timerOverviewActions.onEditClick | ||||
|                     ) | ||||
| 
 | ||||
|                 } | ||||
|  | @ -109,7 +109,7 @@ fun TimerEntry( | |||
|     timerInfo: TimerInfo, | ||||
|     showButton: Boolean, | ||||
|     @StringRes buttonName: Int = -1, | ||||
|     onEditClick: (TimerInfo) -> Unit = {} | ||||
|     onButtonClick: (TimerInfo) -> Unit = {} | ||||
| ) { | ||||
|     Row( | ||||
|         verticalAlignment = Alignment.CenterVertically, | ||||
|  | @ -132,7 +132,7 @@ fun TimerEntry( | |||
|         } | ||||
|         if (showButton) { | ||||
|             StealthButton(buttonName) { | ||||
|                 onEditClick(timerInfo) | ||||
|                 onButtonClick(timerInfo) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -3,60 +3,83 @@ package be.ugent.sel.studeez.screens.timer_selection | |||
| import androidx.compose.foundation.layout.Arrangement | ||||
| import androidx.compose.foundation.lazy.LazyColumn | ||||
| import androidx.compose.foundation.lazy.items | ||||
| import androidx.compose.runtime.* | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.collectAsState | ||||
| import androidx.compose.ui.tooling.preview.Preview | ||||
| import androidx.compose.ui.unit.dp | ||||
| import androidx.hilt.navigation.compose.hiltViewModel | ||||
| import be.ugent.sel.studeez.R | ||||
| import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate | ||||
| import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | ||||
| import be.ugent.sel.studeez.resources | ||||
| import be.ugent.sel.studeez.screens.drawer.DrawerActions | ||||
| import be.ugent.sel.studeez.screens.drawer.DrawerViewModel | ||||
| import be.ugent.sel.studeez.screens.drawer.getDrawerActions | ||||
| import be.ugent.sel.studeez.screens.navbar.NavigationBarActions | ||||
| import be.ugent.sel.studeez.screens.navbar.NavigationBarViewModel | ||||
| import be.ugent.sel.studeez.screens.navbar.getNavigationBarActions | ||||
| import be.ugent.sel.studeez.screens.timer_overview.TimerEntry | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| import kotlinx.coroutines.flow.flowOf | ||||
| 
 | ||||
| data class TimerSelectionActions( | ||||
|     val getAllTimers: () -> Flow<List<TimerInfo>>, | ||||
|     val startSession: (TimerInfo) -> Unit, | ||||
| ) | ||||
| 
 | ||||
| fun getTimerSelectionActions( | ||||
|     viewModel: TimerSelectionViewModel, | ||||
|     open: (String) -> Unit, | ||||
| ): TimerSelectionActions { | ||||
|     return TimerSelectionActions( | ||||
|         getAllTimers = viewModel::getAllTimers, | ||||
|         startSession = { viewModel.startSession(open, it) }, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun TimerSelectionRoute( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     viewModel: TimerSelectionViewModel, | ||||
| ) { | ||||
|     TimerSelectionScreen( | ||||
|         timerSelectionActions = getTimerSelectionActions(viewModel, open), | ||||
|         drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp), | ||||
|         navigationBarActions = getNavigationBarActions(hiltViewModel(), open), | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun TimerSelectionScreen( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     viewModel: TimerSelectionViewModel = hiltViewModel() | ||||
|     timerSelectionActions: TimerSelectionActions, | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
| ) { | ||||
| 
 | ||||
|     val timers = viewModel.getAllTimers().collectAsState(initial = emptyList()) | ||||
|     val drawerViewModel: DrawerViewModel = hiltViewModel() | ||||
|     val drawerActions = DrawerActions( | ||||
|         onHomeButtonClick = { drawerViewModel.onHomeButtonClick(open) }, | ||||
|         onTimersClick = { drawerViewModel.onTimersClick(open) }, | ||||
|         onSettingsClick = { drawerViewModel.onSettingsClick(open) }, | ||||
|         onLogoutClick = { drawerViewModel.onLogoutClick(openAndPopUp) }, | ||||
|         onAboutClick = { drawerViewModel.onAboutClick(open) }, | ||||
|     ) | ||||
|     val navigationBarViewModel: NavigationBarViewModel = hiltViewModel() | ||||
|     val navigationBarActions = NavigationBarActions( | ||||
|         onHomeClick = { navigationBarViewModel.onHomeClick(open) }, | ||||
|         onTasksClick = { navigationBarViewModel.onTasksClick(open) }, | ||||
|         onSessionsClick = { navigationBarViewModel.onSessionsClick(open) }, | ||||
|         onProfileClick = { navigationBarViewModel.onProfileClick(open) }, | ||||
|     ) | ||||
|     val timers = timerSelectionActions.getAllTimers().collectAsState(initial = emptyList()) | ||||
|     PrimaryScreenTemplate( | ||||
|         title = resources().getString(R.string.timers), | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions, | ||||
|     ) { | ||||
| 
 | ||||
|         LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) { | ||||
| 
 | ||||
|             // All timers | ||||
|             items(timers.value) { | ||||
|                 TimerEntry( | ||||
|                     timerInfo = it, | ||||
|                     showButton = true, | ||||
|                     buttonName = R.string.start | ||||
|                 ) { timerInfo -> | ||||
|                     viewModel.startSession(open, timerInfo) | ||||
|                 } | ||||
|                     buttonName = R.string.start, | ||||
|                     onButtonClick = timerSelectionActions.startSession | ||||
|                 ) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Preview | ||||
| @Composable | ||||
| fun TimerSelectionPreview() { | ||||
|     TimerSelectionScreen( | ||||
|         timerSelectionActions = TimerSelectionActions({ flowOf() }, {}), | ||||
|         drawerActions = DrawerActions({}, {}, {}, {}, {}), | ||||
|         navigationBarActions = NavigationBarActions({}, {}, {}, {}), | ||||
|     ) | ||||
| } | ||||
		Reference in a new issue
	
	 brreynie
						brreynie