|
|
@@ -3,8 +3,10 @@ package com.example.torus.ui
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.border
|
|
|
import androidx.compose.foundation.clickable
|
|
|
+import androidx.compose.foundation.BorderStroke
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.PaddingValues
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
@@ -49,8 +51,13 @@ import com.example.torus.id.UuidV7
|
|
|
import com.example.torus.model.DistanceUnit
|
|
|
import com.example.torus.model.ExerciseType
|
|
|
import com.example.torus.model.LastExerciseLog
|
|
|
+import com.example.torus.model.durationHours
|
|
|
+import com.example.torus.model.durationMinutes
|
|
|
+import com.example.torus.model.durationSecondsPart
|
|
|
+import com.example.torus.model.formatAmountFromMeters
|
|
|
import com.example.torus.model.formatDistanceMeters
|
|
|
import com.example.torus.model.formatDurationSeconds
|
|
|
+import com.example.torus.model.hasRecordedData
|
|
|
import com.example.torus.model.parseDistanceMeters
|
|
|
import com.example.torus.model.parseDurationSeconds
|
|
|
import com.example.torus.model.SavedExercise
|
|
|
@@ -202,8 +209,43 @@ private fun StartWorkoutContent(
|
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
|
style = MaterialTheme.typography.labelLarge
|
|
|
)
|
|
|
- lastLogs[exercise.id]?.let { log ->
|
|
|
- LastTimeCard(log = log)
|
|
|
+ lastLogs[exercise.id]?.takeIf { it.hasRecordedData() }?.let { log ->
|
|
|
+ LastTimeCard(
|
|
|
+ log = log,
|
|
|
+ onUseLastTime = {
|
|
|
+ when (log.type) {
|
|
|
+ ExerciseType.Weights -> {
|
|
|
+ val sets = setsByExercise.getOrPut(exercise.id) {
|
|
|
+ defaultWeightSets()
|
|
|
+ }
|
|
|
+ sets.clear()
|
|
|
+ if (log.sets.isEmpty()) {
|
|
|
+ sets.addAll(defaultWeightSets())
|
|
|
+ } else {
|
|
|
+ log.sets.forEach { lastSet ->
|
|
|
+ sets += WeightSetDraft(
|
|
|
+ id = UuidV7.generateString(),
|
|
|
+ weight = lastSet.weight,
|
|
|
+ reps = lastSet.reps
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ExerciseType.Distance -> {
|
|
|
+ val current = distanceByExercise[exercise.id] ?: DistanceDraft()
|
|
|
+ distanceByExercise[exercise.id] = current.copy(
|
|
|
+ amount = formatAmountFromMeters(
|
|
|
+ log.distanceMeters,
|
|
|
+ current.unit
|
|
|
+ ),
|
|
|
+ hours = durationHours(log.durationSeconds).toString(),
|
|
|
+ minutes = durationMinutes(log.durationSeconds).toString(),
|
|
|
+ seconds = durationSecondsPart(log.durationSeconds).toString()
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
when (exercise.type) {
|
|
|
ExerciseType.Weights -> {
|
|
|
@@ -286,7 +328,10 @@ private fun StartWorkoutContent(
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-private fun LastTimeCard(log: LastExerciseLog) {
|
|
|
+private fun LastTimeCard(
|
|
|
+ log: LastExerciseLog,
|
|
|
+ onUseLastTime: () -> Unit
|
|
|
+) {
|
|
|
val shape = RoundedCornerShape(14.dp)
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
|
@@ -296,11 +341,31 @@ private fun LastTimeCard(log: LastExerciseLog) {
|
|
|
.padding(16.dp),
|
|
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
|
) {
|
|
|
- Text(
|
|
|
- text = stringResource(R.string.last_time),
|
|
|
- color = Sand,
|
|
|
- style = MaterialTheme.typography.titleSmall
|
|
|
- )
|
|
|
+ Row(
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ text = stringResource(R.string.last_time),
|
|
|
+ color = Sand,
|
|
|
+ style = MaterialTheme.typography.titleSmall
|
|
|
+ )
|
|
|
+ OutlinedButton(
|
|
|
+ onClick = onUseLastTime,
|
|
|
+ shape = RoundedCornerShape(50),
|
|
|
+ contentPadding = PaddingValues(horizontal = 14.dp, vertical = 6.dp),
|
|
|
+ colors = ButtonDefaults.outlinedButtonColors(
|
|
|
+ contentColor = MaterialTheme.colorScheme.onBackground
|
|
|
+ ),
|
|
|
+ border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant)
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ text = stringResource(R.string.autofill),
|
|
|
+ style = MaterialTheme.typography.labelLarge
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
when (log.type) {
|
|
|
ExerciseType.Weights -> {
|
|
|
if (log.sets.isEmpty()) {
|