less hardcoding
This commit is contained in:
		
							parent
							
								
									e73cc798f0
								
							
						
					
					
						commit
						05860345b6
					
				
					 2 changed files with 16 additions and 12 deletions
				
			
		|  | @ -12,12 +12,14 @@ import androidx.compose.material.icons.outlined.DateRange | |||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.ui.tooling.preview.Preview | ||||
| 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.ui.theme.StudeezTheme | ||||
| import be.ugent.sel.studeez.R.string as AppText | ||||
| 
 | ||||
| data class NavigationBarActions( | ||||
|     val selectedTab: (Int) -> Boolean, | ||||
|     val selectedTab: (String) -> Boolean, | ||||
|     val onHomeClick: () -> Unit, | ||||
|     val onTasksClick: () -> Unit, | ||||
|     val onSessionsClick: () -> Unit, | ||||
|  | @ -56,7 +58,7 @@ fun NavigationBar( | |||
|         BottomNavigationItem( | ||||
|             icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) }, | ||||
|             label = { Text(text = resources().getString(AppText.home)) }, | ||||
|             selected = navigationBarActions.selectedTab(0), | ||||
|             selected = navigationBarActions.selectedTab(HOME_SCREEN), | ||||
|             onClick = navigationBarActions.onHomeClick | ||||
|         ) | ||||
| 
 | ||||
|  | @ -67,7 +69,8 @@ fun NavigationBar( | |||
|                 ) | ||||
|             }, | ||||
|             label = { Text(text = resources().getString(AppText.tasks)) }, | ||||
|             selected = navigationBarActions.selectedTab(1), | ||||
|             // TODO selected = navigationBarActions.selectedTab(TASKS_SCREEN), | ||||
|             selected = false, | ||||
|             onClick = navigationBarActions.onTasksClick | ||||
|         ) | ||||
| 
 | ||||
|  | @ -81,7 +84,8 @@ fun NavigationBar( | |||
|                 ) | ||||
|             }, | ||||
|             label = { Text(text = resources().getString(AppText.sessions)) }, | ||||
|             selected = navigationBarActions.selectedTab(2), | ||||
|             // TODO selected = navigationBarActions.selectedTab(SESSIONS_SCREEN), | ||||
|             selected = false, | ||||
|             onClick = navigationBarActions.onSessionsClick | ||||
|         ) | ||||
| 
 | ||||
|  | @ -92,7 +96,7 @@ fun NavigationBar( | |||
|                 ) | ||||
|             }, | ||||
|             label = { Text(text = resources().getString(AppText.profile)) }, | ||||
|             selected = navigationBarActions.selectedTab(3), | ||||
|             selected = navigationBarActions.selectedTab(PROFILE_SCREEN), | ||||
|             onClick = navigationBarActions.onProfileClick | ||||
|         ) | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,32 +16,32 @@ class NavigationBarViewModel @Inject constructor( | |||
|     logService: LogService | ||||
| ) : StudeezViewModel(logService) { | ||||
| 
 | ||||
|     fun isSelected(index: Int): Boolean { | ||||
|         return index == selectedTab.selectedTab | ||||
|     fun isSelected(screen: String): Boolean { | ||||
|         return screen == selectedTab.selectedTab | ||||
|     } | ||||
| 
 | ||||
|     fun onHomeClick(open: (String) -> Unit) { | ||||
|         selectedTab.selectedTab = 0 | ||||
|         selectedTab.selectedTab = HOME_SCREEN | ||||
|         open(HOME_SCREEN) | ||||
|     } | ||||
| 
 | ||||
|     fun onTasksClick(open: (String) -> Unit) { | ||||
|         // TODO | ||||
|         selectedTab.selectedTab = 1 | ||||
|         // selectedTab.selectedTab = TASKS_SCREEN | ||||
|     } | ||||
| 
 | ||||
|     fun onSessionsClick(open: (String) -> Unit) { | ||||
|         // TODO | ||||
|         selectedTab.selectedTab = 2 | ||||
|         // selectedTab.selectedTab = SESSIONS_SCREEN | ||||
|     } | ||||
| 
 | ||||
|     fun onProfileClick(open: (String) -> Unit) { | ||||
|         selectedTab.selectedTab = 3 | ||||
|         selectedTab.selectedTab = PROFILE_SCREEN | ||||
|         open(PROFILE_SCREEN) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Singleton | ||||
| class SelectedTabState @Inject constructor() { | ||||
|     var selectedTab: Int = 0 | ||||
|     var selectedTab: String = HOME_SCREEN | ||||
| } | ||||
		Reference in a new issue