New DrawerScreen for TimerOverView
This commit is contained in:
		
							parent
							
								
									c73c06b11c
								
							
						
					
					
						commit
						7b3a82cc30
					
				
					 3 changed files with 59 additions and 18 deletions
				
			
		|  | @ -141,8 +141,7 @@ fun StudeezNavGraph( | ||||||
|                 open, |                 open, | ||||||
|                 openAndPopUp, |                 openAndPopUp, | ||||||
|                 viewModel = hiltViewModel(), |                 viewModel = hiltViewModel(), | ||||||
|                 drawerViewModel = drawerViewModel, |                 drawerViewModel = drawerViewModel | ||||||
|                 navBarViewModel = navBarViewModel, |  | ||||||
|             ) |             ) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -0,0 +1,51 @@ | ||||||
|  | package be.ugent.sel.studeez.common.composable | ||||||
|  | 
 | ||||||
|  | import androidx.compose.foundation.layout.PaddingValues | ||||||
|  | import androidx.compose.foundation.layout.RowScope | ||||||
|  | import androidx.compose.material.* | ||||||
|  | import androidx.compose.material.icons.Icons | ||||||
|  | import androidx.compose.material.icons.filled.Menu | ||||||
|  | import androidx.compose.runtime.Composable | ||||||
|  | import androidx.compose.runtime.rememberCoroutineScope | ||||||
|  | import be.ugent.sel.studeez.common.composable.drawer.Drawer | ||||||
|  | import be.ugent.sel.studeez.common.composable.drawer.DrawerActions | ||||||
|  | import be.ugent.sel.studeez.resources | ||||||
|  | import kotlinx.coroutines.CoroutineScope | ||||||
|  | import kotlinx.coroutines.launch | ||||||
|  | import be.ugent.sel.studeez.R.string as AppText | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun DrawerScreenTemplate( | ||||||
|  |     title: String, | ||||||
|  |     drawerActions: DrawerActions, | ||||||
|  |     action: @Composable RowScope.() -> Unit = {}, | ||||||
|  |     content: @Composable (PaddingValues) -> Unit | ||||||
|  | ) { | ||||||
|  |     val scaffoldState: ScaffoldState = rememberScaffoldState() | ||||||
|  |     val coroutineScope: CoroutineScope = rememberCoroutineScope() | ||||||
|  | 
 | ||||||
|  |     Scaffold( | ||||||
|  |         scaffoldState = scaffoldState, | ||||||
|  | 
 | ||||||
|  |         topBar = { TopAppBar( | ||||||
|  |             title = { Text(text = title) }, | ||||||
|  |             navigationIcon = { | ||||||
|  |                 IconButton(onClick = { | ||||||
|  |                     coroutineScope.launch { scaffoldState.drawerState.open() } | ||||||
|  |                 }) { | ||||||
|  |                     Icon( | ||||||
|  |                         imageVector = Icons.Default.Menu, | ||||||
|  |                         contentDescription = resources().getString(AppText.menu) | ||||||
|  |                     ) | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             actions = action | ||||||
|  |         )}, | ||||||
|  | 
 | ||||||
|  |         drawerContent = { | ||||||
|  |             Drawer(drawerActions) | ||||||
|  |         } | ||||||
|  |     ) { | ||||||
|  |         content(it) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -10,10 +10,7 @@ import androidx.compose.ui.Modifier | ||||||
| import androidx.compose.ui.tooling.preview.Preview | import androidx.compose.ui.tooling.preview.Preview | ||||||
| import androidx.compose.ui.unit.dp | import androidx.compose.ui.unit.dp | ||||||
| import be.ugent.sel.studeez.R | import be.ugent.sel.studeez.R | ||||||
| import be.ugent.sel.studeez.common.composable.BasicButton | import be.ugent.sel.studeez.common.composable.* | ||||||
| import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate |  | ||||||
| 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.DrawerActions | ||||||
| import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel | 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.drawer.getDrawerActions | ||||||
|  | @ -48,30 +45,25 @@ fun TimerOverviewRoute( | ||||||
|     open: (String) -> Unit, |     open: (String) -> Unit, | ||||||
|     openAndPopUp: (String, String) -> Unit, |     openAndPopUp: (String, String) -> Unit, | ||||||
|     viewModel: TimerOverviewViewModel, |     viewModel: TimerOverviewViewModel, | ||||||
|     drawerViewModel: DrawerViewModel, |     drawerViewModel: DrawerViewModel | ||||||
|     navBarViewModel: NavigationBarViewModel, |  | ||||||
| ) { | ) { | ||||||
|     TimerOverviewScreen( |     TimerOverviewScreen( | ||||||
|         timerOverviewActions = getTimerOverviewActions(viewModel), |         timerOverviewActions = getTimerOverviewActions(viewModel), | ||||||
|         drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp), |         drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp) | ||||||
|         navigationBarActions = getNavigationBarActions(navBarViewModel, open), |  | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun TimerOverviewScreen( | fun TimerOverviewScreen( | ||||||
|     timerOverviewActions: TimerOverviewActions, |     timerOverviewActions: TimerOverviewActions, | ||||||
|     drawerActions: DrawerActions, |     drawerActions: DrawerActions | ||||||
|     navigationBarActions: NavigationBarActions, |  | ||||||
| ) { | ) { | ||||||
| 
 | 
 | ||||||
|     val timers = timerOverviewActions.getUserTimers().collectAsState(initial = emptyList()) |     val timers = timerOverviewActions.getUserTimers().collectAsState(initial = emptyList()) | ||||||
| 
 | 
 | ||||||
|     // TODO moet geen primary screen zijn: geen navbar nodig |     DrawerScreenTemplate( | ||||||
|     PrimaryScreenTemplate( |  | ||||||
|         title = resources().getString(R.string.timers), |         title = resources().getString(R.string.timers), | ||||||
|         drawerActions = drawerActions, |         drawerActions = drawerActions | ||||||
|         navigationBarActions = navigationBarActions, |  | ||||||
|     ) { |     ) { | ||||||
|         Column { |         Column { | ||||||
|             LazyColumn( |             LazyColumn( | ||||||
|  | @ -112,7 +104,6 @@ fun TimerOverviewPreview() { | ||||||
|             { flowOf() }, |             { flowOf() }, | ||||||
|             { listOf(customTimer, customTimer) }, |             { listOf(customTimer, customTimer) }, | ||||||
|             {}), |             {}), | ||||||
|         drawerActions = DrawerActions({}, {}, {}, {}, {}), |         drawerActions = DrawerActions({}, {}, {}, {}, {}) | ||||||
|         navigationBarActions = NavigationBarActions({}, {}, {}, {}) |  | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue