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