extract navbar and draweractions to StudeezNavGraph
This commit is contained in:
		
							parent
							
								
									cf91d727a0
								
							
						
					
					
						commit
						010c7cff54
					
				
					 6 changed files with 72 additions and 67 deletions
				
			
		|  | @ -2,8 +2,18 @@ package be.ugent.sel.studeez | |||
| 
 | ||||
| import android.content.res.Resources | ||||
| import androidx.compose.foundation.layout.padding | ||||
| import androidx.compose.material.* | ||||
| import androidx.compose.runtime.* | ||||
| 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.getValue | ||||
| import androidx.compose.runtime.remember | ||||
| import androidx.compose.runtime.rememberCoroutineScope | ||||
| import androidx.compose.ui.Modifier | ||||
| import androidx.compose.ui.platform.LocalConfiguration | ||||
| import androidx.compose.ui.platform.LocalContext | ||||
|  | @ -14,8 +24,12 @@ import androidx.navigation.compose.NavHost | |||
| import androidx.navigation.compose.composable | ||||
| import androidx.navigation.compose.currentBackStackEntryAsState | ||||
| import androidx.navigation.compose.rememberNavController | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel | ||||
| import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel | ||||
| import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions | ||||
| import be.ugent.sel.studeez.common.snackbar.SnackbarManager | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations | ||||
| import be.ugent.sel.studeez.screens.home.HomeRoute | ||||
|  | @ -82,48 +96,51 @@ fun StudeezNavGraph( | |||
|     val navBarViewModel: NavigationBarViewModel = hiltViewModel() | ||||
| 
 | ||||
|     val backStackEntry by appState.navController.currentBackStackEntryAsState() | ||||
|     val getCurrentScreen: () -> String? = { backStackEntry?.destination?.route } | ||||
| 
 | ||||
|     val goBack: () -> Unit = { appState.popUp() } | ||||
|     val open: (String) -> Unit = { appState.navigate(it) } | ||||
|     val openAndPopUp: (String, String) -> Unit = | ||||
|         { route, popUp -> appState.navigateAndPopUp(route, popUp) } | ||||
| 
 | ||||
|     val drawerActions: DrawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp) | ||||
|     val navigationBarActions: NavigationBarActions = | ||||
|         getNavigationBarActions(navBarViewModel, open, getCurrentScreen) | ||||
| 
 | ||||
|     NavHost( | ||||
|         navController = appState.navController, | ||||
|         startDestination = StudeezDestinations.SPLASH_SCREEN, | ||||
|         modifier = modifier, | ||||
|     ) { | ||||
|         val goBack: () -> Unit = { | ||||
|             appState.popUp() | ||||
|         } | ||||
| 
 | ||||
|         val open: (String) -> Unit = { route -> | ||||
|             appState.navigate(route) | ||||
|         } | ||||
| 
 | ||||
|         val openAndPopUp: (String, String) -> Unit = { route, popUp -> | ||||
|             appState.navigateAndPopUp(route, popUp) | ||||
|         } | ||||
| 
 | ||||
|         val getCurrentScreen: () -> String? = { | ||||
|             backStackEntry?.destination?.route | ||||
|         } | ||||
| 
 | ||||
|         composable(StudeezDestinations.SPLASH_SCREEN) { | ||||
|             SplashRoute(openAndPopUp, viewModel = hiltViewModel()) | ||||
|             SplashRoute( | ||||
|                 openAndPopUp, | ||||
|                 viewModel = hiltViewModel(), | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         composable(StudeezDestinations.LOGIN_SCREEN) { | ||||
|             LoginRoute(openAndPopUp, viewModel = hiltViewModel()) | ||||
|             LoginRoute( | ||||
|                 openAndPopUp, | ||||
|                 viewModel = hiltViewModel(), | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         composable(StudeezDestinations.SIGN_UP_SCREEN) { | ||||
|             SignUpRoute(openAndPopUp, viewModel = hiltViewModel()) | ||||
|             SignUpRoute( | ||||
|                 openAndPopUp, | ||||
|                 viewModel = hiltViewModel(), | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         composable(StudeezDestinations.HOME_SCREEN) { | ||||
|             HomeRoute( | ||||
|                 open, | ||||
|                 openAndPopUp, | ||||
|                 getCurrentScreen, | ||||
|                 viewModel = hiltViewModel(), | ||||
|                 drawerViewModel = drawerViewModel, | ||||
|                 navBarViewModel = navBarViewModel, | ||||
|                 drawerActions = drawerActions, | ||||
|                 navigationBarActions = navigationBarActions, | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|  | @ -131,20 +148,26 @@ fun StudeezNavGraph( | |||
|         // TODO Sessions screen | ||||
| 
 | ||||
|         composable(StudeezDestinations.PROFILE_SCREEN) { | ||||
|             ProfileRoute(open, openAndPopUp, getCurrentScreen, viewModel = hiltViewModel()) | ||||
|             ProfileRoute( | ||||
|                 open, | ||||
|                 viewModel = hiltViewModel(), | ||||
|                 drawerActions = drawerActions, | ||||
|                 navigationBarActions = navigationBarActions, | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         composable(StudeezDestinations.TIMER_OVERVIEW_SCREEN) { | ||||
|             TimerOverviewRoute( | ||||
|                 open, | ||||
|                 openAndPopUp, | ||||
|                 viewModel = hiltViewModel(), | ||||
|                 drawerViewModel = drawerViewModel | ||||
|                 drawerActions = drawerActions, | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         composable(StudeezDestinations.SESSION_SCREEN) { | ||||
|             SessionRoute(open, viewModel = hiltViewModel()) | ||||
|             SessionRoute( | ||||
|                 open, | ||||
|                 viewModel = hiltViewModel() | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         // TODO Timers screen | ||||
|  | @ -152,18 +175,18 @@ fun StudeezNavGraph( | |||
| 
 | ||||
|         // Edit screens | ||||
|         composable(StudeezDestinations.EDIT_PROFILE_SCREEN) { | ||||
|             EditProfileRoute(goBack, openAndPopUp, viewModel = hiltViewModel()) | ||||
|             EditProfileRoute( | ||||
|                 goBack, | ||||
|                 openAndPopUp, | ||||
|                 viewModel = hiltViewModel(), | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         composable(StudeezDestinations.TIMER_SELECTION_SCREEN) { | ||||
|             TimerSelectionRoute( | ||||
|                 open, | ||||
|                 openAndPopUp, | ||||
|                 goBack, | ||||
|                 getCurrentScreen, | ||||
|                 viewModel = hiltViewModel(), | ||||
|                 drawerViewModel = drawerViewModel, | ||||
|                 navBarViewModel = navBarViewModel, | ||||
|             ) | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -11,27 +11,21 @@ import be.ugent.sel.studeez.R | |||
| import be.ugent.sel.studeez.common.composable.BasicButton | ||||
| import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel | ||||
| import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel | ||||
| import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions | ||||
| import be.ugent.sel.studeez.common.ext.basicButton | ||||
| import be.ugent.sel.studeez.resources | ||||
| 
 | ||||
| @Composable | ||||
| fun HomeRoute( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     getCurrentScreen: () -> String?, | ||||
|     viewModel: HomeViewModel, | ||||
|     drawerViewModel: DrawerViewModel, | ||||
|     navBarViewModel: NavigationBarViewModel, | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
| ) { | ||||
|     HomeScreen( | ||||
|         onStartSessionClick = { viewModel.onStartSessionClick(open) }, | ||||
|         drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp), | ||||
|         navigationBarActions = getNavigationBarActions(navBarViewModel, open, getCurrentScreen), | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
|  | @ -41,7 +35,6 @@ fun HomeScreen( | |||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
| ) { | ||||
| 
 | ||||
|     PrimaryScreenTemplate( | ||||
|         title = resources().getString(R.string.home), | ||||
|         drawerActions = drawerActions, | ||||
|  |  | |||
|  | @ -4,16 +4,18 @@ import androidx.compose.material.Icon | |||
| import androidx.compose.material.IconButton | ||||
| import androidx.compose.material.icons.Icons | ||||
| import androidx.compose.material.icons.filled.Edit | ||||
| import androidx.compose.runtime.* | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.LaunchedEffect | ||||
| import androidx.compose.runtime.getValue | ||||
| import androidx.compose.runtime.mutableStateOf | ||||
| import androidx.compose.runtime.remember | ||||
| import androidx.compose.runtime.setValue | ||||
| import androidx.compose.ui.tooling.preview.Preview | ||||
| import androidx.hilt.navigation.compose.hiltViewModel | ||||
| import be.ugent.sel.studeez.R | ||||
| import be.ugent.sel.studeez.common.composable.Headline | ||||
| import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions | ||||
| import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions | ||||
| import be.ugent.sel.studeez.resources | ||||
| import kotlinx.coroutines.CoroutineScope | ||||
| import be.ugent.sel.studeez.R.string as AppText | ||||
|  | @ -36,14 +38,14 @@ fun getProfileActions( | |||
| @Composable | ||||
| fun ProfileRoute( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     getCurrentScreen: () -> String?, | ||||
|     viewModel: ProfileViewModel, | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
| ) { | ||||
|     ProfileScreen( | ||||
|         profileActions = getProfileActions(viewModel, open), | ||||
|         drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp), | ||||
|         navigationBarActions = getNavigationBarActions(hiltViewModel(), open, getCurrentScreen), | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,5 @@ | |||
| package be.ugent.sel.studeez.screens.splash | ||||
| 
 | ||||
| import android.window.SplashScreen | ||||
| import androidx.compose.foundation.background | ||||
| import androidx.compose.foundation.layout.Arrangement | ||||
| import androidx.compose.foundation.layout.Column | ||||
|  |  | |||
|  | @ -13,8 +13,6 @@ import be.ugent.sel.studeez.common.composable.DrawerScreenTemplate | |||
| import be.ugent.sel.studeez.common.composable.StealthButton | ||||
| import be.ugent.sel.studeez.common.composable.TimerEntry | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel | ||||
| import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions | ||||
| import be.ugent.sel.studeez.common.ext.basicButton | ||||
| import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo | ||||
| import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | ||||
|  | @ -40,14 +38,12 @@ fun getTimerOverviewActions( | |||
| 
 | ||||
| @Composable | ||||
| fun TimerOverviewRoute( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     viewModel: TimerOverviewViewModel, | ||||
|     drawerViewModel: DrawerViewModel | ||||
|     drawerActions: DrawerActions, | ||||
| ) { | ||||
|     TimerOverviewScreen( | ||||
|         timerOverviewActions = getTimerOverviewActions(viewModel), | ||||
|         drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp) | ||||
|         drawerActions = drawerActions, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,8 +2,6 @@ package be.ugent.sel.studeez.screens.timer_selection | |||
| 
 | ||||
| import androidx.compose.foundation.lazy.LazyColumn | ||||
| import androidx.compose.foundation.lazy.items | ||||
| import androidx.compose.material.Text | ||||
| import androidx.compose.material.TextButton | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.collectAsState | ||||
| import androidx.compose.ui.tooling.preview.Preview | ||||
|  | @ -11,8 +9,6 @@ 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.TimerEntry | ||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel | ||||
| import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel | ||||
| import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | ||||
| import be.ugent.sel.studeez.resources | ||||
| import kotlinx.coroutines.flow.Flow | ||||
|  | @ -36,12 +32,8 @@ fun getTimerSelectionActions( | |||
| @Composable | ||||
| fun TimerSelectionRoute( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     popUp: () -> Unit, | ||||
|     getCurrentScreen: () -> String?, | ||||
|     viewModel: TimerSelectionViewModel, | ||||
|     drawerViewModel: DrawerViewModel, | ||||
|     navBarViewModel: NavigationBarViewModel, | ||||
| ) { | ||||
|     TimerSelectionScreen( | ||||
|         timerSelectionActions = getTimerSelectionActions(viewModel, open), | ||||
|  |  | |||
		Reference in a new issue
	
	 brreynie
						brreynie