wrap timeroverview in route
This commit is contained in:
		
							parent
							
								
									c401a29061
								
							
						
					
					
						commit
						480f085325
					
				
					 3 changed files with 83 additions and 50 deletions
				
			
		|  | @ -32,8 +32,7 @@ import be.ugent.sel.studeez.screens.profile.ProfileRoute | ||||||
| import be.ugent.sel.studeez.screens.session.SessionScreen | import be.ugent.sel.studeez.screens.session.SessionScreen | ||||||
| import be.ugent.sel.studeez.screens.sign_up.SignUpRoute | import be.ugent.sel.studeez.screens.sign_up.SignUpRoute | ||||||
| import be.ugent.sel.studeez.screens.splash.SplashRoute | import be.ugent.sel.studeez.screens.splash.SplashRoute | ||||||
| import be.ugent.sel.studeez.screens.splash.SplashScreen | import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewRoute | ||||||
| import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewScreen |  | ||||||
| import be.ugent.sel.studeez.screens.timer_selection.TimerSelectionScreen | import be.ugent.sel.studeez.screens.timer_selection.TimerSelectionScreen | ||||||
| import be.ugent.sel.studeez.ui.theme.StudeezTheme | import be.ugent.sel.studeez.ui.theme.StudeezTheme | ||||||
| import kotlinx.coroutines.CoroutineScope | import kotlinx.coroutines.CoroutineScope | ||||||
|  | @ -125,7 +124,7 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     composable(StudeezDestinations.TIMER_OVERVIEW_SCREEN) { |     composable(StudeezDestinations.TIMER_OVERVIEW_SCREEN) { | ||||||
|         TimerOverviewScreen(open, openAndPopUp) |         TimerOverviewRoute(open, openAndPopUp, viewModel = hiltViewModel()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     composable(StudeezDestinations.SESSION_SCREEN) { |     composable(StudeezDestinations.SESSION_SCREEN) { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,5 @@ | ||||||
| package be.ugent.sel.studeez.screens.timer_overview | package be.ugent.sel.studeez.screens.timer_overview | ||||||
| 
 | 
 | ||||||
| import android.annotation.SuppressLint |  | ||||||
| import androidx.annotation.StringRes | import androidx.annotation.StringRes | ||||||
| import androidx.compose.foundation.layout.Arrangement | import androidx.compose.foundation.layout.Arrangement | ||||||
| import androidx.compose.foundation.layout.Column | import androidx.compose.foundation.layout.Column | ||||||
|  | @ -9,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth | ||||||
| import androidx.compose.foundation.layout.padding | import androidx.compose.foundation.layout.padding | ||||||
| import androidx.compose.foundation.lazy.LazyColumn | import androidx.compose.foundation.lazy.LazyColumn | ||||||
| import androidx.compose.foundation.lazy.items | import androidx.compose.foundation.lazy.items | ||||||
| import androidx.compose.material.Scaffold |  | ||||||
| import androidx.compose.material.Text | import androidx.compose.material.Text | ||||||
| import androidx.compose.runtime.Composable | import androidx.compose.runtime.Composable | ||||||
| import androidx.compose.runtime.collectAsState | import androidx.compose.runtime.collectAsState | ||||||
|  | @ -29,53 +27,73 @@ import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo | ||||||
| import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | ||||||
| import be.ugent.sel.studeez.resources | import be.ugent.sel.studeez.resources | ||||||
| import be.ugent.sel.studeez.screens.drawer.DrawerActions | import be.ugent.sel.studeez.screens.drawer.DrawerActions | ||||||
| import be.ugent.sel.studeez.screens.drawer.DrawerViewModel | import be.ugent.sel.studeez.screens.drawer.getDrawerActions | ||||||
| import be.ugent.sel.studeez.screens.navbar.NavigationBarActions | import be.ugent.sel.studeez.screens.navbar.NavigationBarActions | ||||||
| import be.ugent.sel.studeez.screens.navbar.NavigationBarViewModel | import be.ugent.sel.studeez.screens.navbar.getNavigationBarActions | ||||||
|  | import kotlinx.coroutines.flow.Flow | ||||||
|  | import kotlinx.coroutines.flow.flowOf | ||||||
|  | 
 | ||||||
|  | data class TimerOverviewActions( | ||||||
|  |     val getUserTimers: () -> Flow<List<TimerInfo>>, | ||||||
|  |     val getDefaultTimers: () -> List<TimerInfo>, | ||||||
|  |     val onEditClick: (TimerInfo) -> Unit, | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | fun getTimerOverviewActions( | ||||||
|  |     viewModel: TimerOverviewViewModel, | ||||||
|  | ): TimerOverviewActions { | ||||||
|  |     return TimerOverviewActions( | ||||||
|  |         getUserTimers = viewModel::getUserTimers, | ||||||
|  |         getDefaultTimers = viewModel::getDefaultTimers, | ||||||
|  |         onEditClick = { viewModel.update(it) }, | ||||||
|  |     ) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun TimerOverviewRoute( | ||||||
|  |     open: (String) -> Unit, | ||||||
|  |     openAndPopUp: (String, String) -> Unit, | ||||||
|  |     viewModel: TimerOverviewViewModel, | ||||||
|  | ) { | ||||||
|  |     TimerOverviewScreen( | ||||||
|  |         timerOverviewActions = getTimerOverviewActions(viewModel), | ||||||
|  |         drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp), | ||||||
|  |         navigationBarActions = getNavigationBarActions(hiltViewModel(), open), | ||||||
|  |     ) | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun TimerOverviewScreen( | fun TimerOverviewScreen( | ||||||
|     open: (String) -> Unit, |     timerOverviewActions: TimerOverviewActions, | ||||||
|     openAndPopUp: (String, String) -> Unit, |     drawerActions: DrawerActions, | ||||||
|     viewModel: TimerOverviewViewModel = hiltViewModel() |     navigationBarActions: NavigationBarActions, | ||||||
| ) { | ) { | ||||||
| 
 | 
 | ||||||
|     val timers = viewModel.getUserTimers().collectAsState(initial = emptyList()) |     val timers = timerOverviewActions.getUserTimers().collectAsState(initial = emptyList()) | ||||||
|     val drawerViewModel: DrawerViewModel = hiltViewModel() | 
 | ||||||
|     val drawerActions = DrawerActions( |     // TODO moet geen primary screen zijn: geen navbar nodig | ||||||
|         onHomeButtonClick = { drawerViewModel.onHomeButtonClick(open) }, |  | ||||||
|         onTimersClick = { drawerViewModel.onTimersClick(open) }, |  | ||||||
|         onSettingsClick = { drawerViewModel.onSettingsClick(open) }, |  | ||||||
|         onLogoutClick = { drawerViewModel.onLogoutClick(openAndPopUp) }, |  | ||||||
|         onAboutClick = { drawerViewModel.onAboutClick(open) }, |  | ||||||
|     ) |  | ||||||
|     val navigationBarViewModel: NavigationBarViewModel = hiltViewModel() |  | ||||||
|     val navigationBarActions = NavigationBarActions( |  | ||||||
|         onHomeClick = { navigationBarViewModel.onHomeClick(open) }, |  | ||||||
|         onTasksClick = { navigationBarViewModel.onTasksClick(open) }, |  | ||||||
|         onSessionsClick = { navigationBarViewModel.onSessionsClick(open) }, |  | ||||||
|         onProfileClick = { navigationBarViewModel.onProfileClick(open) }, |  | ||||||
|     ) |  | ||||||
|     PrimaryScreenTemplate( |     PrimaryScreenTemplate( | ||||||
|         title = resources().getString(R.string.timers), |         title = resources().getString(R.string.timers), | ||||||
|         drawerActions = drawerActions, |         drawerActions = drawerActions, | ||||||
|         navigationBarActions = navigationBarActions, |         navigationBarActions = navigationBarActions, | ||||||
|     ) { |     ) { | ||||||
| 
 |  | ||||||
|         Column { |         Column { | ||||||
|             LazyColumn( |             LazyColumn( | ||||||
|                 verticalArrangement = Arrangement.spacedBy(7.dp) |                 verticalArrangement = Arrangement.spacedBy(7.dp) | ||||||
|             ) { |             ) { | ||||||
|                 // Default Timers, cannot be edited |                 // Default Timers, cannot be edited | ||||||
|                 items(viewModel.getDefaultTimers()) { |                 items(timerOverviewActions.getDefaultTimers()) { | ||||||
|                     TimerEntry(timerInfo = it, canDisplay = false) |                     TimerEntry(timerInfo = it, showButton = false) | ||||||
|                 } |                 } | ||||||
| 
 |  | ||||||
|                 // User timers, can be edited |                 // User timers, can be edited | ||||||
|                 items(timers.value) { |                 items(timers.value) { | ||||||
|                     TimerEntry(timerInfo = it, true, R.string.edit) { timerInfo -> |                     TimerEntry( | ||||||
|                         viewModel.update(timerInfo) |                         timerInfo = it, | ||||||
|                     } |                         true, | ||||||
|  |                         R.string.edit, | ||||||
|  |                         onEditClick = timerOverviewActions.onEditClick | ||||||
|  |                     ) | ||||||
|  | 
 | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             BasicButton(R.string.add_timer, Modifier.basicButton()) { |             BasicButton(R.string.add_timer, Modifier.basicButton()) { | ||||||
|  | @ -89,9 +107,9 @@ fun TimerOverviewScreen( | ||||||
| @Composable | @Composable | ||||||
| fun TimerEntry( | fun TimerEntry( | ||||||
|     timerInfo: TimerInfo, |     timerInfo: TimerInfo, | ||||||
|     canDisplay: Boolean, |     showButton: Boolean, | ||||||
|     @StringRes buttonName: Int = -1, |     @StringRes buttonName: Int = -1, | ||||||
|     buttonFunction: (TimerInfo) -> Unit = {} |     onEditClick: (TimerInfo) -> Unit = {} | ||||||
| ) { | ) { | ||||||
|     Row( |     Row( | ||||||
|         verticalAlignment = Alignment.CenterVertically, |         verticalAlignment = Alignment.CenterVertically, | ||||||
|  | @ -112,29 +130,45 @@ fun TimerEntry( | ||||||
|                 fontSize = 15.sp |                 fontSize = 15.sp | ||||||
|             ) |             ) | ||||||
|         } |         } | ||||||
|         if (canDisplay) { |         if (showButton) { | ||||||
|             StealthButton(buttonName) { |             StealthButton(buttonName) { | ||||||
|                 buttonFunction(timerInfo) |                 onEditClick(timerInfo) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @SuppressLint("UnusedMaterialScaffoldPaddingParameter") |  | ||||||
| @Preview | @Preview | ||||||
| @Composable | @Composable | ||||||
| fun TimerEntryPreview() { | fun TimerEntryPreview() { | ||||||
|     val timerInfo = CustomTimerInfo( |     val timerInfo = CustomTimerInfo( | ||||||
|         "my preview timer", |         "my preview timer", "This is the description of the timer", 60 | ||||||
|         "This is the description of the timer", |  | ||||||
|         60 |  | ||||||
|     ) |     ) | ||||||
|     Scaffold() { |  | ||||||
|         Column() { |  | ||||||
|             TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { } |  | ||||||
|             TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { } |  | ||||||
|     TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { } |     TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | @Preview | ||||||
|  | @Composable | ||||||
|  | fun TimerDefaultEntryPreview() { | ||||||
|  |     val timerInfo = CustomTimerInfo( | ||||||
|  |         "my preview timer", "This is the description of the timer", 60 | ||||||
|  |     ) | ||||||
|  |     TimerEntry(timerInfo = timerInfo, false, buttonName = R.string.edit) { } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | @Preview | ||||||
|  | @Composable | ||||||
|  | fun TimerOverviewPreview() { | ||||||
|  |     val customTimer = CustomTimerInfo( | ||||||
|  |         "my preview timer", "This is the description of the timer", 60 | ||||||
|  |     ) | ||||||
|  |     TimerOverviewScreen( | ||||||
|  |         timerOverviewActions = TimerOverviewActions( | ||||||
|  |             { flowOf(listOf()) }, | ||||||
|  |             { listOf(customTimer, customTimer) }, | ||||||
|  |             {}), | ||||||
|  |         drawerActions = DrawerActions({}, {}, {}, {}, {}), | ||||||
|  |         navigationBarActions = NavigationBarActions({}, {}, {}, {}) | ||||||
|  |     ) | ||||||
| } | } | ||||||
|  | @ -50,7 +50,7 @@ fun TimerSelectionScreen( | ||||||
|             items(timers.value) { |             items(timers.value) { | ||||||
|                 TimerEntry( |                 TimerEntry( | ||||||
|                     timerInfo = it, |                     timerInfo = it, | ||||||
|                     canDisplay = true, |                     showButton = true, | ||||||
|                     buttonName = R.string.start |                     buttonName = R.string.start | ||||||
|                 ) { timerInfo -> |                 ) { timerInfo -> | ||||||
|                     viewModel.startSession(open, timerInfo) |                     viewModel.startSession(open, timerInfo) | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 brreynie
						brreynie