#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(
 | 
			
		||||
            "Preview screen",
 | 
			
		||||
            DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
            NavigationBarActions({}, {}, {}, {}),
 | 
			
		||||
            NavigationBarActions({ false }, {}, {}, {}, {}),
 | 
			
		||||
            {
 | 
			
		||||
                IconButton(onClick = { /*TODO*/ }) {
 | 
			
		||||
                    Icon(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 }, {}, {}, {}, {}))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -69,6 +69,6 @@ fun HomeScreenPreview() {
 | 
			
		|||
    HomeScreen(
 | 
			
		||||
        onStartSessionClick = {},
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({}, {}, {}, {})
 | 
			
		||||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {})
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -90,6 +90,6 @@ fun ProfileScreenPreview() {
 | 
			
		|||
    ProfileScreen(
 | 
			
		||||
        profileActions = ProfileActions({ null }, {}),
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({}, {}, {}, {})
 | 
			
		||||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {})
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -86,6 +86,6 @@ fun TimerSelectionPreview() {
 | 
			
		|||
    TimerSelectionScreen(
 | 
			
		||||
        timerSelectionActions = TimerSelectionActions({ flowOf() }, {}),
 | 
			
		||||
        drawerActions = DrawerActions({}, {}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({}, {}, {}, {}),
 | 
			
		||||
        navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}),
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue