WT1.1.10+1 Compact Test Edit

This commit is contained in:
bossanyit
2021-03-09 15:49:15 +01:00
parent 9c84714822
commit 2e0d7fc37d
26 changed files with 656 additions and 40 deletions
+45 -5
View File
@@ -1,7 +1,9 @@
import 'dart:collection';
import 'dart:convert';
import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/exercise_plan_template.dart';
import 'package:aitrainer_app/model/exercise_tree.dart';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/model/model_change.dart';
@@ -63,6 +65,8 @@ class Cache with Logging {
static final String hardwareKey = 'hardware';
static final String loginTypeKey = 'login_type';
static final String timerDisplayKey = 'timer_display';
static final String activeExercisePlanKey = 'active_exercise_plan';
static final String activeExercisePlanDetailsKey = 'active_exercise_details_plan';
static String baseUrl = 'http://aitrainer.info:8888/api/';
static final String mediaUrl = 'https://aitrainer.info:4343/media/';
@@ -89,6 +93,10 @@ class Cache with Logging {
List<wt_product.Product> _products;
List<Purchase> _purchases = List();
List<ProductTest> _productTests;
List<ExercisePlanTemplate> _exercisePlanTemplates = List();
ExercisePlan activeExercisePlan;
List<ExercisePlanDetail> activeExercisePlanDetails;
List<ExerciseDevice> _devices;
List<CustomerExerciseDevice> _customerDevices;
@@ -132,6 +140,38 @@ class Cache with Logging {
return this.authToken;
}
Future<void> saveActiveExercisePlan(ExercisePlan exercisePlan, List<ExercisePlanDetail> exercisePlanDetails) async {
this.activeExercisePlan = exercisePlan;
this.activeExercisePlanDetails = exercisePlanDetails;
String exercisePlanJson = JsonEncoder().convert(exercisePlan.toJson());
String detailsJson = jsonEncode(exercisePlanDetails);
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
sharedPreferences.setString(Cache.activeExercisePlanKey, exercisePlanJson);
sharedPreferences.setString(Cache.activeExercisePlanDetailsKey, detailsJson);
}
Future<void> getActiveExercisePlan() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
String exercisePlanJson = sharedPreferences.getString(Cache.activeExercisePlanKey);
if (exercisePlanJson != null) {
final Map<String, dynamic> map = JsonDecoder().convert(exercisePlanJson);
this.activeExercisePlan = ExercisePlan.fromJson(map);
}
String detailsJson = sharedPreferences.getString(Cache.activeExercisePlanDetailsKey);
if (detailsJson != null) {
Iterable json = jsonDecode(detailsJson);
this.activeExercisePlanDetails = json.map((details) => ExercisePlanDetail.fromJson(details)).toList();
}
}
Future<void> setServer(bool live) async {
if (this.testEnvironment == "1") {
liveServer = false;
@@ -146,7 +186,6 @@ class Cache with Logging {
void getHardware(SharedPreferences prefs) {
final bool hasHardware = prefs.getBool(Cache.hardwareKey);
//log("Has Hardware: " + hasHardware.toString());
this.hasHardware = hasHardware;
if (hasHardware == null) {
this.hasHardware = false;
@@ -301,9 +340,7 @@ class Cache with Logging {
this._exerciseTree = exerciseTree;
}
void setExercises(List<Exercise> exercises) {
this._exercises = exercises;
}
void setExercises(List<Exercise> exercises) => this._exercises = exercises;
void setExercisesTrainee(List<Exercise> exercises) {
this._exercisesTrainee = exercises;
@@ -485,10 +522,10 @@ class Cache with Logging {
Future<void> initCustomer(int customerId) async {
log(" *** initCustomer");
await PackageApi().getCustomerPackage(customerId);
Flurry.setUserId(customerId.toString());
await setLoginTypeFromPrefs();
await getActiveExercisePlan();
Cache().startPage = "home";
Track().track(TrackingEvent.enter);
}
@@ -498,4 +535,7 @@ class Cache with Logging {
LoginType getLoginType() => loginType;
void setLoginType(LoginType type) => this.loginType = type;
List get exercisePlanTemplates => this._exercisePlanTemplates;
setExercisePlanTemplates(value) => this._exercisePlanTemplates = value;
}
+1 -1
View File
@@ -1,4 +1,4 @@
enum ExerciseAbility { oneRepMax, endurance, running, none }
enum ExerciseAbility { oneRepMax, endurance, running, mini_test, none }
extension ExerciseAbilityExt on ExerciseAbility {
bool equalsTo(ExerciseAbility ability) => this.toString() == ability.toString();
+8
View File
@@ -8,6 +8,8 @@ class ExercisePlan {
bool private;
DateTime dateAdd;
DateTime dateUpd;
String type;
int exercisePlanTemplateId;
ExercisePlan(String name, int customerId) {
this.customerId = customerId;
@@ -23,6 +25,8 @@ class ExercisePlan {
this.description = json['description'];
this.dateAdd = json['dateAdd'] == null ? null : DateTime.parse(json['dateAdd']);
this.dateUpd = json['dateUpd'] == null ? null : DateTime.parse(json['dateUpd']);
this.type = json['type'];
this.exercisePlanTemplateId = json['exercisePlanTemplateId'];
}
Map<String, dynamic> toJson() {
@@ -40,6 +44,8 @@ class ExercisePlan {
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
"type": type,
"exercisePlanTemplateId": exercisePlanTemplateId
};
} else {
return {
@@ -50,6 +56,8 @@ class ExercisePlan {
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
"type": type,
"exercisePlanTemplateId": exercisePlanTemplateId
};
}
}
+37
View File
@@ -0,0 +1,37 @@
class ExercisePlanTemplate {
int exercisePlanTemplateId;
String name;
String description;
String templateType;
String nameTranslation;
String descriptionTranslation;
List<int> exerciseTypes = List();
ExercisePlanTemplate.fromJson(Map json) {
this.exercisePlanTemplateId = json['exercisePlanId'];
this.name = json['name'];
this.description = json['description'];
this.templateType = json['templateType'];
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'] : this.description;
if (json['details'] != null && (json['details']).length > 0) {
List details = json['details'];
details.forEach((element) {
exerciseTypes.add(element['exerciseTypeId']);
});
}
}
Map<String, dynamic> toJson() {
return {
"exercisePlanTemplateId": exercisePlanTemplateId,
"name": name,
"description": "description",
"templateType": templateType,
"nameTranslation": nameTranslation,
"descriptionTranslation": descriptionTranslation,
"exerciseTypes": exerciseTypes.toString()
};
}
}
+3
View File
@@ -5,6 +5,7 @@ class ExerciseTree {
String imageUrl;
bool active;
String nameTranslation;
int sort;
ExerciseTree();
@@ -25,6 +26,7 @@ class ExerciseTree {
"imageUrl": imageUrl,
"active": active.toString(),
"nameTranslation": nameTranslation,
"sort": sort,
};
}
@@ -38,6 +40,7 @@ class ExerciseTree {
newTree.parentId = parentId;
}
newTree.active = this.active;
newTree.sort = this.sort;
return newTree;
}
+2
View File
@@ -2,10 +2,12 @@ class ExerciseTreeParents {
int exerciseTreeParentsId;
int exerciseTreeParentId;
int exerciseTreeChildId;
int sort;
ExerciseTreeParents.fromJson(Map json) {
this.exerciseTreeParentsId = json['exerciseTreeParentsId'];
this.exerciseTreeParentId = json['exerciseTreeParentId'];
this.exerciseTreeChildId = json['exerciseTreeChildId'];
this.sort = json['sort'];
}
}
+9
View File
@@ -17,6 +17,7 @@ class ExerciseType {
String descriptionTranslation = "";
List<int> devices = List();
List<int> parents = List();
List<int> alternatives = List();
ExerciseAbility ability;
@@ -55,6 +56,14 @@ class ExerciseType {
this.parents.add(parent['exerciseTreeId']);
});
}
if (json['alternatives'].length > 0) {
final List jsonAlternatives = json['alternatives'];
jsonAlternatives.forEach((alternative) {
this.alternatives.add(alternative['exerciseTypeChildId']);
});
}
}
Map<String, dynamic> toJson() => {
+4 -1
View File
@@ -40,6 +40,7 @@ class WorkoutMenuTree {
String nameEnglish;
String parentName;
String parentNameEnglish;
int sort;
WorkoutMenuTree(
this.id,
@@ -57,7 +58,8 @@ class WorkoutMenuTree {
this.isRunning,
this.nameEnglish,
this.parentName,
this.parentNameEnglish);
this.parentNameEnglish,
this.sort);
Map<String, dynamic> toJson() {
return {
@@ -73,6 +75,7 @@ class WorkoutMenuTree {
"is1RM": is1RM.toString(),
"isEndurance": isEndurance.toString(),
"isRunning": isRunning.toString(),
"sort": sort,
};
}