wrap homescreen in route
This commit is contained in:
		
							parent
							
								
									05c37b4168
								
							
						
					
					
						commit
						8fc4ac8cf1
					
				
					 4 changed files with 55 additions and 30 deletions
				
			
		|  | @ -2,7 +2,13 @@ package be.ugent.sel.studeez | |||
| 
 | ||||
| import android.content.res.Resources | ||||
| import androidx.compose.foundation.layout.padding | ||||
| import androidx.compose.material.* | ||||
| import androidx.compose.material.MaterialTheme | ||||
| import androidx.compose.material.Scaffold | ||||
| import androidx.compose.material.ScaffoldState | ||||
| import androidx.compose.material.Snackbar | ||||
| import androidx.compose.material.SnackbarHost | ||||
| import androidx.compose.material.Surface | ||||
| import androidx.compose.material.rememberScaffoldState | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.ReadOnlyComposable | ||||
| import androidx.compose.runtime.remember | ||||
|  | @ -11,6 +17,7 @@ import androidx.compose.ui.Modifier | |||
| import androidx.compose.ui.platform.LocalConfiguration | ||||
| import androidx.compose.ui.platform.LocalContext | ||||
| import androidx.compose.ui.unit.dp | ||||
| import androidx.hilt.navigation.compose.hiltViewModel | ||||
| import androidx.navigation.NavGraphBuilder | ||||
| import androidx.navigation.NavHostController | ||||
| import androidx.navigation.compose.NavHost | ||||
|  | @ -18,11 +25,11 @@ import androidx.navigation.compose.composable | |||
| import androidx.navigation.compose.rememberNavController | ||||
| import be.ugent.sel.studeez.common.snackbar.SnackbarManager | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations | ||||
| import be.ugent.sel.studeez.screens.home.HomeScreen | ||||
| import be.ugent.sel.studeez.screens.home.HomeRoute | ||||
| import be.ugent.sel.studeez.screens.log_in.LoginScreen | ||||
| import be.ugent.sel.studeez.screens.session.SessionScreen | ||||
| import be.ugent.sel.studeez.screens.profile.EditProfileScreen | ||||
| import be.ugent.sel.studeez.screens.profile.ProfileScreen | ||||
| import be.ugent.sel.studeez.screens.session.SessionScreen | ||||
| import be.ugent.sel.studeez.screens.sign_up.SignUpScreen | ||||
| import be.ugent.sel.studeez.screens.splash.SplashScreen | ||||
| import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewScreen | ||||
|  | @ -85,12 +92,12 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | |||
|         appState.popUp() | ||||
|     } | ||||
| 
 | ||||
|     val open: (String) -> Unit = { | ||||
|             route -> appState.navigate(route) | ||||
|     val open: (String) -> Unit = { route -> | ||||
|         appState.navigate(route) | ||||
|     } | ||||
| 
 | ||||
|     val openAndPopUp: (String, String) -> Unit = { | ||||
|             route, popUp -> appState.navigateAndPopUp(route, popUp) | ||||
|     val openAndPopUp: (String, String) -> Unit = { route, popUp -> | ||||
|         appState.navigateAndPopUp(route, popUp) | ||||
|     } | ||||
| 
 | ||||
|     composable(StudeezDestinations.SPLASH_SCREEN) { | ||||
|  | @ -106,7 +113,7 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | |||
|     } | ||||
| 
 | ||||
|     composable(StudeezDestinations.HOME_SCREEN) { | ||||
|         HomeScreen(open, openAndPopUp) | ||||
|         HomeRoute(open, openAndPopUp, viewModel = hiltViewModel()) | ||||
|     } | ||||
| 
 | ||||
|     // TODO Tasks screen | ||||
|  |  | |||
|  | @ -31,6 +31,20 @@ data class DrawerActions( | |||
|     val onAboutClick: () -> Unit, | ||||
| ) | ||||
| 
 | ||||
| fun getDrawerActions( | ||||
|     drawerViewModel: DrawerViewModel, | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
| ): DrawerActions { | ||||
|     return DrawerActions( | ||||
|         onHomeButtonClick = { drawerViewModel.onHomeButtonClick(open) }, | ||||
|         onTimersClick = { drawerViewModel.onTimersClick(open) }, | ||||
|         onSettingsClick = { drawerViewModel.onSettingsClick(open) }, | ||||
|         onLogoutClick = { drawerViewModel.onLogoutClick(openAndPopUp) }, | ||||
|         onAboutClick = { drawerViewModel.onAboutClick(open) }, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun Drawer( | ||||
|     drawerActions: DrawerActions, | ||||
|  |  | |||
|  | @ -15,8 +15,10 @@ import be.ugent.sel.studeez.common.ext.basicButton | |||
| 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 | ||||
| 
 | ||||
| @Composable | ||||
| fun HomeRoute( | ||||
|  | @ -25,33 +27,19 @@ fun HomeRoute( | |||
|     viewModel: HomeViewModel, | ||||
| ) { | ||||
|     HomeScreen( | ||||
|         open = open, | ||||
|         openAndPopUp = openAndPopUp, | ||||
|         onStartSessionClick = { viewModel.onStartSessionClick(open) } | ||||
|         onStartSessionClick = { viewModel.onStartSessionClick(open) }, | ||||
|         drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp), | ||||
|         navigationBarActions = getNavigationBarActions(hiltViewModel(), open), | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun HomeScreen( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     onStartSessionClick: () -> Unit, | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
| ) { | ||||
|     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) }, | ||||
|     ) | ||||
| 
 | ||||
|     PrimaryScreenTemplate( | ||||
|         title = resources().getString(R.string.home), | ||||
|         drawerActions = drawerActions, | ||||
|  | @ -77,5 +65,9 @@ fun FriendsAction() { | |||
| @Preview | ||||
| @Composable | ||||
| fun HomeScreenPreview() { | ||||
|     HomeScreen(open = {}, openAndPopUp = { _, _ -> run {} }, onStartSessionClick = {}) | ||||
|     HomeScreen( | ||||
|         onStartSessionClick = {}, | ||||
|         drawerActions = DrawerActions({}, {}, {}, {}, {}), | ||||
|         navigationBarActions = NavigationBarActions({}, {}, {}, {}) | ||||
|     ) | ||||
| } | ||||
|  |  | |||
|  | @ -23,6 +23,18 @@ data class NavigationBarActions( | |||
|     val onProfileClick: () -> Unit, | ||||
| ) | ||||
| 
 | ||||
| fun getNavigationBarActions( | ||||
|     navigationBarViewModel: NavigationBarViewModel, | ||||
|     open: (String) -> Unit, | ||||
| ): NavigationBarActions { | ||||
|     return NavigationBarActions( | ||||
|         onHomeClick = { navigationBarViewModel.onHomeClick(open) }, | ||||
|         onTasksClick = { navigationBarViewModel.onTasksClick(open) }, | ||||
|         onSessionsClick = { navigationBarViewModel.onSessionsClick(open) }, | ||||
|         onProfileClick = { navigationBarViewModel.onProfileClick(open) }, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun NavigationBar( | ||||
|     navigationBarActions: NavigationBarActions, | ||||
|  |  | |||
		Reference in a new issue
	
	 brreynie
						brreynie