less hardcoding

This commit is contained in:
Tibo De Peuter 2023-04-25 21:17:57 +02:00
parent e73cc798f0
commit 05860345b6
2 changed files with 16 additions and 12 deletions

View file

@ -12,12 +12,14 @@ import androidx.compose.material.icons.outlined.DateRange
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN
import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN
import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.resources
import be.ugent.sel.studeez.ui.theme.StudeezTheme 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 selectedTab: (String) -> Boolean,
val onHomeClick: () -> Unit, val onHomeClick: () -> Unit,
val onTasksClick: () -> Unit, val onTasksClick: () -> Unit,
val onSessionsClick: () -> Unit, val onSessionsClick: () -> Unit,
@ -56,7 +58,7 @@ fun NavigationBar(
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 = navigationBarActions.selectedTab(0), selected = navigationBarActions.selectedTab(HOME_SCREEN),
onClick = navigationBarActions.onHomeClick onClick = navigationBarActions.onHomeClick
) )
@ -67,7 +69,8 @@ fun NavigationBar(
) )
}, },
label = { Text(text = resources().getString(AppText.tasks)) }, label = { Text(text = resources().getString(AppText.tasks)) },
selected = navigationBarActions.selectedTab(1), // TODO selected = navigationBarActions.selectedTab(TASKS_SCREEN),
selected = false,
onClick = navigationBarActions.onTasksClick onClick = navigationBarActions.onTasksClick
) )
@ -81,7 +84,8 @@ fun NavigationBar(
) )
}, },
label = { Text(text = resources().getString(AppText.sessions)) }, label = { Text(text = resources().getString(AppText.sessions)) },
selected = navigationBarActions.selectedTab(2), // TODO selected = navigationBarActions.selectedTab(SESSIONS_SCREEN),
selected = false,
onClick = navigationBarActions.onSessionsClick onClick = navigationBarActions.onSessionsClick
) )
@ -92,7 +96,7 @@ fun NavigationBar(
) )
}, },
label = { Text(text = resources().getString(AppText.profile)) }, label = { Text(text = resources().getString(AppText.profile)) },
selected = navigationBarActions.selectedTab(3), selected = navigationBarActions.selectedTab(PROFILE_SCREEN),
onClick = navigationBarActions.onProfileClick onClick = navigationBarActions.onProfileClick
) )

View file

@ -16,32 +16,32 @@ class NavigationBarViewModel @Inject constructor(
logService: LogService logService: LogService
) : StudeezViewModel(logService) { ) : StudeezViewModel(logService) {
fun isSelected(index: Int): Boolean { fun isSelected(screen: String): Boolean {
return index == selectedTab.selectedTab return screen == selectedTab.selectedTab
} }
fun onHomeClick(open: (String) -> Unit) { fun onHomeClick(open: (String) -> Unit) {
selectedTab.selectedTab = 0 selectedTab.selectedTab = HOME_SCREEN
open(HOME_SCREEN) open(HOME_SCREEN)
} }
fun onTasksClick(open: (String) -> Unit) { fun onTasksClick(open: (String) -> Unit) {
// TODO // TODO
selectedTab.selectedTab = 1 // selectedTab.selectedTab = TASKS_SCREEN
} }
fun onSessionsClick(open: (String) -> Unit) { fun onSessionsClick(open: (String) -> Unit) {
// TODO // TODO
selectedTab.selectedTab = 2 // selectedTab.selectedTab = SESSIONS_SCREEN
} }
fun onProfileClick(open: (String) -> Unit) { fun onProfileClick(open: (String) -> Unit) {
selectedTab.selectedTab = 3 selectedTab.selectedTab = PROFILE_SCREEN
open(PROFILE_SCREEN) open(PROFILE_SCREEN)
} }
} }
@Singleton @Singleton
class SelectedTabState @Inject constructor() { class SelectedTabState @Inject constructor() {
var selectedTab: Int = 0 var selectedTab: String = HOME_SCREEN
} }