WT 1.1.22 reengineering: Training Plan execution, registration
This commit is contained in:
@@ -29,8 +29,8 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
weight = this.customerRepository.getWeight() == 0 ? 60 : this.customerRepository.getWeight();
|
||||
height = this.customerRepository.getHeight() == 0 ? 170 : this.customerRepository.getHeight();
|
||||
|
||||
selectedSport = customerRepository.getSport();
|
||||
print("selected: $selectedFitnessItem sport: $selectedSport " + customerRepository.customer!.fitnessLevel.toString());
|
||||
// selectedSport = customerRepository.getSport();
|
||||
//print("selected: $selectedFitnessItem sport: $selectedSport " + customerRepository.customer!.fitnessLevel.toString());
|
||||
}
|
||||
|
||||
Sport? selectedSport;
|
||||
@@ -41,6 +41,7 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
CustomerChangeEvent event,
|
||||
) async* {
|
||||
try {
|
||||
print("Event: $event");
|
||||
if (event is CustomerLoad) {
|
||||
yield CustomerChangeLoading();
|
||||
yield CustomerDataChanged();
|
||||
@@ -63,7 +64,7 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
year = event.year;
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerWeightChange) {
|
||||
yield CustomerChangeLoading();
|
||||
//yield CustomerChangeLoading();
|
||||
customerRepository.setWeight(event.weight);
|
||||
weight = event.weight.toDouble();
|
||||
yield CustomerDataChanged();
|
||||
@@ -88,12 +89,43 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
customerRepository.setName(event.name);
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerGenderChange) {
|
||||
yield CustomerChangeLoading();
|
||||
customerRepository.setSex(event.gender == 0 ? "m" : "w");
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerSportChange) {
|
||||
yield CustomerChangeLoading();
|
||||
selectedSport = event.sport;
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerSaveFitness) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.fitnessLevel == null) {
|
||||
throw Exception("Please select your fitness level");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveGoal) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.goal == null) {
|
||||
throw Exception("Please select your goal");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveSex) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.sex == null) {
|
||||
throw Exception("Please select your biologial gender");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveWeight) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.getProperty("Weight") == null) {
|
||||
throw Exception("Please select your weight");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveHeight) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.getProperty("Height") == null) {
|
||||
throw Exception("Please select your height");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSave) {
|
||||
yield CustomerSaving();
|
||||
if (validation()) {
|
||||
|
||||
@@ -114,3 +114,23 @@ class CustomerLoad extends CustomerChangeEvent {
|
||||
class CustomerSave extends CustomerChangeEvent {
|
||||
const CustomerSave();
|
||||
}
|
||||
|
||||
class CustomerSaveGoal extends CustomerChangeEvent {
|
||||
const CustomerSaveGoal();
|
||||
}
|
||||
|
||||
class CustomerSaveFitness extends CustomerChangeEvent {
|
||||
const CustomerSaveFitness();
|
||||
}
|
||||
|
||||
class CustomerSaveSex extends CustomerChangeEvent {
|
||||
const CustomerSaveSex();
|
||||
}
|
||||
|
||||
class CustomerSaveWeight extends CustomerChangeEvent {
|
||||
const CustomerSaveWeight();
|
||||
}
|
||||
|
||||
class CustomerSaveHeight extends CustomerChangeEvent {
|
||||
const CustomerSaveHeight();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_ability.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_device_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -111,6 +115,22 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
listFilterDevice.remove(deviceId);
|
||||
}
|
||||
yield MenuReady();
|
||||
} else if (event is MenuStartTrial) {
|
||||
yield MenuLoading();
|
||||
final DateTime start = event.start;
|
||||
CustomerRepository customerRepository = CustomerRepository();
|
||||
customerRepository.customer = Cache().userLoggedIn;
|
||||
customerRepository.customer!.trialDate = start;
|
||||
Cache().userLoggedIn!.trialDate = start;
|
||||
|
||||
customerRepository.saveCustomer();
|
||||
|
||||
if (DateTime.now().difference(start).inHours < 1) {
|
||||
Cache().hasPurchased = true;
|
||||
log("Trial mode on!");
|
||||
Track().track(TrackingEvent.trial, eventValue: DateFormat('yyyy-MM-dd HH:mm:ss').format(start));
|
||||
}
|
||||
yield MenuReady();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield MenuError(message: ex.toString());
|
||||
@@ -134,6 +154,9 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
case "my_body":
|
||||
ability = ExerciseAbility.none;
|
||||
break;
|
||||
case "training_execute":
|
||||
ability = ExerciseAbility.training_execute;
|
||||
break;
|
||||
}
|
||||
log("Ability: " + ability.toString() + " name: " + name);
|
||||
}
|
||||
|
||||
@@ -56,4 +56,15 @@ class MenuRecreateTree extends MenuEvent {
|
||||
class MenuFilterExerciseType extends MenuEvent {
|
||||
final int deviceId;
|
||||
const MenuFilterExerciseType({required this.deviceId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceId];
|
||||
}
|
||||
|
||||
class MenuStartTrial extends MenuEvent {
|
||||
final DateTime start;
|
||||
const MenuStartTrial({required this.start});
|
||||
|
||||
@override
|
||||
List<Object> get props => [start];
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ part 'session_state.dart';
|
||||
|
||||
class SessionBloc extends Bloc<SessionEvent, SessionState> with Logging {
|
||||
final Session session;
|
||||
StreamSubscription? _sub;
|
||||
|
||||
SessionBloc({required this.session}) : super(SessionInitial());
|
||||
|
||||
@@ -41,6 +42,7 @@ class SessionBloc extends Bloc<SessionEvent, SessionState> with Logging {
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await this.close();
|
||||
_sub?.cancel();
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,12 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
|
||||
trainingPlanBloc.getMyPlan()!.days[day]!.forEach((element) {
|
||||
//if (!element.state.equalsTo(ExercisePlanDetailState.extra)) {
|
||||
if (!findExerciseInEvaluationList(element.exerciseTypeId!)) {
|
||||
addEvaluationExercise(element);
|
||||
} else {
|
||||
//editEvaluationExercise(element);
|
||||
if (element.exerciseTypeId != null) {
|
||||
if (!findExerciseInEvaluationList(element.exerciseTypeId!)) {
|
||||
addEvaluationExercise(element);
|
||||
} else {
|
||||
//editEvaluationExercise(element);
|
||||
}
|
||||
}
|
||||
//}
|
||||
});
|
||||
@@ -93,7 +95,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
exercise.type = TrainingEvaluationExerciseType.weightBased;
|
||||
this.evaluationList.add(exercise);
|
||||
} else {
|
||||
if (detail.exerciseType!.unitQuantityUnit == null) {
|
||||
if (detail.exerciseType!.unitQuantityUnit == null || detail.weight == null) {
|
||||
exercise.type = TrainingEvaluationExerciseType.repeatBased;
|
||||
exercise.repeats = detail.repeats;
|
||||
exercise.maxRepeats = getMaxRepeatsByExerciseType(detail.exerciseTypeId!);
|
||||
|
||||
@@ -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