#42 highlight selected screen
This commit is contained in:
parent
7b3a82cc30
commit
e73cc798f0
6 changed files with 39 additions and 16 deletions
|
@ -77,7 +77,7 @@ fun PrimaryScreenPreview() {
|
||||||
PrimaryScreenTemplate(
|
PrimaryScreenTemplate(
|
||||||
"Preview screen",
|
"Preview screen",
|
||||||
DrawerActions({}, {}, {}, {}, {}),
|
DrawerActions({}, {}, {}, {}, {}),
|
||||||
NavigationBarActions({}, {}, {}, {}),
|
NavigationBarActions({ false }, {}, {}, {}, {}),
|
||||||
{
|
{
|
||||||
IconButton(onClick = { /*TODO*/ }) {
|
IconButton(onClick = { /*TODO*/ }) {
|
||||||
Icon(
|
Icon(
|
||||||
|
|
|
@ -17,6 +17,7 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||||
import be.ugent.sel.studeez.R.string as AppText
|
import be.ugent.sel.studeez.R.string as AppText
|
||||||
|
|
||||||
data class NavigationBarActions(
|
data class NavigationBarActions(
|
||||||
|
val selectedTab: (Int) -> Boolean,
|
||||||
val onHomeClick: () -> Unit,
|
val onHomeClick: () -> Unit,
|
||||||
val onTasksClick: () -> Unit,
|
val onTasksClick: () -> Unit,
|
||||||
val onSessionsClick: () -> Unit,
|
val onSessionsClick: () -> Unit,
|
||||||
|
@ -28,10 +29,19 @@ fun getNavigationBarActions(
|
||||||
open: (String) -> Unit,
|
open: (String) -> Unit,
|
||||||
): NavigationBarActions {
|
): NavigationBarActions {
|
||||||
return NavigationBarActions(
|
return NavigationBarActions(
|
||||||
onHomeClick = { navigationBarViewModel.onHomeClick(open) },
|
selectedTab = { navigationBarViewModel.isSelected(it) },
|
||||||
onTasksClick = { navigationBarViewModel.onTasksClick(open) },
|
onHomeClick = {
|
||||||
onSessionsClick = { navigationBarViewModel.onSessionsClick(open) },
|
navigationBarViewModel.onHomeClick(open)
|
||||||
onProfileClick = { navigationBarViewModel.onProfileClick(open) },
|
},
|
||||||
|
onTasksClick = {
|
||||||
|
navigationBarViewModel.onTasksClick(open)
|
||||||
|
},
|
||||||
|
onSessionsClick = {
|
||||||
|
navigationBarViewModel.onSessionsClick(open)
|
||||||
|
},
|
||||||
|
onProfileClick = {
|
||||||
|
navigationBarViewModel.onProfileClick(open)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,16 +49,14 @@ fun getNavigationBarActions(
|
||||||
fun NavigationBar(
|
fun NavigationBar(
|
||||||
navigationBarActions: NavigationBarActions,
|
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(
|
BottomNavigation(
|
||||||
elevation = 10.dp
|
elevation = 10.dp
|
||||||
) {
|
) {
|
||||||
|
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) },
|
icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) },
|
||||||
label = { Text(text = resources().getString(AppText.home)) },
|
label = { Text(text = resources().getString(AppText.home)) },
|
||||||
selected = false, // TODO
|
selected = navigationBarActions.selectedTab(0),
|
||||||
onClick = navigationBarActions.onHomeClick
|
onClick = navigationBarActions.onHomeClick
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,7 +67,7 @@ fun NavigationBar(
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
label = { Text(text = resources().getString(AppText.tasks)) },
|
label = { Text(text = resources().getString(AppText.tasks)) },
|
||||||
selected = false, // TODO
|
selected = navigationBarActions.selectedTab(1),
|
||||||
onClick = navigationBarActions.onTasksClick
|
onClick = navigationBarActions.onTasksClick
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,7 +81,7 @@ fun NavigationBar(
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
label = { Text(text = resources().getString(AppText.sessions)) },
|
label = { Text(text = resources().getString(AppText.sessions)) },
|
||||||
selected = false, // TODO
|
selected = navigationBarActions.selectedTab(2),
|
||||||
onClick = navigationBarActions.onSessionsClick
|
onClick = navigationBarActions.onSessionsClick
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,7 +92,7 @@ fun NavigationBar(
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
label = { Text(text = resources().getString(AppText.profile)) },
|
label = { Text(text = resources().getString(AppText.profile)) },
|
||||||
selected = false, // TODO
|
selected = navigationBarActions.selectedTab(3),
|
||||||
onClick = navigationBarActions.onProfileClick
|
onClick = navigationBarActions.onProfileClick
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -95,6 +103,6 @@ fun NavigationBar(
|
||||||
@Composable
|
@Composable
|
||||||
fun NavigationBarPreview() {
|
fun NavigationBarPreview() {
|
||||||
StudeezTheme {
|
StudeezTheme {
|
||||||
NavigationBar(NavigationBarActions({}, {}, {}, {}))
|
NavigationBar(NavigationBarActions({ false }, {}, {}, {}, {}))
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,26 +7,41 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN
|
||||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class NavigationBarViewModel @Inject constructor(
|
class NavigationBarViewModel @Inject constructor(
|
||||||
private val accountDAO: AccountDAO,
|
private val accountDAO: AccountDAO,
|
||||||
|
var selectedTab: SelectedTabState,
|
||||||
logService: LogService
|
logService: LogService
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
|
fun isSelected(index: Int): Boolean {
|
||||||
|
return index == selectedTab.selectedTab
|
||||||
|
}
|
||||||
|
|
||||||
fun onHomeClick(open: (String) -> Unit) {
|
fun onHomeClick(open: (String) -> Unit) {
|
||||||
|
selectedTab.selectedTab = 0
|
||||||
open(HOME_SCREEN)
|
open(HOME_SCREEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onTasksClick(open: (String) -> Unit) {
|
fun onTasksClick(open: (String) -> Unit) {
|
||||||
// TODO
|
// TODO
|
||||||
|
selectedTab.selectedTab = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onSessionsClick(open: (String) -> Unit) {
|
fun onSessionsClick(open: (String) -> Unit) {
|
||||||
// TODO
|
// TODO
|
||||||
|
selectedTab.selectedTab = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onProfileClick(open: (String) -> Unit) {
|
fun onProfileClick(open: (String) -> Unit) {
|
||||||
|
selectedTab.selectedTab = 3
|
||||||
open(PROFILE_SCREEN)
|
open(PROFILE_SCREEN)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class SelectedTabState @Inject constructor() {
|
||||||
|
var selectedTab: Int = 0
|
||||||
}
|
}
|
|
@ -69,6 +69,6 @@ fun HomeScreenPreview() {
|
||||||
HomeScreen(
|
HomeScreen(
|
||||||
onStartSessionClick = {},
|
onStartSessionClick = {},
|
||||||
drawerActions = DrawerActions({}, {}, {}, {}, {}),
|
drawerActions = DrawerActions({}, {}, {}, {}, {}),
|
||||||
navigationBarActions = NavigationBarActions({}, {}, {}, {})
|
navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,6 @@ fun ProfileScreenPreview() {
|
||||||
ProfileScreen(
|
ProfileScreen(
|
||||||
profileActions = ProfileActions({ null }, {}),
|
profileActions = ProfileActions({ null }, {}),
|
||||||
drawerActions = DrawerActions({}, {}, {}, {}, {}),
|
drawerActions = DrawerActions({}, {}, {}, {}, {}),
|
||||||
navigationBarActions = NavigationBarActions({}, {}, {}, {})
|
navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {})
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -86,6 +86,6 @@ fun TimerSelectionPreview() {
|
||||||
TimerSelectionScreen(
|
TimerSelectionScreen(
|
||||||
timerSelectionActions = TimerSelectionActions({ flowOf() }, {}),
|
timerSelectionActions = TimerSelectionActions({ flowOf() }, {}),
|
||||||
drawerActions = DrawerActions({}, {}, {}, {}, {}),
|
drawerActions = DrawerActions({}, {}, {}, {}, {}),
|
||||||
navigationBarActions = NavigationBarActions({}, {}, {}, {}),
|
navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}),
|
||||||
)
|
)
|
||||||
}
|
}
|
Reference in a new issue