WT 1.1.20 Training Plan improvements, InApp Messageing
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/training_plan.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
|
||||
class TrainingPlanDayRepository {
|
||||
const TrainingPlanDayRepository();
|
||||
|
||||
void assignTrainingPlanDays() {
|
||||
List<TrainingPlan>? plans = Cache().getTrainingPlans();
|
||||
if (plans == null) {
|
||||
return;
|
||||
}
|
||||
plans.forEach((plan) {
|
||||
if (plan.details != null) {
|
||||
plan.details!.forEach((element) {
|
||||
element.day = this.getNameById(element.dayId);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String? getNameById(int? dayId) {
|
||||
if (dayId == null) {
|
||||
return "";
|
||||
}
|
||||
String? name;
|
||||
for (var day in Cache().getTrainingPlanDays()) {
|
||||
if (day.dayId == dayId) {
|
||||
name = day.nameTranslations[AppLanguage().appLocal.languageCode];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/training_plan.dart';
|
||||
import 'package:aitrainer_app/repository/training_plan_day_repository.dart';
|
||||
import 'package:aitrainer_app/service/training_plan_service.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
|
||||
@@ -66,6 +67,7 @@ class TrainingPlanRepository {
|
||||
|
||||
// 3 calculate weights
|
||||
int index = 0;
|
||||
|
||||
trainingPlan.details!.forEach((elem) {
|
||||
CustomerTrainingPlanDetails detail = CustomerTrainingPlanDetails();
|
||||
detail.customerTrainingPlanDetailsId = ++index;
|
||||
@@ -73,7 +75,9 @@ class TrainingPlanRepository {
|
||||
detail.exerciseTypeId = elem.exerciseTypeId;
|
||||
detail.repeats = elem.repeats;
|
||||
detail.set = elem.set;
|
||||
detail.day = elem.day;
|
||||
detail.dayId = elem.dayId;
|
||||
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
|
||||
detail.day = trainingPlanDayRepository.getNameById(elem.dayId);
|
||||
detail.parallel = elem.parallel;
|
||||
detail.restingTime = elem.restingTime;
|
||||
detail.exerciseType = Cache().getExerciseTypeById(detail.exerciseTypeId!);
|
||||
@@ -83,6 +87,13 @@ class TrainingPlanRepository {
|
||||
} else {
|
||||
detail.weight = 0;
|
||||
}
|
||||
} else if (elem.weight == -2) {
|
||||
final CustomerTrainingPlanDetails calculated = this.isWeightCalculatedByExerciseType(elem.exerciseTypeId, detail, plan);
|
||||
if (calculated.weight != -1) {
|
||||
detail.weight = calculated.weight;
|
||||
} else {
|
||||
detail.weight = -2;
|
||||
}
|
||||
} else {
|
||||
detail.weight = elem.weight;
|
||||
}
|
||||
@@ -98,6 +109,19 @@ class TrainingPlanRepository {
|
||||
return plan;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails isWeightCalculatedByExerciseType(
|
||||
int exerciseTypeId, CustomerTrainingPlanDetails detail, CustomerTrainingPlan plan) {
|
||||
CustomerTrainingPlanDetails calculated = detail;
|
||||
for (var element in plan.details) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
calculated = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return calculated;
|
||||
}
|
||||
|
||||
TrainingPlan? getTrainingPlanById(int trainingPlanId) {
|
||||
TrainingPlan? plan;
|
||||
if (Cache().getTrainingPlans() == null) {
|
||||
@@ -148,8 +172,9 @@ class TrainingPlanRepository {
|
||||
return detail;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails recalculateDetail(int trainingPlanId, CustomerTrainingPlanDetails detail) {
|
||||
CustomerTrainingPlanDetails recalculatedDetail = detail;
|
||||
CustomerTrainingPlanDetails recalculateDetail(
|
||||
int trainingPlanId, CustomerTrainingPlanDetails detail, CustomerTrainingPlanDetails nextDetail) {
|
||||
CustomerTrainingPlanDetails recalculatedDetail = nextDetail;
|
||||
|
||||
// 1. get original repeats
|
||||
|
||||
@@ -164,14 +189,14 @@ class TrainingPlanRepository {
|
||||
plan.details!.forEach((element) {
|
||||
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
||||
print("element $element");
|
||||
originalRepeats = element.repeats;
|
||||
originalRepeats = element.repeats ?? 0;
|
||||
}
|
||||
});
|
||||
|
||||
// 2 get recalculated repeats
|
||||
|
||||
recalculatedDetail.weight =
|
||||
Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
recalculatedDetail.weight = Common.roundWeight(recalculatedDetail.weight!);
|
||||
print("recalculated repeats for $originalRepeats: ${recalculatedDetail.weight}");
|
||||
recalculatedDetail.repeats = originalRepeats;
|
||||
|
||||
|
||||
@@ -112,10 +112,10 @@ class WorkoutTreeRepository with Logging {
|
||||
0,
|
||||
"");
|
||||
this.tree[exerciseType.name] = menuItem;
|
||||
if (isRunning || is1RM) {
|
||||
if (isRunning || is1RM || exerciseType.name == "Warming Up" || exerciseType.name == "Stretching") {
|
||||
menuAsExercise.add(menuItem);
|
||||
}
|
||||
//log("ExerciseType in Menu item ${exerciseType.toJson()} is1RM: $is1RM");
|
||||
//log("ExerciseType in Menu item ${exerciseType.toJson()}");
|
||||
});
|
||||
} else {
|
||||
//log("No Parents " + exerciseType.toJson().toString());
|
||||
|
||||
Reference in New Issue
Block a user