WT 1.1.22 reengineering: Training Plan execution, registration
This commit is contained in:
@@ -46,7 +46,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
try {
|
||||
if (event is TrainingPlanActivate) {
|
||||
yield TrainingPlanLoading();
|
||||
_myPlan = await trainingPlanRepository.activateTrainingPlan(event.trainingPlanId);
|
||||
_myPlan = trainingPlanRepository.activateTrainingPlan(event.trainingPlanId);
|
||||
_myPlan!.type = CustomerTrainingPlanType.template;
|
||||
|
||||
menuBloc.menuTreeRepository.sortedTree.forEach((name, list) {
|
||||
@@ -72,7 +72,6 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
event.detail.repeats =
|
||||
Common.reCalculateRepeatsByChangedWeight(event.detail.weight!, event.detail.repeats!.toDouble(), event.weight);
|
||||
event.detail.weight = event.weight;
|
||||
print(" weight: ${event.weight} new repeats: ${event.detail.repeats}");
|
||||
|
||||
yield TrainingPlanReady();
|
||||
} else if (event is TrainingPlanRepeatsChange) {
|
||||
@@ -102,13 +101,12 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
exercise.unitQuantity = event.detail.weight;
|
||||
exercise.dateAdd = DateTime.now();
|
||||
event.detail.exercises.add(exercise);
|
||||
if (event.detail.exercises.length >= event.detail.set!) {
|
||||
if (this.isAllDetailsSameExerciseFinished(event.detail)) {
|
||||
event.detail.state = ExercisePlanDetailState.finished;
|
||||
} else if (event.detail.exercises.length >= 0) {
|
||||
event.detail.state = ExercisePlanDetailState.inProgress;
|
||||
}
|
||||
// recalculate the weight to the original planned repeats for the next details
|
||||
|
||||
if (exercise.unitQuantity != null && exercise.unitQuantity! > 0) {
|
||||
for (var nextDetail in _myPlan!.details) {
|
||||
double weightFromPlan = trainingPlanRepository.getOriginalWeight(this.getMyPlan()!.trainingPlanId!, nextDetail);
|
||||
@@ -357,6 +355,23 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
return workoutTree.imageName;
|
||||
}
|
||||
|
||||
int getStep(CustomerTrainingPlanDetails detail) {
|
||||
List<CustomerTrainingPlanDetails> details = getAllDetailsSameExercise(detail);
|
||||
int step = 0;
|
||||
int indexElement = 0;
|
||||
details.forEach((element) {
|
||||
if (indexElement == 0) {
|
||||
step = element.exercises.length;
|
||||
} else {
|
||||
step += element.exercises.length;
|
||||
}
|
||||
indexElement++;
|
||||
});
|
||||
|
||||
//print("STEP: $step ");
|
||||
return step;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails? getNext() {
|
||||
if (_myPlan == null || _myPlan!.details.isEmpty) {
|
||||
return null;
|
||||
@@ -373,12 +388,16 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
break;
|
||||
} else {
|
||||
final int step = detail.exercises.length;
|
||||
if (step < minStep && !detail.state.equalsTo(ExercisePlanDetailState.skipped) && day == detail.day) {
|
||||
if (step < minStep &&
|
||||
step < detail.set! &&
|
||||
!isAllDetailsSameExerciseFinished(detail) &&
|
||||
!detail.state.equalsTo(ExercisePlanDetailState.skipped) &&
|
||||
day == detail.day) {
|
||||
next = detail;
|
||||
minStep = step;
|
||||
if (detail.parallel != true) {
|
||||
break;
|
||||
}
|
||||
//if (detail.parallel != true) {
|
||||
break;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -423,18 +442,23 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
int indexInProgress = 0;
|
||||
int indexInStart = 0;
|
||||
final String day = dayNames[this.activeDayIndex];
|
||||
CustomerTrainingPlanDetails? prev;
|
||||
for (var detail in _myPlan!.days[day]!) {
|
||||
if (detail.state == ExercisePlanDetailState.inProgress) {
|
||||
//print("Offset detail $detail");
|
||||
if (detail.state == ExercisePlanDetailState.inProgress || detail.state == ExercisePlanDetailState.start) {
|
||||
prev = detail;
|
||||
break;
|
||||
}
|
||||
if (detail.state == ExercisePlanDetailState.start) {
|
||||
break;
|
||||
|
||||
if (prev != null && prev.exerciseTypeId != detail.exerciseTypeId && detail.state != ExercisePlanDetailState.extra) {
|
||||
//print(" --- offset + 1");
|
||||
indexInStart++;
|
||||
indexInProgress++;
|
||||
}
|
||||
indexInStart++;
|
||||
indexInProgress++;
|
||||
prev = detail;
|
||||
}
|
||||
int index = indexInStart > indexInProgress ? indexInStart : indexInProgress;
|
||||
offset = index * 80;
|
||||
offset = (index) * 270;
|
||||
print("Offset: $offset day: $day ($indexInStart, $indexInProgress)");
|
||||
return offset;
|
||||
}
|
||||
@@ -573,4 +597,23 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
List<CustomerTrainingPlanDetails> getAllDetailsSameExercise(CustomerTrainingPlanDetails detail) {
|
||||
List<CustomerTrainingPlanDetails> list = [];
|
||||
getMyPlan()!.details.forEach((element) {
|
||||
if (detail.exerciseTypeId == element.exerciseTypeId) {
|
||||
list.add(element);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
bool isAllDetailsSameExerciseFinished(CustomerTrainingPlanDetails detail) {
|
||||
bool allFinished = true;
|
||||
List<CustomerTrainingPlanDetails> list = getAllDetailsSameExercise(detail);
|
||||
for (var listDetail in list) {
|
||||
allFinished = allFinished && listDetail.exercises.length >= listDetail.set!;
|
||||
}
|
||||
return allFinished;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user