New DrawerScreen for TimerOverView

This commit is contained in:
Tibo De Peuter 2023-04-25 09:43:10 +02:00
parent c73c06b11c
commit 7b3a82cc30
3 changed files with 59 additions and 18 deletions

View file

@ -141,8 +141,7 @@ fun StudeezNavGraph(
open,
openAndPopUp,
viewModel = hiltViewModel(),
drawerViewModel = drawerViewModel,
navBarViewModel = navBarViewModel,
drawerViewModel = drawerViewModel
)
}

View file

@ -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)
}
}

View file

@ -10,10 +10,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
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.StealthButton
import be.ugent.sel.studeez.common.composable.TimerEntry
import be.ugent.sel.studeez.common.composable.*
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
@ -48,30 +45,25 @@ fun TimerOverviewRoute(
open: (String) -> Unit,
openAndPopUp: (String, String) -> Unit,
viewModel: TimerOverviewViewModel,
drawerViewModel: DrawerViewModel,
navBarViewModel: NavigationBarViewModel,
drawerViewModel: DrawerViewModel
) {
TimerOverviewScreen(
timerOverviewActions = getTimerOverviewActions(viewModel),
drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp),
navigationBarActions = getNavigationBarActions(navBarViewModel, open),
drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp)
)
}
@Composable
fun TimerOverviewScreen(
timerOverviewActions: TimerOverviewActions,
drawerActions: DrawerActions,
navigationBarActions: NavigationBarActions,
drawerActions: DrawerActions
) {
val timers = timerOverviewActions.getUserTimers().collectAsState(initial = emptyList())
// TODO moet geen primary screen zijn: geen navbar nodig
PrimaryScreenTemplate(
DrawerScreenTemplate(
title = resources().getString(R.string.timers),
drawerActions = drawerActions,
navigationBarActions = navigationBarActions,
drawerActions = drawerActions
) {
Column {
LazyColumn(
@ -112,7 +104,6 @@ fun TimerOverviewPreview() {
{ flowOf() },
{ listOf(customTimer, customTimer) },
{}),
drawerActions = DrawerActions({}, {}, {}, {}, {}),
navigationBarActions = NavigationBarActions({}, {}, {}, {})
drawerActions = DrawerActions({}, {}, {}, {}, {})
)
}