move TimerEntry to common.composable

This commit is contained in:
brreynie 2023-04-23 00:34:51 +02:00
parent 08a33d1c9e
commit d5b62e0cb9
3 changed files with 70 additions and 64 deletions

View file

@ -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) { }
}

View file

@ -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() {

View file

@ -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