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.ProfileRoute
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.splash.SplashRoute
import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewRoute

View file

@ -1,6 +1,5 @@
package be.ugent.sel.studeez.common.composable
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@ -21,9 +20,7 @@ import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
@Composable
fun TimerEntry(
timerInfo: TimerInfo,
showButton: Boolean,
@StringRes buttonName: Int = -1,
onButtonClick: (TimerInfo) -> Unit = {}
button: @Composable () -> Unit,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
@ -40,12 +37,7 @@ fun TimerEntry(
text = timerInfo.description, fontWeight = FontWeight.Light, fontSize = 15.sp
)
}
if (showButton) {
StealthButton(buttonName) {
onButtonClick(timerInfo)
}
}
button()
}
}
@ -55,7 +47,9 @@ fun TimerEntryPreview() {
val timerInfo = CustomTimerInfo(
"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
@ -64,5 +58,5 @@ fun TimerDefaultEntryPreview() {
val timerInfo = CustomTimerInfo(
"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
fun DrawerEntry(
icon: ImageVector, text: String, onClick: () -> Unit
icon: ImageVector,
text: String,
onClick: () -> Unit
) {
Row(
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.common.composable.BasicButton
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.DrawerViewModel
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.NavigationBarViewModel
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
import be.ugent.sel.studeez.common.ext.basicButton
import be.ugent.sel.studeez.resources
@Composable
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.common.composable.BasicButton
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.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.getDrawerActions
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
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.flowOf
@ -75,16 +76,18 @@ fun TimerOverviewScreen(
) {
// Default Timers, cannot be edited
items(timerOverviewActions.getDefaultTimers()) {
TimerEntry(timerInfo = it, showButton = false)
TimerEntry(timerInfo = it) {}
}
// User timers, can be edited
items(timers.value) {
items(timers.value) { timerInfo ->
TimerEntry(
timerInfo = it,
true,
R.string.edit,
onButtonClick = timerOverviewActions.onEditClick
)
timerInfo = timerInfo,
) {
StealthButton(
text = R.string.edit,
onClick = { timerOverviewActions.onEditClick(timerInfo) }
)
}
}
}
@ -103,7 +106,7 @@ fun TimerOverviewPreview() {
)
TimerOverviewScreen(
timerOverviewActions = TimerOverviewActions(
{ flowOf(listOf()) },
{ flowOf() },
{ listOf(customTimer, customTimer) },
{}),
drawerActions = DrawerActions({}, {}, {}, {}, {}),

View file

@ -10,13 +10,14 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import be.ugent.sel.studeez.R
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.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.getDrawerActions
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
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.flowOf
@ -62,13 +63,15 @@ fun TimerSelectionScreen(
) {
LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) {
// All timers
items(timers.value) {
items(timers.value) { timerInfo ->
TimerEntry(
timerInfo = it,
showButton = true,
buttonName = R.string.start,
onButtonClick = timerSelectionActions.startSession
)
timerInfo = timerInfo,
) {
StealthButton(
text = R.string.start,
onClick = { timerSelectionActions.startSession(timerInfo) }
)
}
}
}
}