Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Support miles in SessionExerciseCardItem
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 19, 2022
1 parent 63bbbd0 commit 76d3c00
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ package com.ankitsuda.rebound.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Chip
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Icon
import androidx.compose.material.Text
Expand All @@ -45,15 +43,16 @@ import com.ankitsuda.base.util.colorFromSupersetId
import com.ankitsuda.base.util.isDark
import com.ankitsuda.base.util.lighterOrDarkerColor
import com.ankitsuda.base.util.toReadableString
import com.ankitsuda.base.utils.toDurationStr
import com.ankitsuda.common.compose.kgToUserPrefStr
import com.ankitsuda.common.compose.kmToUserPrefStr
import com.ankitsuda.common.compose.userPrefDistanceUnitStr
import com.ankitsuda.common.compose.userPrefWeightUnitStr
import com.ankitsuda.rebound.domain.*
import com.ankitsuda.rebound.domain.entities.Exercise
import com.ankitsuda.rebound.domain.entities.ExerciseLogEntry
import com.ankitsuda.rebound.ui.theme.LocalThemeState
import com.ankitsuda.rebound.ui.theme.ReboundTheme
import com.google.accompanist.flowlayout.FlowRow
import com.google.accompanist.flowlayout.MainAxisAlignment
import com.google.accompanist.flowlayout.SizeMode


Expand All @@ -68,6 +67,7 @@ fun SessionExerciseCardItem(
title: String?,
subtitle: String? = null,
supersetId: Int? = null,
exerciseCategory: ExerciseCategory,
entries: List<ExerciseLogEntry>
) {
val sortedEntries by remember(key1 = entries) {
Expand Down Expand Up @@ -137,6 +137,7 @@ fun SessionExerciseCardItem(
val entry = sortedEntries[i]
SessionExerciseSetItem(
entry = entry,
exerciseCategory = exerciseCategory,
revisedSetText = revisedSetsTexts[sortedEntries.indexOf(entry)],
)
if (i != sortedEntries.size - 1) {
Expand All @@ -151,6 +152,7 @@ fun SessionExerciseCardItem(
@Composable
fun SessionExerciseSetItem(
entry: ExerciseLogEntry,
exerciseCategory: ExerciseCategory,
revisedSetText: Pair<String, Color?>,
) {
Column(modifier = Modifier.fillMaxWidth()) {
Expand All @@ -177,14 +179,28 @@ fun SessionExerciseSetItem(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(20.dp)
) {
SetColumnItem(
value = entry.weight.kgToUserPrefStr(),
title = userPrefWeightUnitStr()
)
SetColumnItem(
value = (entry.reps ?: 0).toString(),
title = stringResource(id = R.string.reps_lowercase)
)
when (exerciseCategory) {
ExerciseCategory.WEIGHTS_AND_REPS -> SetColumnItem(
value = entry.weight.kgToUserPrefStr(),
title = userPrefWeightUnitStr()
)
ExerciseCategory.DISTANCE_AND_TIME -> SetColumnItem(
value = entry.distance.kmToUserPrefStr(),
title = userPrefDistanceUnitStr()
)
else -> {}
}
when (exerciseCategory) {
ExerciseCategory.WEIGHTS_AND_REPS, ExerciseCategory.REPS -> SetColumnItem(
value = (entry.reps ?: 0).toString(),
title = stringResource(id = R.string.reps_lowercase)
)
ExerciseCategory.DISTANCE_AND_TIME, ExerciseCategory.TIME -> SetColumnItem(
value = (entry.timeRecorded ?: 0).toString(),
title = stringResource(id = R.string.time)
)
else -> {}
}
entry.rpe?.let {
SetColumnItem(
value = it.toReadableString() ?: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ankitsuda.rebound.domain.entities.Exercise
import com.ankitsuda.rebound.domain.entities.LogEntriesWithWorkout
import com.ankitsuda.rebound.ui.components.SessionExerciseCardItem
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle

@Composable
fun ExerciseDetailHistoryTab(list: List<LogEntriesWithWorkout>) {
fun ExerciseDetailHistoryTab(
exercise: Exercise,
list: List<LogEntriesWithWorkout>
) {
LazyColumn(
modifier = Modifier
.fillMaxSize(),
Expand All @@ -43,6 +47,7 @@ fun ExerciseDetailHistoryTab(list: List<LogEntriesWithWorkout>) {
.padding(bottom = 16.dp),
onClick = { },
title = workout.name,
exerciseCategory = exercise.category,
subtitle = (workout.startAt ?: workout.createdAt)?.format(
DateTimeFormatter.ofLocalizedDateTime(
FormatStyle.MEDIUM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,18 @@ fun ExerciseDetailScreen(
verticalAlignment = Alignment.Top,
count = 3,
) { index ->
when (index) {
0 -> {
ExerciseDetailChartsTab(charts)
}
1 -> {
ExerciseDetailHistoryTab(logEntriesWithWorkoutList)
}
2 -> {
exercise?.let {
exercise?.let {
when (index) {
0 -> {
ExerciseDetailChartsTab(charts)
}
1 -> {
ExerciseDetailHistoryTab(
exercise = it,
list = logEntriesWithWorkoutList
)
}
2 -> {
ExerciseDetailAboutTab(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ fun SessionScreen(
.padding(bottom = 20.dp),
supersetId = log.junction.supersetId,
title = log.exercise.name ?: "",
exerciseCategory = log.exercise.category,
entries = log.logEntries
)
}
Expand Down

0 comments on commit 76d3c00

Please sign in to comment.