From d5b62e0cb97626ac5e67edddcaf3dce44eb51be2 Mon Sep 17 00:00:00 2001 From: brreynie Date: Sun, 23 Apr 2023 00:34:51 +0200 Subject: [PATCH] move TimerEntry to common.composable --- .../studeez/common/composable/TimerEntry.kt | 68 +++++++++++++++++++ .../timer_overview/TimerOverviewScreen.kt | 64 +---------------- .../timer_selection/TimerSelectionScreen.kt | 2 +- 3 files changed, 70 insertions(+), 64 deletions(-) create mode 100644 app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt new file mode 100644 index 0000000..6dafb45 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt @@ -0,0 +1,68 @@ +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 +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import be.ugent.sel.studeez.R +import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo +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 = {} +) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Column( + Modifier.padding(horizontal = 10.dp) + ) { + Text( + text = timerInfo.name, fontWeight = FontWeight.Bold, fontSize = 20.sp + ) + Text( + text = timerInfo.description, fontWeight = FontWeight.Light, fontSize = 15.sp + ) + } + if (showButton) { + StealthButton(buttonName) { + onButtonClick(timerInfo) + } + } + + } +} + +@Preview +@Composable +fun TimerEntryPreview() { + val timerInfo = CustomTimerInfo( + "my preview timer", "This is the description of the timer", 60 + ) + 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) { } +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt index e822576..c7fefa2 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt @@ -1,27 +1,19 @@ package be.ugent.sel.studeez.screens.timer_overview -import androidx.annotation.StringRes import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp 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 @@ -100,63 +92,9 @@ fun TimerOverviewScreen( // TODO } } - } } -@Composable -fun TimerEntry( - timerInfo: TimerInfo, - showButton: Boolean, - @StringRes buttonName: Int = -1, - onButtonClick: (TimerInfo) -> Unit = {} -) { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween - ) { - Column( - Modifier.padding(horizontal = 10.dp) - ) { - Text( - text = timerInfo.name, - fontWeight = FontWeight.Bold, - fontSize = 20.sp - ) - Text( - text = timerInfo.description, - fontWeight = FontWeight.Light, - fontSize = 15.sp - ) - } - if (showButton) { - StealthButton(buttonName) { - onButtonClick(timerInfo) - } - } - - } -} - -@Preview -@Composable -fun TimerEntryPreview() { - val timerInfo = CustomTimerInfo( - "my preview timer", "This is the description of the timer", 60 - ) - 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() { diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index 0ed5a25..0a534a8 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -10,13 +10,13 @@ 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.TimerEntry import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.screens.drawer.DrawerActions import be.ugent.sel.studeez.screens.drawer.getDrawerActions import be.ugent.sel.studeez.screens.navbar.NavigationBarActions import be.ugent.sel.studeez.screens.navbar.getNavigationBarActions -import be.ugent.sel.studeez.screens.timer_overview.TimerEntry import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf