Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,31 @@ data class JustLiftDefaults(
val weightPerCableKg: Float = 20f,
val weightChangePerRep: Float = 0f,
val eccentricLoadPercentage: Int = 100,
val echoLevelValue: Int = 2
)
val echoLevelValue: Int = 2,
val stallDetectionEnabled: Boolean = true // Stall detection auto-stop toggle
) {
fun getEccentricLoad(): com.devil.phoenixproject.domain.model.EccentricLoad {
return com.devil.phoenixproject.domain.model.EccentricLoad.entries.find { it.percentage == eccentricLoadPercentage }
?: com.devil.phoenixproject.domain.model.EccentricLoad.LOAD_100
}

fun getEchoLevel(): com.devil.phoenixproject.domain.model.EchoLevel {
return com.devil.phoenixproject.domain.model.EchoLevel.entries.find { it.levelValue == echoLevelValue }
?: com.devil.phoenixproject.domain.model.EchoLevel.HARDER
}

fun toWorkoutType(): com.devil.phoenixproject.domain.model.WorkoutType {
return when (workoutModeId) {
0 -> com.devil.phoenixproject.domain.model.WorkoutType.Program(com.devil.phoenixproject.domain.model.ProgramMode.OldSchool)
2 -> com.devil.phoenixproject.domain.model.WorkoutType.Program(com.devil.phoenixproject.domain.model.ProgramMode.Pump)
3 -> com.devil.phoenixproject.domain.model.WorkoutType.Program(com.devil.phoenixproject.domain.model.ProgramMode.TUT)
4 -> com.devil.phoenixproject.domain.model.WorkoutType.Program(com.devil.phoenixproject.domain.model.ProgramMode.TUTBeast)
6 -> com.devil.phoenixproject.domain.model.WorkoutType.Program(com.devil.phoenixproject.domain.model.ProgramMode.EccentricOnly)
10 -> com.devil.phoenixproject.domain.model.WorkoutType.Echo(getEchoLevel(), getEccentricLoad())
else -> com.devil.phoenixproject.domain.model.WorkoutType.Program(com.devil.phoenixproject.domain.model.ProgramMode.OldSchool)
}
}
}

/**
* Preferences Manager interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ data class WorkoutParameters(
val selectedExerciseId: String? = null,
val isAMRAP: Boolean = false, // AMRAP (As Many Reps As Possible) - disables auto-stop

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "AMRAP (As Many Reps As Possible) - disables auto-stop" is now outdated since AMRAP mode can have stall detection enabled when stallDetectionEnabled is true. The comment should be updated to reflect that stall detection is now configurable.

Suggested change
val isAMRAP: Boolean = false, // AMRAP (As Many Reps As Possible) - disables auto-stop
val isAMRAP: Boolean = false, // AMRAP (As Many Reps As Possible) - auto-stop (stall detection) is configurable via stallDetectionEnabled

Copilot uses AI. Check for mistakes.
val lastUsedWeightKg: Float? = null, // Last used weight for this exercise (for quick preset)
val prWeightKg: Float? = null // Personal record weight for this exercise (for quick preset)
val prWeightKg: Float? = null, // Personal record weight for this exercise (for quick preset)
val stallDetectionEnabled: Boolean = true // Enable stall detection auto-stop for Just Lift/AMRAP modes
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ data class RoutineExercise(
val isAMRAP: Boolean = false,
// Per Set Rest Time toggle - when true, each set has its own rest time; when false, single rest time applies to all sets
val perSetRestTime: Boolean = false,
// Stall detection toggle - when true, auto-stops set if user hesitates too long (applies to AMRAP/Just Lift modes)
val stallDetectionEnabled: Boolean = true,
// Superset configuration
val supersetGroupId: String? = null, // Exercises with same ID are in same superset
val supersetOrder: Int = 0, // Order within the superset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fun ExerciseEditBottomSheet(
val perSetRestTime by viewModel.perSetRestTime.collectAsState()
val eccentricLoad by viewModel.eccentricLoad.collectAsState()
val echoLevel by viewModel.echoLevel.collectAsState()
val stallDetectionEnabled by viewModel.stallDetectionEnabled.collectAsState()

// Fetch current PR for selected mode
var currentPR by remember { mutableStateOf<PersonalRecord?>(null) }
Expand Down Expand Up @@ -394,6 +395,44 @@ fun ExerciseEditBottomSheet(
}
}

// Stall Detection toggle - show when any set is AMRAP
val hasAMRAPSets = sets.any { it.reps == null }
if (hasAMRAPSets) {
Surface(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(12.dp),
color = MaterialTheme.colorScheme.surface,
border = BorderStroke(1.dp, MaterialTheme.colorScheme.surfaceVariant),
shadowElevation = 2.dp
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(Spacing.small),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = "Stall Detection",
style = MaterialTheme.typography.bodyMedium,
fontWeight = if (stallDetectionEnabled) FontWeight.Bold else FontWeight.Normal,
color = if (stallDetectionEnabled) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface
)
Text(
text = "Auto-stop set when movement pauses for 5 seconds",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = stallDetectionEnabled,
onCheckedChange = viewModel::onStallDetectionEnabledChange
)
}
}
}

// Sets Configuration
SetsConfiguration(
sets = sets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fun JustLiftScreen(
var weightChangePerRep by remember { mutableStateOf(0) } // Progression/Regression value
var eccentricLoad by remember { mutableStateOf(EccentricLoad.LOAD_100) }
var echoLevel by remember { mutableStateOf(EchoLevel.HARDER) }
var stallDetectionEnabled by remember { mutableStateOf(true) }
var defaultsLoaded by remember { mutableStateOf(false) }

// Load saved Just Lift defaults on screen init
Expand All @@ -102,7 +103,10 @@ fun JustLiftScreen(
eccentricLoad = defaults.getEccentricLoad()
echoLevel = defaults.getEchoLevel()

Logger.d("Loaded Just Lift defaults: modeId=${defaults.workoutModeId}, weight=${defaults.weightPerCableKg}kg, progression=${defaults.weightChangePerRep}")
// Restore stall detection setting
stallDetectionEnabled = defaults.stallDetectionEnabled

Logger.d("Loaded Just Lift defaults: modeId=${defaults.workoutModeId}, weight=${defaults.weightPerCableKg}kg, progression=${defaults.weightChangePerRep}, stallDetection=$stallDetectionEnabled")
}
defaultsLoaded = true
}
Expand Down Expand Up @@ -150,7 +154,7 @@ fun JustLiftScreen(
}

// Update parameters whenever user changes them
LaunchedEffect(selectedMode, weightPerCable, weightChangePerRep) {
LaunchedEffect(selectedMode, weightPerCable, weightChangePerRep, stallDetectionEnabled) {
val weightChangeKg = if (weightUnit == WeightUnit.LB) {
weightChangePerRep / 2.20462f
} else {
Expand All @@ -162,7 +166,8 @@ fun JustLiftScreen(
weightPerCableKg = weightPerCable,
progressionRegressionKg = weightChangeKg,
isJustLift = true,
useAutoStart = true // Enable auto-start for Just Lift
useAutoStart = true, // Enable auto-start for Just Lift
stallDetectionEnabled = stallDetectionEnabled
)
viewModel.updateWorkoutParameters(updatedParameters)
}
Expand Down Expand Up @@ -251,6 +256,41 @@ fun JustLiftScreen(
}
}

// Stall Detection Toggle Card
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh
),
shape = RoundedCornerShape(16.dp)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = Spacing.medium, vertical = Spacing.small),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(modifier = Modifier.weight(1f)) {
Text(
"Stall Detection",
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurface
)
Text(
"Auto-stop set when movement pauses for 5 seconds",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = stallDetectionEnabled,
onCheckedChange = { stallDetectionEnabled = it }
)
}
}

// Mode-specific options - OLD SCHOOL & PUMP
val isOldSchoolOrPump = selectedMode is WorkoutMode.OldSchool || selectedMode is WorkoutMode.Pump
if (isOldSchoolOrPump) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class ExerciseConfigViewModel constructor() : ViewModel() {
private val _echoLevel = MutableStateFlow(EchoLevel.HARDER)
val echoLevel: StateFlow<EchoLevel> = _echoLevel.asStateFlow()

private val _stallDetectionEnabled = MutableStateFlow(true)
val stallDetectionEnabled: StateFlow<Boolean> = _stallDetectionEnabled.asStateFlow()

init {

}
Expand Down Expand Up @@ -166,6 +169,7 @@ class ExerciseConfigViewModel constructor() : ViewModel() {
_perSetRestTime.value = exercise.perSetRestTime
_eccentricLoad.value = exercise.eccentricLoad
_echoLevel.value = exercise.echoLevel
_stallDetectionEnabled.value = exercise.stallDetectionEnabled

_initialized.value = true
}
Expand Down Expand Up @@ -213,6 +217,10 @@ class ExerciseConfigViewModel constructor() : ViewModel() {
}
}

fun onStallDetectionEnabledChange(enabled: Boolean) {
_stallDetectionEnabled.value = enabled
}

fun updateReps(setId: String, reps: Int?) {
_sets.value = _sets.value.map { set ->
if (set.id == setId) set.copy(reps = reps) else set
Expand Down Expand Up @@ -297,7 +305,8 @@ class ExerciseConfigViewModel constructor() : ViewModel() {
_sets.value.firstOrNull()?.duration ?: 30 // Default to 30 seconds if not set
} else null,
perSetRestTime = _perSetRestTime.value,
isAMRAP = isAMRAP
isAMRAP = isAMRAP,
stallDetectionEnabled = _stallDetectionEnabled.value
)

logDebug("Updated exercise to save:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,10 @@ class MainViewModel constructor(
// Update rep ranges for position bar ROM visualization
_repRanges.value = repCounter.getRepRanges()

// Just Lift Auto-Stop (danger zone detection)
// Note: AMRAP mode explicitly disables auto-stop
// Just Lift / AMRAP Auto-Stop (stall detection)
// Stall detection is now toggleable via stallDetectionEnabled flag
val params = _workoutParameters.value
if (params.isJustLift && !params.isAMRAP) {
if ((params.isJustLift || params.isAMRAP) && params.stallDetectionEnabled) {
checkAutoStop(metric)
}

Expand Down Expand Up @@ -1139,10 +1139,11 @@ class MainViewModel constructor(
stopAtTop = stopAtTop.value,
warmupReps = _workoutParameters.value.warmupReps,
isAMRAP = firstSetReps == null, // This SET is AMRAP if its reps is null
selectedExerciseId = firstExercise.exercise.id
selectedExerciseId = firstExercise.exercise.id,
stallDetectionEnabled = firstExercise.stallDetectionEnabled
)

Logger.d { "Created WorkoutParameters: isAMRAP=${params.isAMRAP}, isJustLift=${params.isJustLift}" }
Logger.d { "Created WorkoutParameters: isAMRAP=${params.isAMRAP}, isJustLift=${params.isJustLift}, stallDetection=${params.stallDetectionEnabled}" }
updateWorkoutParameters(params)
}

Expand Down Expand Up @@ -2319,7 +2320,8 @@ class MainViewModel constructor(
_workoutParameters.value = _workoutParameters.value.copy(
reps = targetReps ?: 0,
weightPerCableKg = setWeight,
isAMRAP = targetReps == null
isAMRAP = targetReps == null,
stallDetectionEnabled = currentExercise.stallDetectionEnabled
)

repCounter.resetCountsOnly()
Expand Down Expand Up @@ -2368,7 +2370,8 @@ class MainViewModel constructor(
workoutType = nextExercise.workoutType,
progressionRegressionKg = nextExercise.progressionKg,
selectedExerciseId = nextExercise.exercise.id,
isAMRAP = nextSetReps == null
isAMRAP = nextSetReps == null,
stallDetectionEnabled = nextExercise.stallDetectionEnabled
)

repCounter.resetCountsOnly()
Expand Down Expand Up @@ -2397,7 +2400,8 @@ class MainViewModel constructor(
workoutType = nextExercise.workoutType,
progressionRegressionKg = nextExercise.progressionKg,
selectedExerciseId = nextExercise.exercise.id,
isAMRAP = nextSetReps == null
isAMRAP = nextSetReps == null,
stallDetectionEnabled = nextExercise.stallDetectionEnabled
)

repCounter.resetCountsOnly()
Expand All @@ -2420,7 +2424,8 @@ class MainViewModel constructor(
_workoutParameters.value = _workoutParameters.value.copy(
reps = targetReps ?: 0,
weightPerCableKg = setWeight,
isAMRAP = targetReps == null
isAMRAP = targetReps == null,
stallDetectionEnabled = currentExercise.stallDetectionEnabled
)

repCounter.resetCountsOnly()
Expand All @@ -2445,7 +2450,8 @@ class MainViewModel constructor(
workoutType = nextExercise.workoutType,
progressionRegressionKg = nextExercise.progressionKg,
selectedExerciseId = nextExercise.exercise.id,
isAMRAP = nextSetReps == null
isAMRAP = nextSetReps == null,
stallDetectionEnabled = nextExercise.stallDetectionEnabled
)

repCounter.reset()
Expand Down Expand Up @@ -2505,7 +2511,8 @@ data class JustLiftDefaults(
val weightChangePerRep: Int, // In display units (kg or lbs based on user preference)
val workoutModeId: Int, // 0=OldSchool, 1=Pump, 2=Echo
val eccentricLoadPercentage: Int = 100,
val echoLevelValue: Int = 1 // 0=Hard, 1=Harder, 2=Hardest, 3=Epic
val echoLevelValue: Int = 1, // 0=Hard, 1=Harder, 2=Hardest, 3=Epic
val stallDetectionEnabled: Boolean = true // Stall detection auto-stop toggle
) {
/**
* Convert stored mode ID to WorkoutType
Expand Down