WT 1.1.8+1 TrainingPlan

This commit is contained in:
bossanyit
2021-05-28 15:49:58 +02:00
parent 4b6b4dafc7
commit d388228caa
50 changed files with 2610 additions and 265 deletions
+43
View File
@@ -2,6 +2,7 @@ import 'dart:collection';
import 'dart:convert';
import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/customer_activity.dart';
import 'package:aitrainer_app/model/customer_training_plan.dart';
import 'package:aitrainer_app/model/description.dart';
import 'package:aitrainer_app/model/evaluation.dart';
import 'package:aitrainer_app/model/exercise_plan.dart';
@@ -17,6 +18,7 @@ import 'package:aitrainer_app/model/product_test.dart';
import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/model/purchase.dart';
import 'package:aitrainer_app/model/sport.dart';
import 'package:aitrainer_app/model/training_plan.dart';
import 'package:aitrainer_app/model/tutorial.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
@@ -104,6 +106,7 @@ class Cache with Logging {
static final String activeExercisePlanKey = "active_exercise_plan";
static final String activeExercisePlanDateKey = "active_exercise_plan_date";
static final String activeExercisePlanDetailsKey = "active_exercise_details_plan";
static final String myTrainingPlanKey = "myTrainingPlan";
static String baseUrlLive = 'https://aitrainer.info:8943/api/';
static String baseUrlTest = 'https://aitrainer.info:8843/api/';
@@ -137,14 +140,19 @@ class Cache with Logging {
List<ExercisePlanTemplate> _exercisePlanTemplates = [];
ExercisePlan? activeExercisePlan;
CustomerTrainingPlan? myTrainingPlan;
List<ExercisePlanDetail>? activeExercisePlanDetails;
List<ExerciseDevice>? _devices;
List<CustomerExerciseDevice>? _customerDevices;
List<CustomerActivity>? _customerActivities;
List<CustomerTrainingPlan>? _customerTrainingPlans;
List<Tutorial>? _tutorials;
List<Description>? _descriptions;
List<Faq>? _faqs;
List<TrainingPlan>? _trainingPlans;
LinkedHashMap<int, ExercisePlanDetail> _myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
@@ -209,6 +217,33 @@ class Cache with Logging {
sharedPreferences.setString(Cache.activeExercisePlanDateKey, savingDay);
}
Future<void> saveMyTrainingPlan() async {
if (myTrainingPlan == null) {
return;
}
String myTrainingPlanJson = JsonEncoder().convert(myTrainingPlan!.toJsonWithDetails());
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
sharedPreferences.setString(Cache.myTrainingPlanKey, myTrainingPlanJson);
}
Future<void> getMyTrainingPlan() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
final String? savedTrainingPlanJson = sharedPreferences.getString(Cache.myTrainingPlanKey);
if (savedTrainingPlanJson == null) {
return;
}
final Map<String, dynamic> map = JsonDecoder().convert(savedTrainingPlanJson);
print("Training plan: $savedTrainingPlanJson");
this.myTrainingPlan = CustomerTrainingPlan.fromJsonWithDetails(map);
}
Future<void> deleteActiveExercisePlan() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
@@ -644,6 +679,8 @@ class Cache with Logging {
await isActivityDonePrefs(activity);
});
await getMyTrainingPlan();
Cache().startPage = "home";
}
@@ -690,4 +727,10 @@ class Cache with Logging {
List<Faq>? getFaqs() => this._faqs;
setFaqs(List<Faq>? value) => this._faqs = value;
List<TrainingPlan>? getTrainingPlans() => this._trainingPlans;
setTrainingPlans(List<TrainingPlan>? value) => this._trainingPlans = value;
List<CustomerTrainingPlan>? getCustomerTrainingPlans() => this._customerTrainingPlans;
setCustomerTrainingPlans(value) => this._customerTrainingPlans = value;
}
+78
View File
@@ -0,0 +1,78 @@
import 'dart:convert';
import 'package:intl/intl.dart';
import 'package:aitrainer_app/model/customer_training_plan_details.dart';
class CustomerTrainingPlan {
int? customerTrainingPlanId;
int? customerId;
int? trainingPlanId;
DateTime? dateAdd;
bool? active;
String? status;
String? name;
CustomerTrainingPlan();
List<CustomerTrainingPlanDetails> details = [];
CustomerTrainingPlan.fromJson(Map json) {
this.customerTrainingPlanId = json['customerTrainingPlanId'];
this.customerId = json['customerId'];
this.trainingPlanId = json['trainingPlanId'];
this.dateAdd = DateTime.parse(json['dateAdd']);
this.active = json['active'];
this.status = json['status'];
this.name = json['name'];
}
CustomerTrainingPlan.fromJsonWithDetails(Map json) {
this.customerTrainingPlanId = json['customerTrainingPlanId'];
this.customerId = json['customerId'];
this.trainingPlanId = json['trainingPlanId'];
this.dateAdd = json['dateAdd'] != null ? DateTime.parse(json['dateAdd']) : DateTime.now();
this.active = json['active'];
this.status = json['status'];
this.name = json['name'];
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]}\"");
jsonDetails = jsonDetails.replaceAll(r'\"null\"', 'null');
jsonDetails = jsonDetails.replaceAll(r'\"false\"', 'false');
jsonDetails = jsonDetails.replaceAll(r'\"true\"', 'true');
Iterable iterable = jsonDecode(jsonDetails);
this.details = iterable.map((detail) => CustomerTrainingPlanDetails.fromJsonWithExerciseList(detail)).toList();
} on Exception catch (e) {
print("JsonDecode error " + e.toString());
}
}
Map<String, dynamic> toJson() => {
"customerTrainingPlanId": this.customerTrainingPlanId,
"customerId": this.customerId,
"trainingPlanId": this.trainingPlanId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"name": this.name,
"active": this.active,
"status": this.status
};
Map<String, dynamic> toJsonWithDetails() => {
"customerTrainingPlanId": this.customerTrainingPlanId,
"customerId": this.customerId,
"trainingPlanId": this.trainingPlanId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"name": this.name,
"active": this.active,
"status": this.status,
'details': details.isEmpty ? [].toString() : details.map((detail) => detail.toJsonWithExercises()).toList().toString(),
};
@override
String toString() => this.toJson().toString();
}
@@ -0,0 +1,114 @@
import 'dart:convert';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/exercise_type.dart';
class CustomerTrainingPlanDetails {
/// customerTrainingPlanDetails
int? customerTrainingPlanDetailsId;
/// exerciseTypeId
int? exerciseTypeId;
/// set
int? set;
/// repeats
int? repeats;
/// weight
double? weight;
int? restingTime;
bool? parallel;
String? day;
/// exerciseType
ExerciseType? exerciseType;
ExercisePlanDetailState state = ExercisePlanDetailState.start;
List<Exercise> exercises = [];
CustomerTrainingPlanDetails();
CustomerTrainingPlanDetails.fromJson(Map json) {
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.set = json['set'];
this.repeats = json['repeats'];
this.weight = json['weight'];
this.restingTime = json['restingTime'];
this.parallel = json['parallel'];
this.day = json['day'];
}
CustomerTrainingPlanDetails.fromJsonWithExerciseList(Map json) {
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'] == "null" || json['customerTrainingPlanDetailsId'] == null
? 0
: json['customerTrainingPlanDetailsId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.set = json['set'];
this.repeats = json['repeats'];
this.weight = json['weight'];
this.restingTime = json['restingTime'];
this.parallel = json['parallel'] == "false"
? false
: json['parallel'] == "true"
? true
: null;
this.day = json['day'];
try {
Iterable iterable = json['exercises'];
this.exercises = iterable.map((exercise) => Exercise.fromJson(exercise)).toList();
} on Exception catch (e) {
print("JsonDecode error " + e.toString());
}
if (exercises.length >= this.set!) {
this.state = ExercisePlanDetailState.finished;
} else if (exercises.length > 0) {
this.state = ExercisePlanDetailState.inProgress;
} else {
this.state = ExercisePlanDetailState.start;
}
this.exerciseType = Cache().getExerciseTypeById(exerciseTypeId!);
}
ExerciseType? getExerciseType() => exerciseType;
Map<String, dynamic> toJson() => {
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
"exerciseTypeId": this.exerciseTypeId,
"set": this.set,
"repeats": this.repeats,
"weight": this.weight,
"restingTime": this.restingTime,
"parallel": this.parallel,
"day": this.day == null ? '1.' : this.day,
};
Map<String, dynamic> toJsonWithExercises() {
final Map<String, dynamic> jsonMap = {
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
"exerciseTypeId": this.exerciseTypeId,
"set": this.set,
"repeats": this.repeats,
"weight": this.weight,
"restingTime": this.restingTime,
"parallel": this.parallel,
'exercises': exercises.isEmpty ? [].toString() : exercises.map((exercise) => exercise.toJson()).toList().toString(),
};
if (this.day != null && this.day!.isNotEmpty) {
jsonMap["day"] = this.day;
}
//print("Detail $jsonMap");
return jsonMap;
}
@override
String toString() => this.toJson().toString();
}
@@ -0,0 +1,30 @@
class CustomerTrainingPlanExercise {
int? customerTrainingPlanExerciseId;
int? customerTrainingPlanDetailsId;
int? customerId;
int? exerciseId;
double? weight;
int? repeats;
CustomerTrainingPlanExercise();
CustomerTrainingPlanExercise.fromJson(Map json) {
this.customerTrainingPlanExerciseId = json['customerTrainingPlanExerciseId'];
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'];
this.customerId = json['customerId'];
this.exerciseId = json['exerciseId'];
this.repeats = json['repeats'];
this.weight = json['weight'];
}
Map<String, dynamic> toJson() => {
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
"customerId": this.customerId,
"exerciseId": this.exerciseId,
"weight": this.weight,
"repeats": this.repeats
};
@override
String toString() => this.toJson().toString();
}
+4
View File
@@ -9,6 +9,7 @@ class Exercise {
double? unitQuantity;
DateTime? dateAdd;
int? exercisePlanDetailId;
int? trainingPlanDetailsId;
String? datePart;
double? calculated;
@@ -26,6 +27,8 @@ class Exercise {
this.dateAdd = DateTime.parse(json['dateAdd']);
this.datePart = DateFormat('yyyy-MM-dd').format(this.dateAdd!);
this.calculated = quantity;
this.exercisePlanDetailId = json['exercisePlanDetailId'] == "null" ? null : json['exercisePlanDetailId'];
this.trainingPlanDetailsId = json['trainingPlanDetailsId'] == "null" ? null : json['trainingPlanDetailsId'];
}
Map<String, dynamic> toJson() => {
@@ -36,6 +39,7 @@ class Exercise {
"unitQuantity": unitQuantity,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"exercisePlanDetailId": exercisePlanDetailId,
"trainingPlanDetailsId": trainingPlanDetailsId,
};
Map<String, dynamic> toJsonDatePart() => {
+16 -1
View File
@@ -18,7 +18,12 @@ class ExerciseTree {
late String nameTranslation;
/// sort
late int? sort;
int? sort;
String? internalName;
String? description;
String? descriptionTranslation;
ExerciseTree();
@@ -29,7 +34,12 @@ class ExerciseTree {
this.imageUrl = json['imageUrl'];
this.active = json['active'];
this.nameTranslation = json['translations'] != null && (json['translations']).length > 0 ? json['translations'][0]['name'] : this.name;
this.descriptionTranslation =
json['translations'] != null && (json['translations']).length > 0 && json['translations'][0]['description'] != null
? json['translations'][0]['description']
: this.description;
this.sort = 99;
this.internalName = json['internalName'];
}
Map<String, dynamic> toJson() {
@@ -37,13 +47,18 @@ class ExerciseTree {
"treeId": treeId,
"parentId": parentId,
"name": name,
"description": description,
"imageUrl": imageUrl,
"active": active.toString(),
"nameTranslation": nameTranslation,
"descriptionTranslation": descriptionTranslation,
"sort": sort,
};
}
@override
String toString() => this.toJson().toString();
ExerciseTree copy(int parentId) {
ExerciseTree newTree = ExerciseTree();
newTree.treeId = this.treeId;
+71
View File
@@ -0,0 +1,71 @@
import 'dart:collection';
import 'package:aitrainer_app/model/training_plan_detail.dart';
class TrainingPlan {
late int trainingPlanId;
late String type;
late String name;
late String internalName;
late String description;
late bool free;
int? treeId;
HashMap<String, String> nameTranslations = HashMap();
HashMap<String, String> descriptionTranslations = HashMap();
List<TrainingPlanDetail>? details;
TrainingPlan.fromJson(Map<String, dynamic> json) {
this.trainingPlanId = json['trainingPlanId'];
this.name = json['name'];
this.type = json['type'];
this.internalName = json['internalName'];
this.description = json['description'];
this.free = json['free'];
this.treeId = json['treeId'];
nameTranslations['en'] = name;
descriptionTranslations['en'] = description;
if (json['translations'] != null && json['translations'].length > 0) {
json['translations'].forEach((translation) {
nameTranslations[translation['languageCode']] = translation['nameTranslation'];
descriptionTranslations[translation['languageCode']] = translation['descriptionTranslation'];
});
}
if (json['details'] != null && json['details'].length > 0) {
details = json['details'].map<TrainingPlanDetail>((detail) => TrainingPlanDetail.fromJson(detail)).toList();
if (details != null && details!.isNotEmpty) {
details!.sort((a, b) {
if (a.sort == 0 || b.sort == 0) {
if (a.trainingPlanDetailId <= b.trainingPlanDetailId) {
return -1;
} else {
return 1;
}
}
if (a.sort <= b.sort) {
return -1;
} else {
return 1;
}
});
}
}
}
Map<String, dynamic> toJson() => {
"trainingPlanId": this.trainingPlanId,
"treeId": this.treeId,
"name": this.name,
"type": this.type,
"internalName": this.internalName,
"free": this.free,
"description": this.description,
"nameTranslation": this.nameTranslations.toString(),
};
@override
String toString() => this.toJson().toString();
}
+40
View File
@@ -0,0 +1,40 @@
class TrainingPlanDetail {
late int trainingPlanDetailId;
late int trainingPlanId;
late int exerciseTypeId;
late int sort;
late int set;
late int repeats;
late double weight;
late int restingTime;
late bool parallel;
late String day;
TrainingPlanDetail.fromJson(Map<String, dynamic> json) {
this.trainingPlanDetailId = json['trainingPlanDetailId'];
this.trainingPlanId = json['trainingPlanId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.sort = json['sort'];
this.set = json['set'];
this.repeats = json['repeats'];
this.weight = json['weight'];
this.restingTime = json['restingTime'];
this.parallel = json['parallel'];
this.day = json['day'];
}
Map<String, dynamic> toJson() => {
"trainingPlanDetailId": this.trainingPlanDetailId,
"trainingPlanId": this.trainingPlanId,
"exerciseType": this.exerciseTypeId,
"sort": this.sort,
"repeats": this.repeats,
"weight": this.weight,
"restingTime": this.restingTime,
"parallel": this.parallel,
"day": this.day,
};
@override
String toString() => this.toJson().toString();
}