|
|
@@ -48,6 +48,9 @@ import com.example.torus.data.WorkoutRepository
|
|
|
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.formatDistanceMeters
|
|
|
+import com.example.torus.model.formatDurationSeconds
|
|
|
import com.example.torus.model.parseDistanceMeters
|
|
|
import com.example.torus.model.parseDurationSeconds
|
|
|
import com.example.torus.model.SavedExercise
|
|
|
@@ -83,6 +86,7 @@ fun StartWorkoutScreen(
|
|
|
var detail by remember(workoutId) { mutableStateOf<WorkoutDetail?>(null) }
|
|
|
var exerciseIndex by remember(workoutId) { mutableIntStateOf(0) }
|
|
|
var isCompleting by remember { mutableStateOf(false) }
|
|
|
+ var lastLogs by remember(workoutId) { mutableStateOf<Map<String, LastExerciseLog>>(emptyMap()) }
|
|
|
val startedAt = remember(workoutId) { System.currentTimeMillis() }
|
|
|
val setsByExercise = remember(workoutId) {
|
|
|
mutableStateMapOf<String, SnapshotStateList<WeightSetDraft>>()
|
|
|
@@ -103,6 +107,7 @@ fun StartWorkoutScreen(
|
|
|
ExerciseType.Distance -> distanceByExercise[exercise.id] = DistanceDraft()
|
|
|
}
|
|
|
}
|
|
|
+ lastLogs = workoutRepository.getLastExerciseLogs(workoutId)
|
|
|
}
|
|
|
|
|
|
val workout = detail ?: return
|
|
|
@@ -111,6 +116,7 @@ fun StartWorkoutScreen(
|
|
|
exerciseIndex = exerciseIndex,
|
|
|
setsByExercise = setsByExercise,
|
|
|
distanceByExercise = distanceByExercise,
|
|
|
+ lastLogs = lastLogs,
|
|
|
isCompleting = isCompleting,
|
|
|
modifier = modifier,
|
|
|
onNextExercise = { exerciseIndex += 1 },
|
|
|
@@ -133,6 +139,7 @@ private fun StartWorkoutContent(
|
|
|
exerciseIndex: Int,
|
|
|
setsByExercise: MutableMap<String, SnapshotStateList<WeightSetDraft>>,
|
|
|
distanceByExercise: MutableMap<String, DistanceDraft>,
|
|
|
+ lastLogs: Map<String, LastExerciseLog> = emptyMap(),
|
|
|
isCompleting: Boolean = false,
|
|
|
modifier: Modifier = Modifier,
|
|
|
onNextExercise: () -> Unit = {},
|
|
|
@@ -195,6 +202,9 @@ private fun StartWorkoutContent(
|
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
|
style = MaterialTheme.typography.labelLarge
|
|
|
)
|
|
|
+ lastLogs[exercise.id]?.let { log ->
|
|
|
+ LastTimeCard(log = log)
|
|
|
+ }
|
|
|
when (exercise.type) {
|
|
|
ExerciseType.Weights -> {
|
|
|
val sets = setsByExercise.getOrPut(exercise.id) { defaultWeightSets() }
|
|
|
@@ -275,6 +285,64 @@ private fun StartWorkoutContent(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+@Composable
|
|
|
+private fun LastTimeCard(log: LastExerciseLog) {
|
|
|
+ val shape = RoundedCornerShape(14.dp)
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .background(MaterialTheme.colorScheme.surfaceVariant, shape)
|
|
|
+ .border(1.dp, MaterialTheme.colorScheme.outline, shape)
|
|
|
+ .padding(16.dp),
|
|
|
+ verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ text = stringResource(R.string.last_time),
|
|
|
+ color = Sand,
|
|
|
+ style = MaterialTheme.typography.titleSmall
|
|
|
+ )
|
|
|
+ when (log.type) {
|
|
|
+ ExerciseType.Weights -> {
|
|
|
+ if (log.sets.isEmpty()) {
|
|
|
+ Text(
|
|
|
+ text = stringResource(R.string.last_empty_value),
|
|
|
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
|
+ style = MaterialTheme.typography.bodyMedium
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ log.sets.forEachIndexed { index, set ->
|
|
|
+ val weight = set.weight.ifBlank { stringResource(R.string.last_empty_value) }
|
|
|
+ val reps = set.reps.ifBlank { stringResource(R.string.last_empty_value) }
|
|
|
+ Text(
|
|
|
+ text = stringResource(R.string.last_set, index + 1, weight, reps),
|
|
|
+ color = MaterialTheme.colorScheme.onBackground,
|
|
|
+ style = MaterialTheme.typography.bodyMedium
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ExerciseType.Distance -> {
|
|
|
+ Text(
|
|
|
+ text = stringResource(
|
|
|
+ R.string.last_distance,
|
|
|
+ formatDistanceMeters(log.distanceMeters)
|
|
|
+ ),
|
|
|
+ color = MaterialTheme.colorScheme.onBackground,
|
|
|
+ style = MaterialTheme.typography.bodyMedium
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = stringResource(
|
|
|
+ R.string.last_duration,
|
|
|
+ formatDurationSeconds(log.durationSeconds)
|
|
|
+ ),
|
|
|
+ color = MaterialTheme.colorScheme.onBackground,
|
|
|
+ style = MaterialTheme.typography.bodyMedium
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
@Composable
|
|
|
private fun WeightSetsEditor(
|
|
|
sets: SnapshotStateList<WeightSetDraft>,
|