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

Commit

Permalink
Support lbs in warm up calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 18, 2022
1 parent 1c83994 commit 0a9035c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ fun LazyListScope.workoutExerciseItemAlt(
}

if (warmUpSetsDialogVisible) {
WarmUpCalculatorDialog(
startingWorkSetWeight = warmUpWorkSetWeight,
startingSets = dialogWarmUpSets,
onInsert = { newWarmUpWorkSetWeight, newWarmUpSets ->
updateWarmUpSets(newWarmUpWorkSetWeight, newWarmUpSets)
},
onDismissRequest = {
warmUpSetsDialogVisible = false
}
)
key(LocalAppSettings.current.weightUnit) {
WarmUpCalculatorDialog(
startingWorkSetWeight = warmUpWorkSetWeight,
startingSets = dialogWarmUpSets,
onInsert = { newWarmUpWorkSetWeight, newWarmUpSets ->
updateWarmUpSets(newWarmUpWorkSetWeight, newWarmUpSets)
},
onDismissRequest = {
warmUpSetsDialogVisible = false
}
)
}
}

Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.hilt.navigation.compose.hiltViewModel
import com.ankitsuda.base.util.fromKgToLbs
import com.ankitsuda.base.util.fromLbsToKg
import com.ankitsuda.base.util.lighterOrDarkerColor
import com.ankitsuda.base.util.toReadableString
import com.ankitsuda.common.compose.LocalAppSettings
import com.ankitsuda.common.compose.kgToUserPrefStr
import com.ankitsuda.rebound.domain.WeightUnit
import com.ankitsuda.rebound.ui.components.RButton
import com.ankitsuda.rebound.ui.components.RSpacer
import com.ankitsuda.rebound.ui.components.workouteditor.R
Expand Down Expand Up @@ -105,10 +109,14 @@ private fun WarmUpCalculatorDialogLayout(
onClickInsert: (workSet: Double) -> Unit,
onClickCancel: () -> Unit
) {
val fieldValue = startingWorkSetWeight?.kgToUserPrefStr() ?: ""

var workSetStr by remember {
mutableStateOf(startingWorkSetWeight?.toReadableString() ?: "")
mutableStateOf(fieldValue)
}

val weightUnit = LocalAppSettings.current.weightUnit

Surface(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -132,13 +140,15 @@ private fun WarmUpCalculatorDialogLayout(
RSpacer(space = 12.dp)

Text(
text = stringResource(R.string.work_set_kg),
text = when (weightUnit) {
WeightUnit.KG -> stringResource(R.string.work_set_kg)
WeightUnit.LBS -> stringResource(R.string.work_set_lbs)
},
style = ReboundTheme.typography.caption,
color = ReboundTheme.colors.onBackground.copy(0.75f)
)
}


Row(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -154,7 +164,13 @@ private fun WarmUpCalculatorDialogLayout(
value = workSetStr,
onValueChange = {
workSetStr = it
onUpdateWorkSet(20.0, it.toDoubleOrNull() ?: 0.0)
onUpdateWorkSet(
20.0,
when (weightUnit) {
WeightUnit.KG -> it.toDoubleOrNull()
WeightUnit.LBS -> it.toDoubleOrNull()?.fromLbsToKg()
} ?: 0.0
)
},
reboundKeyboardType = ReboundKeyboardType.WEIGHT,
)
Expand Down Expand Up @@ -182,8 +198,11 @@ private fun WarmUpCalculatorDialogLayout(
modifier = Modifier
.fillMaxWidth()
.animateItemPlacement(),
workSetWeight = workSetStr.toDoubleOrNull() ?: 0.0,
barWeight = 20.0,
workSetWeightKg = when (weightUnit) {
WeightUnit.KG -> workSetStr.toDoubleOrNull()
WeightUnit.LBS -> workSetStr.toDoubleOrNull()?.fromLbsToKg()
} ?: 0.0,
barWeightKg = 20.0,
startingSet = set,
onChangeValue = onUpdateSet,
onDeleteSet = {
Expand Down Expand Up @@ -243,10 +262,10 @@ private fun ColumnScope.DialogButtonsRow(
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
TextButton(onClick = onClickCancel) {
Text("CANCEL")
Text(stringResource(id = R.string.cancel))
}
TextButton(onClick = onClickInsert) {
Text("INSERT")
Text(stringResource(id = R.string.insert))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.ankitsuda.base.util.toReadableString
import com.ankitsuda.base.util.fromKgToLbs
import com.ankitsuda.common.compose.LocalAppSettings
import com.ankitsuda.common.compose.kgToUserPrefStr
import com.ankitsuda.rebound.domain.WeightUnit
import com.ankitsuda.rebound.domain.WeightUnit.*
import com.ankitsuda.rebound.ui.components.workouteditor.SetSwipeWrapperComponent
import com.ankitsuda.rebound.ui.keyboard.enums.ReboundKeyboardType
import com.ankitsuda.rebound.ui.keyboard.field.ReboundSetTextField
Expand All @@ -37,21 +41,27 @@ import com.ankitsuda.rebound.ui.theme.ReboundTheme
@Composable
internal fun WarmUpSetComponent(
modifier: Modifier = Modifier,
workSetWeight: Double,
barWeight: Double,
workSetWeightKg: Double,
barWeightKg: Double,
startingSet: WarmUpSet,
onDeleteSet: () -> Unit,
onChangeValue: (WarmUpSet) -> Unit
) {
val fieldContentColor = ReboundTheme.colors.onBackground
val weightUnit = LocalAppSettings.current.weightUnit

val setWeight =
if (startingSet.weightPercentage == -1 || startingSet.weightPercentage == null) {
barWeight
barWeightKg
} else {
workSetWeight * startingSet.weightPercentage!! / 100
workSetWeightKg * startingSet.weightPercentage!! / 100
}

// val setWeight = when (weightUnit) {
// KG -> setWeightKg
// LBS -> setWeightKg.fromKgToLbs()
// }

val bgColor =
LocalElevationOverlay.current?.apply(
color = ReboundTheme.colors.background,
Expand Down Expand Up @@ -94,9 +104,9 @@ internal fun WarmUpSetComponent(
?: -1

val weight = if (weightInt == -1) {
barWeight
barWeightKg
} else {
workSetWeight * weightInt / 100
workSetWeightKg * weightInt / 100
}

val reps = arr.getOrNull(1)?.toIntOrNull() ?: 0
Expand All @@ -112,7 +122,7 @@ internal fun WarmUpSetComponent(
}
)
Text(
text = "${setWeight.toReadableString()}kg x ${startingSet.reps ?: 0}",
text = "${setWeight.kgToUserPrefStr(addUnitSuffix = true)} x ${startingSet.reps ?: 0}",
style = ReboundTheme.typography.caption,
color = ReboundTheme.colors.onBackground,
textAlign = TextAlign.Center,
Expand Down
2 changes: 2 additions & 0 deletions modules/common-ui-resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
<string name="top_bar">Top Bar</string>
<string name="title_alignment">Title alignment</string>
<string name="work_set_kg">Work set (kg)</string>
<string name="work_set_lbs">Work set (lbs)</string>
<string name="add_set">Add set</string>
<string name="set">Set</string>
<string name="formula">Formula</string>
Expand Down Expand Up @@ -231,4 +232,5 @@
<string name="rpe_9_5_description">Could have maybe done 1 more rep</string>
<string name="rpe_10_title">Max Effort</string>
<string name="rpe_10_description">No more reps possible</string>
<string name="insert">Insert</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -104,42 +104,42 @@ fun ReboundSetKeyboardComponent(
)
}
) { mCurrentMode ->
when (mCurrentMode) {
KeyboardModeType.NUMBERS -> {
NumKeysContainerComponent(
modifier = Modifier
.fillMaxWidth(1f)
.height(
height = 250.dp,
)
.padding(end = rightButtonsWidth)
.background(theme.keyboardBackgroundColor),
reboundKeyboardType = reboundKeyboardType,
onClickNumKey = { numKey ->
onClickNumKey(numKey)
}
)
}
KeyboardModeType.PLATE_CALCULATOR -> {
key(LocalAppSettings.current.weightUnit) {
PlateCalculatorComponent(
key(inputConnection) {
when (mCurrentMode) {
KeyboardModeType.NUMBERS -> {
NumKeysContainerComponent(
modifier = Modifier
.fillMaxWidth()
.fillMaxWidth(1f)
.height(
height = 250.dp,
),
weight = inputConnection?.getText()?.toDoubleOrNull() ?: 0.0
)
.padding(end = rightButtonsWidth)
.background(theme.keyboardBackgroundColor),
reboundKeyboardType = reboundKeyboardType,
onClickNumKey = { numKey ->
onClickNumKey(numKey)
}
)
}
}
KeyboardModeType.WARMUP_PICKER -> {
WarmUpListPickerComponent(
onSetText = ::setText,
startingText = inputConnection?.getText()
)
}
KeyboardModeType.RPE_PICKER -> {
key(inputConnection) {
KeyboardModeType.PLATE_CALCULATOR -> {
key(LocalAppSettings.current.weightUnit) {
PlateCalculatorComponent(
modifier = Modifier
.fillMaxWidth()
.height(
height = 250.dp,
),
weight = inputConnection?.getText()?.toDoubleOrNull() ?: 0.0
)
}
}
KeyboardModeType.WARMUP_PICKER -> {
WarmUpListPickerComponent(
onSetText = ::setText,
startingText = inputConnection?.getText()
)
}
KeyboardModeType.RPE_PICKER -> {
RpePickerComponent(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -150,6 +150,7 @@ fun ReboundSetKeyboardComponent(
text = inputConnection?.getText(),
)
}

}
}
}
Expand Down

0 comments on commit 0a9035c

Please sign in to comment.