Răsfoiți Sursa

Compress stuff at the top of session page to reduce vertical space

Lee Morgan 2 săptămâni în urmă
părinte
comite
6c0d61f720
1 a modificat fișierele cu 76 adăugiri și 31 ștergeri
  1. 76 31
      app/src/main/java/com/example/torus/ui/StartWorkoutScreen.kt

+ 76 - 31
app/src/main/java/com/example/torus/ui/StartWorkoutScreen.kt

@@ -45,6 +45,7 @@ import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.res.stringResource
 import androidx.compose.ui.text.input.KeyboardType
+import androidx.compose.ui.text.style.TextOverflow
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import com.example.torus.R
@@ -195,23 +196,11 @@ private fun StartWorkoutContent(
                 .padding(horizontal = 16.dp, vertical = 8.dp),
             verticalArrangement = Arrangement.spacedBy(16.dp)
         ) {
-            Text(
-                text = workout.name.ifBlank { stringResource(R.string.untitled_workout) },
-                color = Sand,
-                style = MaterialTheme.typography.headlineMedium
+            SessionHeader(
+                workoutName = workout.name.ifBlank { stringResource(R.string.untitled_workout) },
+                showExercisesMenu = exercises.isNotEmpty(),
+                onOpenExercisesMenu = { showExerciseMenu = true }
             )
-            if (exercises.isNotEmpty()) {
-                OutlinedButton(
-                    onClick = { showExerciseMenu = true },
-                    modifier = Modifier.fillMaxWidth(),
-                    shape = RoundedCornerShape(50),
-                    colors = ButtonDefaults.outlinedButtonColors(
-                        contentColor = MaterialTheme.colorScheme.onBackground
-                    )
-                ) {
-                    Text(text = stringResource(R.string.exercises_menu))
-                }
-            }
             if (exercises.isEmpty()) {
                 Text(
                     text = stringResource(R.string.no_exercises),
@@ -221,24 +210,14 @@ private fun StartWorkoutContent(
             } else {
                 val currentIndex = exerciseIndex.coerceIn(0, exercises.lastIndex)
                 val exercise = exercises[currentIndex]
-                Text(
-                    text = stringResource(
+                SessionExerciseIdentity(
+                    name = exercise.name.ifBlank { stringResource(R.string.untitled_exercise) },
+                    typeLabel = stringResource(exercise.type.labelRes),
+                    progress = stringResource(
                         R.string.exercise_progress,
                         currentIndex + 1,
                         exercises.size
-                    ),
-                    color = MaterialTheme.colorScheme.onSurfaceVariant,
-                    style = MaterialTheme.typography.titleSmall
-                )
-                Text(
-                    text = exercise.name.ifBlank { stringResource(R.string.untitled_exercise) },
-                    color = MaterialTheme.colorScheme.onBackground,
-                    style = MaterialTheme.typography.headlineSmall
-                )
-                Text(
-                    text = stringResource(exercise.type.labelRes),
-                    color = MaterialTheme.colorScheme.onSurfaceVariant,
-                    style = MaterialTheme.typography.labelLarge
+                    )
                 )
                 lastLogs[exercise.id]?.takeIf { it.hasRecordedData() }?.let { log ->
                     LastTimeCard(
@@ -358,6 +337,72 @@ private fun StartWorkoutContent(
     }
 }
 
+@Composable
+private fun SessionHeader(
+    workoutName: String,
+    showExercisesMenu: Boolean,
+    onOpenExercisesMenu: () -> Unit
+) {
+    Row(
+        modifier = Modifier.fillMaxWidth(),
+        horizontalArrangement = Arrangement.spacedBy(12.dp),
+        verticalAlignment = Alignment.CenterVertically
+    ) {
+        Text(
+            text = workoutName,
+            modifier = Modifier.weight(1f),
+            color = Sand,
+            style = MaterialTheme.typography.titleLarge,
+            maxLines = 1,
+            overflow = TextOverflow.Ellipsis
+        )
+        if (showExercisesMenu) {
+            OutlinedButton(
+                onClick = onOpenExercisesMenu,
+                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.exercises_menu),
+                    style = MaterialTheme.typography.labelLarge
+                )
+            }
+        }
+    }
+}
+
+@Composable
+private fun SessionExerciseIdentity(
+    name: String,
+    typeLabel: String,
+    progress: String
+) {
+    Row(
+        modifier = Modifier.fillMaxWidth(),
+        horizontalArrangement = Arrangement.spacedBy(12.dp),
+        verticalAlignment = Alignment.CenterVertically
+    ) {
+        Text(
+            text = "$name  ·  $typeLabel",
+            modifier = Modifier.weight(1f),
+            color = MaterialTheme.colorScheme.onBackground,
+            style = MaterialTheme.typography.titleMedium,
+            maxLines = 1,
+            overflow = TextOverflow.Ellipsis
+        )
+        Text(
+            text = progress,
+            color = MaterialTheme.colorScheme.onSurfaceVariant,
+            style = MaterialTheme.typography.labelLarge,
+            maxLines = 1
+        )
+    }
+}
+
 @Composable
 private fun LastTimeCard(
     log: LastExerciseLog,