WT1.1.18+2 Training Plan days, skip
This commit is contained in:
@@ -238,10 +238,15 @@ class Cache with Logging {
|
||||
if (savedTrainingPlanJson == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, dynamic> map = JsonDecoder().convert(savedTrainingPlanJson);
|
||||
print("Training plan: $savedTrainingPlanJson");
|
||||
this.myTrainingPlan = CustomerTrainingPlan.fromJsonWithDetails(map);
|
||||
//String jsonPlan = savedTrainingPlanJson.replaceAllMapped(RegExp(r'[a-zA-Z]+\:'), (Match m) => "\"${m[0]}\"");
|
||||
Map<String, dynamic> map;
|
||||
try {
|
||||
map = JsonDecoder().convert(savedTrainingPlanJson);
|
||||
print("Training plan: $savedTrainingPlanJson");
|
||||
this.myTrainingPlan = CustomerTrainingPlan.fromJsonWithDetails(map);
|
||||
} on Exception catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteActiveExercisePlan() async {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
@@ -17,6 +18,8 @@ class CustomerTrainingPlan {
|
||||
|
||||
List<CustomerTrainingPlanDetails> details = [];
|
||||
|
||||
HashMap<String, List<CustomerTrainingPlanDetails>> days = HashMap();
|
||||
|
||||
CustomerTrainingPlan.fromJson(Map json) {
|
||||
this.customerTrainingPlanId = json['customerTrainingPlanId'];
|
||||
this.customerId = json['customerId'];
|
||||
@@ -38,12 +41,17 @@ class CustomerTrainingPlan {
|
||||
|
||||
try {
|
||||
final String details = json['details'];
|
||||
String jsonDetails = details.replaceAllMapped(
|
||||
RegExp(r'([a-zA-Z]+|[0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})'), (Match m) => "\"${m[0]}\"");
|
||||
String jsonDetails = details.replaceAllMapped(RegExp(r'([a-zA-Z]+)\:'), (Match m) => "\"${m[1]}\":");
|
||||
jsonDetails = jsonDetails.replaceAllMapped(RegExp(r'\: ([a-zA-Z /]+)'), (Match m) => ":\"${m[1]}\"");
|
||||
|
||||
jsonDetails = jsonDetails.replaceAll(r'\"null\"', 'null');
|
||||
jsonDetails = jsonDetails.replaceAll(r'\"false\"', 'false');
|
||||
jsonDetails = jsonDetails.replaceAll(r'\"true\"', 'true');
|
||||
jsonDetails =
|
||||
jsonDetails.replaceAllMapped(RegExp(r'([0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})'), (Match m) => "\"${m[0]}\"");
|
||||
|
||||
// jsonDetails = jsonDetails.replaceAll(r'\"null\"', 'null');
|
||||
// jsonDetails = jsonDetails.replaceAll(r'\"false\"', 'false');
|
||||
// jsonDetails = jsonDetails.replaceAll(r'\"true\"', 'true');
|
||||
|
||||
print("detail: $jsonDetails");
|
||||
|
||||
Iterable iterable = jsonDecode(jsonDetails);
|
||||
this.details = iterable.map((detail) => CustomerTrainingPlanDetails.fromJsonWithExerciseList(detail)).toList();
|
||||
@@ -66,7 +74,7 @@ class CustomerTrainingPlan {
|
||||
"customerTrainingPlanId": this.customerTrainingPlanId,
|
||||
"customerId": this.customerId,
|
||||
"trainingPlanId": this.trainingPlanId,
|
||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
|
||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!).toString(),
|
||||
"name": this.name,
|
||||
"active": this.active,
|
||||
"status": this.status,
|
||||
|
||||
@@ -51,7 +51,7 @@ class CustomerTrainingPlanDetails {
|
||||
: json['customerTrainingPlanDetailsId'];
|
||||
this.exerciseTypeId = json['exerciseTypeId'];
|
||||
this.set = json['set'];
|
||||
this.repeats = json['repeats'];
|
||||
this.repeats = json['repeats'] == "null" ? -1 : json['repeats'];
|
||||
this.weight = json['weight'];
|
||||
this.restingTime = json['restingTime'];
|
||||
this.parallel = json['parallel'] == "false"
|
||||
@@ -59,7 +59,10 @@ class CustomerTrainingPlanDetails {
|
||||
: json['parallel'] == "true"
|
||||
? true
|
||||
: null;
|
||||
this.day = json['day'];
|
||||
this.day = json['day'].toString();
|
||||
if (this.day == null || this.day == "null") {
|
||||
this.day = "";
|
||||
}
|
||||
try {
|
||||
Iterable iterable = json['exercises'];
|
||||
this.exercises = iterable.map((exercise) => Exercise.fromJson(exercise)).toList();
|
||||
@@ -67,13 +70,16 @@ class CustomerTrainingPlanDetails {
|
||||
print("JsonDecode error " + e.toString());
|
||||
}
|
||||
|
||||
if (exercises.length >= this.set!) {
|
||||
if (json['state'] == ExercisePlanDetailState.finished.toStr()) {
|
||||
this.state = ExercisePlanDetailState.finished;
|
||||
} else if (exercises.length > 0) {
|
||||
} else if (json['state'] == ExercisePlanDetailState.inProgress.toStr()) {
|
||||
this.state = ExercisePlanDetailState.inProgress;
|
||||
} else if (json['state'] == ExercisePlanDetailState.skipped.toStr()) {
|
||||
this.state = ExercisePlanDetailState.skipped;
|
||||
} else {
|
||||
this.state = ExercisePlanDetailState.start;
|
||||
}
|
||||
|
||||
this.exerciseType = Cache().getExerciseTypeById(exerciseTypeId!);
|
||||
}
|
||||
|
||||
@@ -92,7 +98,7 @@ class CustomerTrainingPlanDetails {
|
||||
|
||||
Map<String, dynamic> toJsonWithExercises() {
|
||||
final Map<String, dynamic> jsonMap = {
|
||||
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
|
||||
//"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
|
||||
"exerciseTypeId": this.exerciseTypeId,
|
||||
"set": this.set,
|
||||
"repeats": this.repeats,
|
||||
@@ -100,6 +106,7 @@ class CustomerTrainingPlanDetails {
|
||||
"restingTime": this.restingTime,
|
||||
"parallel": this.parallel,
|
||||
'exercises': exercises.isEmpty ? [].toString() : exercises.map((exercise) => exercise.toJson()).toList().toString(),
|
||||
'state': this.state.toStr(),
|
||||
};
|
||||
if (this.day != null && this.day!.isNotEmpty) {
|
||||
jsonMap["day"] = this.day;
|
||||
@@ -110,5 +117,5 @@ class CustomerTrainingPlanDetails {
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => this.toJson().toString();
|
||||
String toString() => this.toJsonWithExercises().toString();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
enum ExerciseAbility { oneRepMax, endurance, running, mini_test_set, paralell_test, none }
|
||||
enum ExerciseAbility { oneRepMax, endurance, running, mini_test_set, paralell_test, training, none }
|
||||
|
||||
extension ExerciseAbilityExt on ExerciseAbility {
|
||||
String enumToString() => this.toString().split(".").last;
|
||||
@@ -16,6 +16,8 @@ extension ExerciseAbilityExt on ExerciseAbility {
|
||||
return "Compact Test";
|
||||
case ExerciseAbility.paralell_test:
|
||||
return "Custom Test";
|
||||
case ExerciseAbility.training:
|
||||
return "Training";
|
||||
default:
|
||||
return "Compact Test";
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@ import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
|
||||
enum ExercisePlanDetailState { start, inProgress, finished }
|
||||
enum ExercisePlanDetailState { start, inProgress, skipped, finished }
|
||||
|
||||
extension ExericisePlanDetailStateExt on ExercisePlanDetailState {
|
||||
bool equalsTo(ExercisePlanDetailState state) => this.toString() == state.toString();
|
||||
bool equalsStringTo(String state) => this.toString() == state;
|
||||
String toStr() => this.toString().split(".").last;
|
||||
}
|
||||
|
||||
class ExercisePlanDetail {
|
||||
|
||||
@@ -40,9 +40,26 @@ class WorkoutMenuTree {
|
||||
late String parentName;
|
||||
late String parentNameEnglish;
|
||||
late int sort;
|
||||
late String internalName;
|
||||
|
||||
WorkoutMenuTree(this.id, this.parent, this.name, this.imageName, this.color, this.fontSize, this.child, this.exerciseTypeId,
|
||||
this.exerciseType, this.base, this.is1RM, this.isRunning, this.nameEnglish, this.parentName, this.parentNameEnglish, this.sort);
|
||||
WorkoutMenuTree(
|
||||
this.id,
|
||||
this.parent,
|
||||
this.name,
|
||||
this.imageName,
|
||||
this.color,
|
||||
this.fontSize,
|
||||
this.child,
|
||||
this.exerciseTypeId,
|
||||
this.exerciseType,
|
||||
this.base,
|
||||
this.is1RM,
|
||||
this.isRunning,
|
||||
this.nameEnglish,
|
||||
this.parentName,
|
||||
this.parentNameEnglish,
|
||||
this.sort,
|
||||
this.internalName);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user