decouple button from timerEntry

This commit is contained in:
brreynie 2023-04-24 15:41:31 +02:00
parent 70449500cc
commit 097d1ea134
6 changed files with 37 additions and 38 deletions

View file

@ -30,7 +30,6 @@ import be.ugent.sel.studeez.screens.log_in.LoginRoute
import be.ugent.sel.studeez.screens.profile.EditProfileRoute import be.ugent.sel.studeez.screens.profile.EditProfileRoute
import be.ugent.sel.studeez.screens.profile.ProfileRoute import be.ugent.sel.studeez.screens.profile.ProfileRoute
import be.ugent.sel.studeez.screens.session.SessionRoute import be.ugent.sel.studeez.screens.session.SessionRoute
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

View file

@ -1,6 +1,5 @@
package be.ugent.sel.studeez.common.composable package be.ugent.sel.studeez.common.composable
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
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -21,9 +20,7 @@ import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
@Composable @Composable
fun TimerEntry( fun TimerEntry(
timerInfo: TimerInfo, timerInfo: TimerInfo,
showButton: Boolean, button: @Composable () -> Unit,
@StringRes buttonName: Int = -1,
onButtonClick: (TimerInfo) -> Unit = {}
) { ) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
@ -40,12 +37,7 @@ fun TimerEntry(
text = timerInfo.description, fontWeight = FontWeight.Light, fontSize = 15.sp text = timerInfo.description, fontWeight = FontWeight.Light, fontSize = 15.sp
) )
} }
if (showButton) { button()
StealthButton(buttonName) {
onButtonClick(timerInfo)
}
}
} }
} }
@ -55,7 +47,9 @@ fun TimerEntryPreview() {
val timerInfo = CustomTimerInfo( val timerInfo = CustomTimerInfo(
"my preview timer", "This is the description of the timer", 60 "my preview timer", "This is the description of the timer", 60
) )
TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { } TimerEntry(timerInfo = timerInfo) {
StealthButton(text = R.string.edit) {}
}
} }
@Preview @Preview
@ -64,5 +58,5 @@ fun TimerDefaultEntryPreview() {
val timerInfo = CustomTimerInfo( val timerInfo = CustomTimerInfo(
"Default preview timer", "This is the description of the timer", 60 "Default preview timer", "This is the description of the timer", 60
) )
TimerEntry(timerInfo = timerInfo, false, buttonName = R.string.edit) { } TimerEntry(timerInfo = timerInfo) {}
} }

View file

@ -89,7 +89,9 @@ fun Drawer(
@Composable @Composable
fun DrawerEntry( fun DrawerEntry(
icon: ImageVector, text: String, onClick: () -> Unit icon: ImageVector,
text: String,
onClick: () -> Unit
) { ) {
Row( Row(
horizontalArrangement = Arrangement.Center, horizontalArrangement = Arrangement.Center,

View file

@ -11,14 +11,12 @@ 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.BasicButton import be.ugent.sel.studeez.common.composable.BasicButton
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
import be.ugent.sel.studeez.common.ext.basicButton
import be.ugent.sel.studeez.resources
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
import be.ugent.sel.studeez.common.ext.basicButton
import be.ugent.sel.studeez.resources
@Composable @Composable
fun HomeRoute( fun HomeRoute(

View file

@ -13,15 +13,16 @@ 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.BasicButton import be.ugent.sel.studeez.common.composable.BasicButton
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
import be.ugent.sel.studeez.common.composable.StealthButton
import be.ugent.sel.studeez.common.composable.TimerEntry import be.ugent.sel.studeez.common.composable.TimerEntry
import be.ugent.sel.studeez.common.ext.basicButton
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.resources
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
import be.ugent.sel.studeez.common.ext.basicButton
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.resources
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
@ -75,16 +76,18 @@ fun TimerOverviewScreen(
) { ) {
// Default Timers, cannot be edited // Default Timers, cannot be edited
items(timerOverviewActions.getDefaultTimers()) { items(timerOverviewActions.getDefaultTimers()) {
TimerEntry(timerInfo = it, showButton = false) TimerEntry(timerInfo = it) {}
} }
// User timers, can be edited // User timers, can be edited
items(timers.value) { items(timers.value) { timerInfo ->
TimerEntry( TimerEntry(
timerInfo = it, timerInfo = timerInfo,
true, ) {
R.string.edit, StealthButton(
onButtonClick = timerOverviewActions.onEditClick text = R.string.edit,
) onClick = { timerOverviewActions.onEditClick(timerInfo) }
)
}
} }
} }
@ -103,7 +106,7 @@ fun TimerOverviewPreview() {
) )
TimerOverviewScreen( TimerOverviewScreen(
timerOverviewActions = TimerOverviewActions( timerOverviewActions = TimerOverviewActions(
{ flowOf(listOf()) }, { flowOf() },
{ listOf(customTimer, customTimer) }, { listOf(customTimer, customTimer) },
{}), {}),
drawerActions = DrawerActions({}, {}, {}, {}, {}), drawerActions = DrawerActions({}, {}, {}, {}, {}),

View file

@ -10,13 +10,14 @@ 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.common.composable.StealthButton
import be.ugent.sel.studeez.common.composable.TimerEntry import be.ugent.sel.studeez.common.composable.TimerEntry
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
import be.ugent.sel.studeez.resources
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
import be.ugent.sel.studeez.resources
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
@ -62,13 +63,15 @@ fun TimerSelectionScreen(
) { ) {
LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) { LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) {
// All timers // All timers
items(timers.value) { items(timers.value) { timerInfo ->
TimerEntry( TimerEntry(
timerInfo = it, timerInfo = timerInfo,
showButton = true, ) {
buttonName = R.string.start, StealthButton(
onButtonClick = timerSelectionActions.startSession text = R.string.start,
) onClick = { timerSelectionActions.startSession(timerInfo) }
)
}
} }
} }
} }