wrap timerselection in route
This commit is contained in:
parent
480f085325
commit
08a33d1c9e
3 changed files with 57 additions and 35 deletions
|
@ -33,7 +33,6 @@ 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.timer_overview.TimerOverviewRoute
|
import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewRoute
|
||||||
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
|
||||||
|
|
||||||
|
@ -140,6 +139,6 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(StudeezDestinations.TIMER_SELECTION_SCREEN) {
|
composable(StudeezDestinations.TIMER_SELECTION_SCREEN) {
|
||||||
TimerSelectionScreen(open, openAndPopUp)
|
TimerOverviewRoute(open, openAndPopUp, viewModel = hiltViewModel())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -91,7 +91,7 @@ fun TimerOverviewScreen(
|
||||||
timerInfo = it,
|
timerInfo = it,
|
||||||
true,
|
true,
|
||||||
R.string.edit,
|
R.string.edit,
|
||||||
onEditClick = timerOverviewActions.onEditClick
|
onButtonClick = timerOverviewActions.onEditClick
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ fun TimerEntry(
|
||||||
timerInfo: TimerInfo,
|
timerInfo: TimerInfo,
|
||||||
showButton: Boolean,
|
showButton: Boolean,
|
||||||
@StringRes buttonName: Int = -1,
|
@StringRes buttonName: Int = -1,
|
||||||
onEditClick: (TimerInfo) -> Unit = {}
|
onButtonClick: (TimerInfo) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
@ -132,7 +132,7 @@ fun TimerEntry(
|
||||||
}
|
}
|
||||||
if (showButton) {
|
if (showButton) {
|
||||||
StealthButton(buttonName) {
|
StealthButton(buttonName) {
|
||||||
onEditClick(timerInfo)
|
onButtonClick(timerInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,60 +3,83 @@ package be.ugent.sel.studeez.screens.timer_selection
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
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.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import be.ugent.sel.studeez.R
|
import be.ugent.sel.studeez.R
|
||||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
||||||
|
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 be.ugent.sel.studeez.screens.timer_overview.TimerEntry
|
import be.ugent.sel.studeez.screens.timer_overview.TimerEntry
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
|
||||||
|
data class TimerSelectionActions(
|
||||||
|
val getAllTimers: () -> Flow<List<TimerInfo>>,
|
||||||
|
val startSession: (TimerInfo) -> Unit,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getTimerSelectionActions(
|
||||||
|
viewModel: TimerSelectionViewModel,
|
||||||
|
open: (String) -> Unit,
|
||||||
|
): TimerSelectionActions {
|
||||||
|
return TimerSelectionActions(
|
||||||
|
getAllTimers = viewModel::getAllTimers,
|
||||||
|
startSession = { viewModel.startSession(open, it) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TimerSelectionRoute(
|
||||||
|
open: (String) -> Unit,
|
||||||
|
openAndPopUp: (String, String) -> Unit,
|
||||||
|
viewModel: TimerSelectionViewModel,
|
||||||
|
) {
|
||||||
|
TimerSelectionScreen(
|
||||||
|
timerSelectionActions = getTimerSelectionActions(viewModel, open),
|
||||||
|
drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp),
|
||||||
|
navigationBarActions = getNavigationBarActions(hiltViewModel(), open),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimerSelectionScreen(
|
fun TimerSelectionScreen(
|
||||||
open: (String) -> Unit,
|
timerSelectionActions: TimerSelectionActions,
|
||||||
openAndPopUp: (String, String) -> Unit,
|
drawerActions: DrawerActions,
|
||||||
viewModel: TimerSelectionViewModel = hiltViewModel()
|
navigationBarActions: NavigationBarActions,
|
||||||
) {
|
) {
|
||||||
|
val timers = timerSelectionActions.getAllTimers().collectAsState(initial = emptyList())
|
||||||
val timers = viewModel.getAllTimers().collectAsState(initial = emptyList())
|
|
||||||
val drawerViewModel: DrawerViewModel = hiltViewModel()
|
|
||||||
val drawerActions = DrawerActions(
|
|
||||||
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,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) {
|
LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) {
|
||||||
|
|
||||||
// All timers
|
// All timers
|
||||||
items(timers.value) {
|
items(timers.value) {
|
||||||
TimerEntry(
|
TimerEntry(
|
||||||
timerInfo = it,
|
timerInfo = it,
|
||||||
showButton = true,
|
showButton = true,
|
||||||
buttonName = R.string.start
|
buttonName = R.string.start,
|
||||||
) { timerInfo ->
|
onButtonClick = timerSelectionActions.startSession
|
||||||
viewModel.startSession(open, timerInfo)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun TimerSelectionPreview() {
|
||||||
|
TimerSelectionScreen(
|
||||||
|
timerSelectionActions = TimerSelectionActions({ flowOf() }, {}),
|
||||||
|
drawerActions = DrawerActions({}, {}, {}, {}, {}),
|
||||||
|
navigationBarActions = NavigationBarActions({}, {}, {}, {}),
|
||||||
|
)
|
||||||
}
|
}
|
Reference in a new issue