WT 1.1.20 Training Plan improvements, InApp Messageing

This commit is contained in:
bossanyit
2021-06-25 17:30:14 +02:00
parent a595ffb358
commit 211307e63e
36 changed files with 693 additions and 300 deletions
+8 -8
View File
@@ -87,9 +87,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
yield LoginSuccess();
} else if (event is RegistrationSubmit) {
yield LoginLoading();
if (!this.dataPolicyAllowed) {
/* if (!this.dataPolicyAllowed) {
throw Exception("Please accept our data policy");
}
} */
final String? validationError = validate();
if (validationError != null) {
yield LoginError(message: validationError);
@@ -104,9 +104,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
}
} else if (event is RegistrationFB) {
yield LoginLoading();
if (!this.dataPolicyAllowed) {
/* if (!this.dataPolicyAllowed) {
throw Exception("Please accept our data policy");
}
} */
Cache().setLoginType(LoginType.fb);
await userRepository.addUserFB();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
@@ -116,9 +116,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
yield LoginSuccess();
} else if (event is RegistrationGoogle) {
yield LoginLoading();
if (!this.dataPolicyAllowed) {
/* if (!this.dataPolicyAllowed) {
throw Exception("Please accept our data policy");
}
} */
Cache().setLoginType(LoginType.google);
await userRepository.addUserGoogle();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
@@ -128,9 +128,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
yield LoginSuccess();
} else if (event is RegistrationApple) {
yield LoginLoading();
if (!this.dataPolicyAllowed) {
/* if (!this.dataPolicyAllowed) {
throw Exception("Please accept our data policy");
}
} */
Cache().setLoginType(LoginType.apple);
await userRepository.addUserApple();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
+54 -17
View File
@@ -58,15 +58,16 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
await Cache().saveMyTrainingPlan();
yield TrainingPlanFinished();
} else if (event is TrainingPlanWeightChange) {
yield TrainingPlanLoading();
yield TrainingPlanExerciseLoading();
event.detail.weight = event.weight;
yield TrainingPlanExerciseReady();
yield TrainingPlanReady();
} else if (event is TrainingPlanRepeatsChange) {
yield TrainingPlanLoading();
yield TrainingPlanExerciseLoading();
event.detail.repeats = event.repeats;
yield TrainingPlanExerciseReady();
yield TrainingPlanReady();
} else if (event is TrainingPlanSetChange) {
yield TrainingPlanLoading();
@@ -91,10 +92,13 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
} else if (event.detail.exercises.length >= 0) {
event.detail.state = ExercisePlanDetailState.inProgress;
}
// recalculate the weight to the original planned repeats
if (event.detail.isTest && event.detail.exercises.length == 1) {
trainingPlanRepository.recalculateDetail(_myPlan!.trainingPlanId!, event.detail);
// 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) {
if (nextDetail.exerciseTypeId == event.detail.exerciseTypeId && nextDetail.weight == -2) {
trainingPlanRepository.recalculateDetail(_myPlan!.trainingPlanId!, event.detail, nextDetail);
}
}
}
exercise.trainingPlanDetailsId = _myPlan!.trainingPlanId;
@@ -230,28 +234,61 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
dayNames.clear();
_myPlan!.days.clear();
String dayName = ".";
String previousDay = ".";
_myPlan!.details.forEach((element) {
if (element.day != null && element.day != dayName) {
dayNames.add(element.day!);
dayName = element.day!;
if (previousDay != ".") {
this.addExtraExerciseType("Stretching", previousDay);
}
}
if (_myPlan!.days[dayName] == null) {
if (dayName == ".") {
dayName = "";
}
_myPlan!.days[dayName] = [];
this.addExtraExerciseType("Warming Up", dayName);
previousDay = dayName;
}
_myPlan!.days[dayName]!.add(element);
});
if (dayNames.length == 0) {
dayNames.add("");
_myPlan!.days[""] = [];
_myPlan!.days[""]!.addAll(_myPlan!.details);
dayName = "";
dayNames.add(dayName);
_myPlan!.days[dayName] = [];
_myPlan!.days[dayName]!.addAll(_myPlan!.details);
}
getActiveDayIndex();
}
void addExtraExerciseType(String name, String dayName) {
if (Cache().getExerciseTypes() == null) {
return;
}
for (var exerciseType in Cache().getExerciseTypes()!) {
if (exerciseType.name == name) {
CustomerTrainingPlanDetails detail = CustomerTrainingPlanDetails();
detail.customerTrainingPlanDetailsId = 0;
detail.trainingPlanDetailsId = 0;
detail.exerciseTypeId = exerciseType.exerciseTypeId;
detail.repeats = 1;
detail.set = 1;
detail.day = "";
detail.parallel = false;
detail.restingTime = 0;
detail.exerciseType = exerciseType;
if (_myPlan!.days[dayName] == null) {
_myPlan!.days[dayName] = [];
}
_myPlan!.days[dayName]!.add(detail);
break;
}
}
}
CustomerTrainingPlanDetails? getTrainingPlanDetail(int trainingPlanDetailsId) {
CustomerTrainingPlanDetails? detail;
if (_myPlan == null || _myPlan!.details.isEmpty) {
@@ -297,13 +334,14 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
int minStep = 99;
for (final detail in this._myPlan!.details) {
if (!detail.state.equalsTo(ExercisePlanDetailState.finished)) {
if (detail.exercises.isEmpty && !detail.state.equalsTo(ExercisePlanDetailState.skipped)) {
final day = dayNames[this.activeDayIndex];
if (detail.exercises.isEmpty && !detail.state.equalsTo(ExercisePlanDetailState.skipped) && day == detail.day) {
next = detail;
minStep = 1;
break;
} else {
final int step = detail.exercises.length;
if (step < minStep && !detail.state.equalsTo(ExercisePlanDetailState.skipped)) {
if (step < minStep && !detail.state.equalsTo(ExercisePlanDetailState.skipped) && day == detail.day) {
next = detail;
minStep = step;
if (detail.parallel != true) {
@@ -313,7 +351,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
}
}
}
print("Next detail $next");
//print("Next detail $next");
return next;
}
@@ -379,20 +417,19 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
}
int getActiveDayIndex() {
activeDayIndex = 0;
if (restarting) {
return 0;
}
if (_myPlan == null || _myPlan!.details.isEmpty) {
// throw Exception("No defined Training Plan");
return 0;
}
if (dayNames.isEmpty || dayNames.length == 1) {
activeDayIndex = 0;
return 0;
}
activeDayIndex = 0;
for (var day in dayNames) {
if (_myPlan!.days[day] == null) {
throw Exception("Wrong activated day: $day does not exist");
@@ -413,7 +450,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
activeDayIndex = 0;
this.add(TrainingPlanGoToRestart());
}
print("ActiveDayIndex $activeDayIndex");
return activeDayIndex;
}
@@ -15,10 +15,18 @@ class TrainingPlanLoading extends TrainingPlanState {
const TrainingPlanLoading();
}
class TrainingPlanExerciseLoading extends TrainingPlanState {
const TrainingPlanExerciseLoading();
}
class TrainingPlanReady extends TrainingPlanState {
const TrainingPlanReady();
}
class TrainingPlanExerciseReady extends TrainingPlanState {
const TrainingPlanExerciseReady();
}
class TrainingPlanFinished extends TrainingPlanState {
const TrainingPlanFinished();
}