286 lines
12 KiB
Kotlin
286 lines
12 KiB
Kotlin
package com.oshicue.tempo.ui
|
|
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.border
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.WindowInsets
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.safeDrawing
|
|
import androidx.compose.foundation.layout.windowInsetsPadding
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.size
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.foundation.rememberScrollState
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.foundation.text.BasicTextField
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.foundation.verticalScroll
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.PlayArrow
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.draw.clip
|
|
import androidx.compose.ui.focus.FocusRequester
|
|
import androidx.compose.ui.focus.focusRequester
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.SolidColor
|
|
import androidx.compose.ui.text.TextStyle
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.semantics.contentDescription
|
|
import androidx.compose.ui.semantics.semantics
|
|
import androidx.compose.ui.unit.sp
|
|
import com.oshicue.tempo.core.L10n
|
|
import com.oshicue.tempo.core.TempoGroup
|
|
import com.oshicue.tempo.core.TempoLimits
|
|
import com.oshicue.tempo.core.TempoMember
|
|
|
|
/**
|
|
* Ticket entry for one member. The common case is one to three tickets, so those are
|
|
* one-tap chips; the keypad stays for anything larger. The duration preview updates as
|
|
* you type, and the last used count is pre-filled.
|
|
*/
|
|
@Composable
|
|
fun TicketEntryScreen(
|
|
member: TempoMember,
|
|
group: TempoGroup,
|
|
lastTicketCount: Int?,
|
|
onCancel: () -> Unit,
|
|
onConfirm: (Int) -> Unit,
|
|
) {
|
|
var tickets by remember {
|
|
mutableStateOf(
|
|
lastTicketCount?.takeIf { it in TempoLimits.TICKETS }?.toString() ?: "",
|
|
)
|
|
}
|
|
var errorMessage by remember { mutableStateOf<String?>(null) }
|
|
val focus = remember { FocusRequester() }
|
|
val count = tickets.toIntOrNull()
|
|
val totalSeconds = (count ?: 0) * group.secondsPerTicket
|
|
val valid = count != null && count in TempoLimits.TICKETS &&
|
|
totalSeconds <= TempoLimits.MAXIMUM_DURATION_SECONDS
|
|
val accent = Tempo.memberAccent(member.colorHex)
|
|
|
|
LaunchedEffect(member.id) {
|
|
if (tickets.isEmpty()) runCatching { focus.requestFocus() }
|
|
}
|
|
|
|
Column(
|
|
Modifier
|
|
.fillMaxSize()
|
|
.background(Tempo.colors.background)
|
|
.windowInsetsPadding(WindowInsets.safeDrawing),
|
|
) {
|
|
SheetHeader(title = L10n.text("tickets.newRound"), onDone = onCancel, doneLabel = L10n.text("common.cancel"))
|
|
Column(
|
|
Modifier.weight(1f).verticalScroll(rememberScrollState()).padding(horizontal = 22.dp).padding(top = 4.dp),
|
|
verticalArrangement = Arrangement.spacedBy(20.dp),
|
|
) {
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
Box(
|
|
Modifier.size(12.dp).clip(CircleShape).background(Tempo.parse(member.colorHex))
|
|
.border(0.75.dp, Tempo.colors.swatchOutline, CircleShape),
|
|
)
|
|
Spacer(Modifier.width(11.dp))
|
|
Text(
|
|
member.name,
|
|
fontSize = 20.sp, fontWeight = FontWeight.Bold, color = Tempo.colors.ink,
|
|
maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f),
|
|
)
|
|
Text(
|
|
L10n.text("tickets.roundTickets"),
|
|
fontSize = 13.sp,
|
|
color = Tempo.colors.muted,
|
|
maxLines = 1,
|
|
softWrap = false,
|
|
modifier = Modifier.padding(start = 8.dp),
|
|
)
|
|
}
|
|
|
|
Row(
|
|
Modifier
|
|
.fillMaxWidth()
|
|
.clip(RoundedCornerShape(TempoMetric.PANEL_RADIUS.dp))
|
|
.background(Tempo.colors.surface)
|
|
.border(1.dp, Tempo.colors.line, RoundedCornerShape(TempoMetric.PANEL_RADIUS.dp))
|
|
.padding(horizontal = 20.dp, vertical = 14.dp),
|
|
verticalAlignment = Alignment.Bottom,
|
|
) {
|
|
Box(Modifier.weight(1f)) {
|
|
if (tickets.isEmpty()) {
|
|
Text(
|
|
"0",
|
|
fontFamily = DigitsFont, fontSize = 54.sp,
|
|
color = Tempo.colors.ink.copy(alpha = 0.3f),
|
|
)
|
|
}
|
|
BasicTextField(
|
|
value = tickets,
|
|
onValueChange = { value ->
|
|
val filtered = value.filter { it.isDigit() }.take(3)
|
|
tickets = filtered
|
|
errorMessage = null
|
|
},
|
|
singleLine = true,
|
|
textStyle = TextStyle(
|
|
fontFamily = DigitsFont,
|
|
fontSize = 50.sp,
|
|
color = if (valid) Tempo.colors.ink else Tempo.colors.ink.copy(alpha = 0.55f),
|
|
),
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
|
cursorBrush = SolidColor(accent),
|
|
modifier = Modifier.fillMaxWidth().focusRequester(focus),
|
|
)
|
|
}
|
|
Text(L10n.text("tickets.unit"), fontSize = 22.sp, color = Tempo.colors.muted)
|
|
}
|
|
|
|
Row(horizontalArrangement = Arrangement.spacedBy(9.dp), modifier = Modifier.fillMaxWidth()) {
|
|
TempoLimits.QUICK_TICKET_COUNTS.forEach { value ->
|
|
val selected = count == value
|
|
Box(
|
|
Modifier
|
|
.weight(1f)
|
|
.height(46.dp)
|
|
.clip(RoundedCornerShape(TempoMetric.CONTROL_RADIUS.dp))
|
|
.background(if (selected) Tempo.colors.primaryFill else Tempo.colors.controlSurface)
|
|
.border(
|
|
1.dp,
|
|
if (selected) Color.Transparent else Tempo.colors.line,
|
|
RoundedCornerShape(TempoMetric.CONTROL_RADIUS.dp),
|
|
)
|
|
.clickable {
|
|
tickets = value.toString()
|
|
errorMessage = null
|
|
}
|
|
.semantics { contentDescription = L10n.format("tickets.quickPick", value) },
|
|
contentAlignment = Alignment.Center,
|
|
) {
|
|
Text(
|
|
"$value",
|
|
fontFamily = DigitsFont,
|
|
fontSize = 16.sp,
|
|
color = if (selected) Color.White else Tempo.colors.ink,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
Column(
|
|
Modifier
|
|
.fillMaxWidth()
|
|
.clip(RoundedCornerShape(TempoMetric.PANEL_RADIUS.dp))
|
|
.background(Tempo.colors.surface)
|
|
.border(1.dp, Tempo.colors.line, RoundedCornerShape(TempoMetric.PANEL_RADIUS.dp))
|
|
.padding(16.dp),
|
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
|
) {
|
|
Row(verticalAlignment = Alignment.Bottom) {
|
|
Text(
|
|
L10n.format("tickets.formula", group.secondsPerTicket, count ?: 0),
|
|
fontSize = 13.sp,
|
|
color = Tempo.colors.muted,
|
|
maxLines = 2,
|
|
overflow = TextOverflow.Ellipsis,
|
|
modifier = Modifier.weight(1f).padding(end = 10.dp),
|
|
)
|
|
Text(
|
|
tempoTime(totalSeconds.toDouble()),
|
|
fontFamily = DigitsFont,
|
|
fontSize = 22.sp,
|
|
color = if (Tempo.colors.isDark) accent else Tempo.colors.ink,
|
|
)
|
|
}
|
|
val fraction = (totalSeconds / TempoLimits.MAXIMUM_DURATION_SECONDS).coerceIn(0.0, 1.0).toFloat()
|
|
Box(Modifier.fillMaxWidth().height(5.dp).clip(CircleShape).background(Tempo.colors.controlSurface)) {
|
|
Box(
|
|
Modifier
|
|
.fillMaxWidth(fraction.coerceAtLeast(0.02f))
|
|
.height(5.dp)
|
|
.clip(CircleShape)
|
|
.background(accent.copy(alpha = if (valid) 0.8f else 0.35f)),
|
|
)
|
|
}
|
|
Text(
|
|
if (totalSeconds > TempoLimits.MAXIMUM_DURATION_SECONDS) {
|
|
L10n.text("tickets.maximumDuration")
|
|
} else {
|
|
L10n.text("tickets.hint")
|
|
},
|
|
fontSize = 12.sp,
|
|
color = if (totalSeconds > TempoLimits.MAXIMUM_DURATION_SECONDS) Tempo.colors.warning else Tempo.colors.muted,
|
|
)
|
|
errorMessage?.let { Text(it, fontSize = 12.sp, color = Color(0xFFC62828)) }
|
|
}
|
|
}
|
|
|
|
Box(Modifier.fillMaxWidth().padding(horizontal = 22.dp).padding(top = 8.dp, bottom = 14.dp)) {
|
|
TempoCapsuleButton(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
fill = if (valid) Tempo.colors.primaryFill else Tempo.colors.controlSurface,
|
|
contentColor = if (valid) Color.White else Tempo.colors.muted,
|
|
enabled = valid,
|
|
minHeight = 56.dp,
|
|
onClick = { count?.let(onConfirm) },
|
|
) {
|
|
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
Icon(Icons.Filled.PlayArrow, contentDescription = null, modifier = Modifier.size(18.dp))
|
|
Text(
|
|
L10n.text("tickets.confirmStart"),
|
|
fontSize = 16.sp, fontWeight = FontWeight.SemiBold, maxLines = 1,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Shared sheet header: a title on the left and one action on the right. */
|
|
@Composable
|
|
fun SheetHeader(title: String, doneLabel: String, onDone: () -> Unit) {
|
|
Row(
|
|
Modifier.fillMaxWidth().padding(horizontal = 20.dp).padding(top = 14.dp, bottom = 12.dp),
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
) {
|
|
Text(
|
|
title,
|
|
fontSize = 17.sp,
|
|
fontWeight = FontWeight.SemiBold,
|
|
color = Tempo.colors.ink,
|
|
modifier = Modifier.weight(1f),
|
|
maxLines = 1,
|
|
overflow = TextOverflow.Ellipsis,
|
|
)
|
|
Text(
|
|
doneLabel,
|
|
fontSize = 15.sp,
|
|
fontWeight = FontWeight.SemiBold,
|
|
color = Tempo.colors.pink,
|
|
maxLines = 1,
|
|
softWrap = false,
|
|
modifier = Modifier
|
|
.padding(start = 12.dp)
|
|
.clickable(onClick = onDone)
|
|
.padding(vertical = 4.dp, horizontal = 2.dp),
|
|
)
|
|
}
|
|
}
|