wrap profilescreen in route
This commit is contained in:
		
							parent
							
								
									90170eb635
								
							
						
					
					
						commit
						3fd191cccc
					
				
					 2 changed files with 55 additions and 24 deletions
				
			
		|  | @ -30,6 +30,7 @@ import be.ugent.sel.studeez.screens.log_in.LoginRoute | |||
| import be.ugent.sel.studeez.screens.log_in.LoginScreen | ||||
| import be.ugent.sel.studeez.screens.profile.EditProfileRoute | ||||
| import be.ugent.sel.studeez.screens.profile.EditProfileScreen | ||||
| import be.ugent.sel.studeez.screens.profile.ProfileRoute | ||||
| 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 | ||||
|  | @ -122,7 +123,7 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | |||
|     // TODO Sessions screen | ||||
| 
 | ||||
|     composable(StudeezDestinations.PROFILE_SCREEN) { | ||||
|         ProfileScreen(open, openAndPopUp) | ||||
|         ProfileRoute(open, openAndPopUp, viewModel = hiltViewModel()) | ||||
|     } | ||||
| 
 | ||||
|     composable(StudeezDestinations.TIMER_OVERVIEW_SCREEN) { | ||||
|  |  | |||
|  | @ -4,48 +4,68 @@ 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.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 kotlinx.coroutines.CoroutineScope | ||||
| import be.ugent.sel.studeez.R.string as AppText | ||||
| 
 | ||||
| data class ProfileActions( | ||||
|     val getUsername: suspend CoroutineScope.() -> String?, | ||||
|     val onEditProfileClick: () -> Unit, | ||||
| ) | ||||
| 
 | ||||
| fun getProfileActions( | ||||
|     viewModel: ProfileViewModel, | ||||
|     open: (String) -> Unit, | ||||
| ): ProfileActions { | ||||
|     return ProfileActions( | ||||
|         getUsername = { viewModel.getUsername() }, | ||||
|         onEditProfileClick = { viewModel.onEditProfileClick(open) }, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun ProfileRoute( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     viewModel: ProfileViewModel, | ||||
| ) { | ||||
|     ProfileScreen( | ||||
|         profileActions = getProfileActions(viewModel, open), | ||||
|         drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp), | ||||
|         navigationBarActions = getNavigationBarActions(hiltViewModel(), open), | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| @Composable | ||||
| fun ProfileScreen( | ||||
|     open: (String) -> Unit, | ||||
|     openAndPopUp: (String, String) -> Unit, | ||||
|     viewModel: ProfileViewModel = hiltViewModel() | ||||
|     profileActions: ProfileActions, | ||||
|     drawerActions: DrawerActions, | ||||
|     navigationBarActions: NavigationBarActions, | ||||
| ) { | ||||
|     var username: String? by remember { mutableStateOf("") } | ||||
|     LaunchedEffect(key1 = Unit) { | ||||
|         username = viewModel.getUsername() | ||||
|         username = profileActions.getUsername(this) | ||||
|     } | ||||
|     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(AppText.profile), | ||||
|         drawerActions = drawerActions, | ||||
|         navigationBarActions = navigationBarActions, | ||||
|         action = { EditAction { viewModel.onEditProfileClick(open) } } | ||||
|         action = { EditAction(onClick = profileActions.onEditProfileClick) } | ||||
|     ) { | ||||
|         Headline(text = (username ?: resources().getString(R.string.no_username))) | ||||
|     } | ||||
|  | @ -62,4 +82,14 @@ fun EditAction( | |||
|         ) | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Preview | ||||
| @Composable | ||||
| fun ProfileScreenPreview() { | ||||
|     ProfileScreen( | ||||
|         profileActions = ProfileActions({ null }, {}), | ||||
|         drawerActions = DrawerActions({}, {}, {}, {}, {}), | ||||
|         navigationBarActions = NavigationBarActions({}, {}, {}, {}) | ||||
|     ) | ||||
| } | ||||
		Reference in a new issue
	
	 brreynie
						brreynie