diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt index 5af2788..773c546 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt @@ -77,7 +77,7 @@ fun PrimaryScreenPreview() { PrimaryScreenTemplate( "Preview screen", DrawerActions({}, {}, {}, {}, {}), - NavigationBarActions({}, {}, {}, {}), + NavigationBarActions({ false }, {}, {}, {}, {}), { IconButton(onClick = { /*TODO*/ }) { Icon( diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt index 21311ef..27fb605 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt @@ -17,6 +17,7 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme import be.ugent.sel.studeez.R.string as AppText data class NavigationBarActions( + val selectedTab: (Int) -> Boolean, val onHomeClick: () -> Unit, val onTasksClick: () -> Unit, val onSessionsClick: () -> Unit, @@ -28,10 +29,19 @@ fun getNavigationBarActions( open: (String) -> Unit, ): NavigationBarActions { return NavigationBarActions( - onHomeClick = { navigationBarViewModel.onHomeClick(open) }, - onTasksClick = { navigationBarViewModel.onTasksClick(open) }, - onSessionsClick = { navigationBarViewModel.onSessionsClick(open) }, - onProfileClick = { navigationBarViewModel.onProfileClick(open) }, + selectedTab = { navigationBarViewModel.isSelected(it) }, + onHomeClick = { + navigationBarViewModel.onHomeClick(open) + }, + onTasksClick = { + navigationBarViewModel.onTasksClick(open) + }, + onSessionsClick = { + navigationBarViewModel.onSessionsClick(open) + }, + onProfileClick = { + navigationBarViewModel.onProfileClick(open) + }, ) } @@ -39,16 +49,14 @@ fun getNavigationBarActions( fun NavigationBar( navigationBarActions: NavigationBarActions, ) { - // TODO Pass functions and new screens. - // TODO Pass which screen is selected. - // TODO Disabled -> HIGH/MEDIUM_EMPHASIS if the page is implemented BottomNavigation( elevation = 10.dp ) { + BottomNavigationItem( icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) }, label = { Text(text = resources().getString(AppText.home)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(0), onClick = navigationBarActions.onHomeClick ) @@ -59,7 +67,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.tasks)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(1), onClick = navigationBarActions.onTasksClick ) @@ -73,7 +81,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.sessions)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(2), onClick = navigationBarActions.onSessionsClick ) @@ -84,7 +92,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.profile)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(3), onClick = navigationBarActions.onProfileClick ) @@ -95,6 +103,6 @@ fun NavigationBar( @Composable fun NavigationBarPreview() { StudeezTheme { - NavigationBar(NavigationBarActions({}, {}, {}, {})) + NavigationBar(NavigationBarActions({ false }, {}, {}, {}, {})) } } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt index 1e4bd0d..58a75ef 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt @@ -7,26 +7,41 @@ 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 +import javax.inject.Singleton @HiltViewModel class NavigationBarViewModel @Inject constructor( private val accountDAO: AccountDAO, + var selectedTab: SelectedTabState, logService: LogService ) : StudeezViewModel(logService) { + fun isSelected(index: Int): Boolean { + return index == selectedTab.selectedTab + } + fun onHomeClick(open: (String) -> Unit) { + selectedTab.selectedTab = 0 open(HOME_SCREEN) } fun onTasksClick(open: (String) -> Unit) { // TODO + selectedTab.selectedTab = 1 } fun onSessionsClick(open: (String) -> Unit) { // TODO + selectedTab.selectedTab = 2 } fun onProfileClick(open: (String) -> Unit) { + selectedTab.selectedTab = 3 open(PROFILE_SCREEN) } +} + +@Singleton +class SelectedTabState @Inject constructor() { + var selectedTab: Int = 0 } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt index e318655..ba322d9 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt @@ -69,6 +69,6 @@ fun HomeScreenPreview() { HomeScreen( onStartSessionClick = {}, drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({}, {}, {}, {}) + navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}) ) } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt index a12dd08..af72010 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt @@ -90,6 +90,6 @@ fun ProfileScreenPreview() { ProfileScreen( profileActions = ProfileActions({ null }, {}), drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({}, {}, {}, {}) + navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}) ) } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index 47e7f91..007a656 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -86,6 +86,6 @@ fun TimerSelectionPreview() { TimerSelectionScreen( timerSelectionActions = TimerSelectionActions({ flowOf() }, {}), drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({}, {}, {}, {}), + navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}), ) } \ No newline at end of file