Make use of open instead of always openAndPopUp
This commit is contained in:
		
							parent
							
								
									da3f8d3377
								
							
						
					
					
						commit
						13140d4e3c
					
				
					 8 changed files with 47 additions and 48 deletions
				
			
		|  | @ -80,6 +80,10 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | ||||||
|             route, popUp -> appState.navigateAndPopUp(route, popUp) |             route, popUp -> appState.navigateAndPopUp(route, popUp) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     val open: (String) -> Unit = { | ||||||
|  |         route -> appState.navigate(route) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     composable(StudeezDestinations.SPLASH_SCREEN) { |     composable(StudeezDestinations.SPLASH_SCREEN) { | ||||||
|         SplashScreen(openAndPopUp) |         SplashScreen(openAndPopUp) | ||||||
|     } |     } | ||||||
|  | @ -93,6 +97,6 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     composable(StudeezDestinations.HOME_SCREEN) { |     composable(StudeezDestinations.HOME_SCREEN) { | ||||||
|         HomeScreen(openAndPopUp) |         HomeScreen(open, openAndPopUp) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -18,6 +18,7 @@ import kotlinx.coroutines.launch | ||||||
| @Composable | @Composable | ||||||
| fun PrimaryScreenTemplate( | fun PrimaryScreenTemplate( | ||||||
|     title: String, |     title: String, | ||||||
|  |     open: (String) -> Unit, | ||||||
|     openAndPopUp: (String, String) -> Unit, |     openAndPopUp: (String, String) -> Unit, | ||||||
|     content: @Composable (PaddingValues) -> Unit |     content: @Composable (PaddingValues) -> Unit | ||||||
| ) { | ) { | ||||||
|  | @ -42,10 +43,10 @@ fun PrimaryScreenTemplate( | ||||||
|         ) }, |         ) }, | ||||||
| 
 | 
 | ||||||
|         drawerContent = { |         drawerContent = { | ||||||
|             Drawer(openAndPopUp) |             Drawer(open, openAndPopUp) | ||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         bottomBar = { NavigationBar(openAndPopUp) }, |         bottomBar = { NavigationBar(open) }, | ||||||
|         floatingActionButtonPosition = FabPosition.Center, |         floatingActionButtonPosition = FabPosition.Center, | ||||||
|         isFloatingActionButtonDocked = true, |         isFloatingActionButtonDocked = true, | ||||||
|         floatingActionButton = { CollapsedAddButton() } |         floatingActionButton = { CollapsedAddButton() } | ||||||
|  | @ -60,6 +61,7 @@ fun PrimaryScreenPreview() { | ||||||
|     StudeezTheme { |     StudeezTheme { | ||||||
|         PrimaryScreenTemplate( |         PrimaryScreenTemplate( | ||||||
|             "Preview screen", |             "Preview screen", | ||||||
|  |             { _ -> {}}, | ||||||
|             { _, _ -> {}} |             { _, _ -> {}} | ||||||
|         ) {} |         ) {} | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -23,6 +23,7 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun Drawer( | fun Drawer( | ||||||
|  |     open: (String) -> Unit, | ||||||
|     openAndPopUp: (String, String) -> Unit, |     openAndPopUp: (String, String) -> Unit, | ||||||
|     viewModel: DrawerViewModel = hiltViewModel() |     viewModel: DrawerViewModel = hiltViewModel() | ||||||
| ) { | ) { | ||||||
|  | @ -36,19 +37,19 @@ fun Drawer( | ||||||
|                 icon = Icons.Default.Home, |                 icon = Icons.Default.Home, | ||||||
|                 text = resources().getString(R.string.home) |                 text = resources().getString(R.string.home) | ||||||
|             ) { |             ) { | ||||||
|                 // TODO Go to home |                 viewModel.onHomeButtonClick(open) | ||||||
|             } |             } | ||||||
|             DrawerEntry( |             DrawerEntry( | ||||||
|                 icon = ImageVector.vectorResource(id = R.drawable.ic_timer), |                 icon = ImageVector.vectorResource(id = R.drawable.ic_timer), | ||||||
|                 text = resources().getString(R.string.timers) |                 text = resources().getString(R.string.timers) | ||||||
|             ) { |             ) { | ||||||
|                 viewModel.onTimersClick(openAndPopUp) |                 viewModel.onTimersClick(open) | ||||||
|             } |             } | ||||||
|             DrawerEntry( |             DrawerEntry( | ||||||
|                 icon = Icons.Default.Settings, |                 icon = Icons.Default.Settings, | ||||||
|                 text = resources().getString(R.string.settings) |                 text = resources().getString(R.string.settings) | ||||||
|             ) { |             ) { | ||||||
|                 viewModel.onSettingsClick(openAndPopUp) |                 viewModel.onSettingsClick(open) | ||||||
|             } |             } | ||||||
|             DrawerEntry( |             DrawerEntry( | ||||||
|                 icon = ImageVector.vectorResource(id = R.drawable.ic_logout), |                 icon = ImageVector.vectorResource(id = R.drawable.ic_logout), | ||||||
|  | @ -62,7 +63,7 @@ fun Drawer( | ||||||
|             icon = Icons.Outlined.Info, |             icon = Icons.Outlined.Info, | ||||||
|             text = resources().getString(R.string.about) |             text = resources().getString(R.string.about) | ||||||
|         ) { |         ) { | ||||||
|             viewModel.onAboutClick(openAndPopUp) |             viewModel.onAboutClick(open) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -101,7 +102,9 @@ fun DrawerEntry( | ||||||
| fun DrawerPreview() { | fun DrawerPreview() { | ||||||
|     StudeezTheme { |     StudeezTheme { | ||||||
|         Drawer( |         Drawer( | ||||||
|             {a, b -> {}}, hiltViewModel() |             { _, -> {} }, | ||||||
|  |             { _, _ -> {} }, | ||||||
|  |             hiltViewModel() | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -13,6 +13,18 @@ class DrawerViewModel @Inject constructor( | ||||||
|     logService: LogService |     logService: LogService | ||||||
| ) : StudeezViewModel(logService) { | ) : StudeezViewModel(logService) { | ||||||
| 
 | 
 | ||||||
|  |     fun onHomeButtonClick(open: (String) -> Unit) { | ||||||
|  |         // TODO | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fun onTimersClick(open: (String) -> Unit) { | ||||||
|  |         // TODO | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fun onSettingsClick(open: (String) -> Unit) { | ||||||
|  |         // TODO | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     fun onLogoutClick(openAndPopup: (String, String) -> Unit) { |     fun onLogoutClick(openAndPopup: (String, String) -> Unit) { | ||||||
|         launchCatching { |         launchCatching { | ||||||
|             accountDAO.signOut() |             accountDAO.signOut() | ||||||
|  | @ -20,19 +32,7 @@ class DrawerViewModel @Inject constructor( | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun onHomeButtonClick(openAndPopup: (String, String) -> Unit) { |     fun onAboutClick(open: (String) -> Unit) { | ||||||
|         // TODO |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     fun onTimersClick(openAndPopup: (String, String) -> Unit) { |  | ||||||
|         // TODO |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     fun onSettingsClick(openAndPopup: (String, String) -> Unit) { |  | ||||||
|         // TODO |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     fun onAboutClick(openAndPopup: (String, String) -> Unit) { |  | ||||||
|         // TODO |         // TODO | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -11,15 +11,17 @@ import be.ugent.sel.studeez.resources | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun HomeScreen( | fun HomeScreen( | ||||||
|  |     open: (String) -> Unit, | ||||||
|     openAndPopUp: (String, String) -> Unit, |     openAndPopUp: (String, String) -> Unit, | ||||||
|     viewModel: HomeViewModel = hiltViewModel() |     viewModel: HomeViewModel = hiltViewModel() | ||||||
| ) { | ) { | ||||||
|     PrimaryScreenTemplate( |     PrimaryScreenTemplate( | ||||||
|         title = resources().getString(R.string.home), |         title = resources().getString(R.string.home), | ||||||
|  |         open = open, | ||||||
|         openAndPopUp = openAndPopUp |         openAndPopUp = openAndPopUp | ||||||
|     ) { |     ) { | ||||||
|         BasicButton(R.string.start_session, Modifier.basicButton()) { |         BasicButton(R.string.start_session, Modifier.basicButton()) { | ||||||
|             viewModel.onStartSessionClick(openAndPopUp) |             viewModel.onStartSessionClick(open) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -1,15 +1,9 @@ | ||||||
| package be.ugent.sel.studeez.screens.home | package be.ugent.sel.studeez.screens.home | ||||||
| 
 | 
 | ||||||
| import androidx.compose.material.ScaffoldState |  | ||||||
| import androidx.compose.material.rememberScaffoldState |  | ||||||
| import be.ugent.sel.studeez.data.local.models.User |  | ||||||
| import be.ugent.sel.studeez.domain.AccountDAO | import be.ugent.sel.studeez.domain.AccountDAO | ||||||
| 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.LOGIN_SCREEN |  | ||||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | import be.ugent.sel.studeez.screens.StudeezViewModel | ||||||
| import dagger.hilt.android.lifecycle.HiltViewModel | import dagger.hilt.android.lifecycle.HiltViewModel | ||||||
| import kotlinx.coroutines.flow.Flow |  | ||||||
| import javax.inject.Inject | import javax.inject.Inject | ||||||
| 
 | 
 | ||||||
| @HiltViewModel | @HiltViewModel | ||||||
|  | @ -18,14 +12,7 @@ class HomeViewModel @Inject constructor( | ||||||
|     logService: LogService |     logService: LogService | ||||||
| ) : StudeezViewModel(logService) { | ) : StudeezViewModel(logService) { | ||||||
| 
 | 
 | ||||||
|     fun onStartSessionClick(openAndPopUp: (String, String) -> Unit) { |     fun onStartSessionClick(open: (String) -> Unit) { | ||||||
|         // TODO openAndPopUp(StudeezDestinations.xxx, StudeezDestinations.HOME_SCREEN) |         // TODO open(StudeezDestinations.xxx, StudeezDestinations.HOME_SCREEN) | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     fun onLogoutClick(openAndPopup: (String, String) -> Unit) { |  | ||||||
|         launchCatching { |  | ||||||
|             accountDAO.signOut() |  | ||||||
|             openAndPopup(LOGIN_SCREEN, HOME_SCREEN) |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -20,7 +20,7 @@ import be.ugent.sel.studeez.R.string as AppText | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun NavigationBar( | fun NavigationBar( | ||||||
|     popUpAndOpen: (String, String) -> Unit, |     open: (String) -> Unit, | ||||||
|     viewModel: NavigationBarViewModel = hiltViewModel() |     viewModel: NavigationBarViewModel = hiltViewModel() | ||||||
| ) { | ) { | ||||||
|     // TODO Pass functions and new screens. |     // TODO Pass functions and new screens. | ||||||
|  | @ -33,14 +33,14 @@ fun NavigationBar( | ||||||
|             icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) }, |             icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) }, | ||||||
|             label = { Text(text = resources().getString(AppText.home)) }, |             label = { Text(text = resources().getString(AppText.home)) }, | ||||||
|             selected = false, // TODO |             selected = false, // TODO | ||||||
|             onClick = { viewModel.onHomeClick(popUpAndOpen) } |             onClick = { viewModel.onHomeClick(open) } | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         BottomNavigationItem( |         BottomNavigationItem( | ||||||
|             icon = { Icon(imageVector = Icons.Default.Check, resources().getString(AppText.tasks)) }, |             icon = { Icon(imageVector = Icons.Default.Check, resources().getString(AppText.tasks)) }, | ||||||
|             label = { Text(text = resources().getString(AppText.tasks)) }, |             label = { Text(text = resources().getString(AppText.tasks)) }, | ||||||
|             selected = false, // TODO |             selected = false, // TODO | ||||||
|             onClick = { viewModel.onTasksClick(popUpAndOpen) } |             onClick = { viewModel.onTasksClick(open) } | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         // Hack to space the entries in the navigation bar, make space for fab |         // Hack to space the entries in the navigation bar, make space for fab | ||||||
|  | @ -50,14 +50,14 @@ fun NavigationBar( | ||||||
|             icon = { Icon(imageVector = Icons.Outlined.DateRange, resources().getString(AppText.sessions)) }, |             icon = { Icon(imageVector = Icons.Outlined.DateRange, resources().getString(AppText.sessions)) }, | ||||||
|             label = { Text(text = resources().getString(AppText.sessions)) }, |             label = { Text(text = resources().getString(AppText.sessions)) }, | ||||||
|             selected = false, // TODO |             selected = false, // TODO | ||||||
|             onClick = { viewModel.onSessionsClick(popUpAndOpen) } |             onClick = { viewModel.onSessionsClick(open) } | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         BottomNavigationItem( |         BottomNavigationItem( | ||||||
|             icon = { Icon(imageVector = Icons.Default.Person, resources().getString(AppText.profile)) }, |             icon = { Icon(imageVector = Icons.Default.Person, resources().getString(AppText.profile)) }, | ||||||
|             label = { Text(text = resources().getString(AppText.profile)) }, |             label = { Text(text = resources().getString(AppText.profile)) }, | ||||||
|             selected = false, // TODO |             selected = false, // TODO | ||||||
|             onClick = { viewModel.onProfileClick(popUpAndOpen) } |             onClick = { viewModel.onProfileClick(open) } | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  | @ -68,7 +68,7 @@ fun NavigationBar( | ||||||
| fun NavigationBarPreview() { | fun NavigationBarPreview() { | ||||||
|     StudeezTheme { |     StudeezTheme { | ||||||
|         NavigationBar( |         NavigationBar( | ||||||
|             { _, _ -> {} }, |             { _ -> {} }, | ||||||
|             hiltViewModel() |             hiltViewModel() | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ package be.ugent.sel.studeez.screens.navbar | ||||||
| import be.ugent.sel.studeez.domain.AccountDAO | import be.ugent.sel.studeez.domain.AccountDAO | ||||||
| import be.ugent.sel.studeez.domain.LogService | import be.ugent.sel.studeez.domain.LogService | ||||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations | import be.ugent.sel.studeez.navigation.StudeezDestinations | ||||||
|  | import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN | ||||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | import be.ugent.sel.studeez.screens.StudeezViewModel | ||||||
| import dagger.hilt.android.lifecycle.HiltViewModel | import dagger.hilt.android.lifecycle.HiltViewModel | ||||||
| import javax.inject.Inject | import javax.inject.Inject | ||||||
|  | @ -13,19 +14,19 @@ class NavigationBarViewModel @Inject constructor( | ||||||
|     logService: LogService |     logService: LogService | ||||||
| ) : StudeezViewModel(logService) { | ) : StudeezViewModel(logService) { | ||||||
| 
 | 
 | ||||||
|     fun onHomeClick(openAndPopup: (String, String) -> Unit) { |     fun onHomeClick(open: (String) -> Unit) { | ||||||
|         // TODO |         // TODO | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun onTasksClick(openAndPopup: (String, String) -> Unit) { |     fun onTasksClick(open: (String) -> Unit) { | ||||||
|         // TODO |         // TODO | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun onSessionsClick(openAndPopup: (String, String) -> Unit) { |     fun onSessionsClick(open: (String) -> Unit) { | ||||||
|         // TODO |         // TODO | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun onProfileClick(openAndPopup: (String, String) -> Unit) { |     fun onProfileClick(open: (String) -> Unit) { | ||||||
|         // TODO |         open(PROFILE_SCREEN) | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in a new issue