WT1.1.0+40 Premium feature settings
This commit is contained in:
@@ -45,8 +45,6 @@ class CustomerExerciseDeviceRepository {
|
||||
}
|
||||
|
||||
Future<void> removeDevice(ExerciseDevice device) async {
|
||||
print("Remove " + device.name);
|
||||
|
||||
CustomerExerciseDevice found;
|
||||
if (_devices != null) {
|
||||
this._devices.forEach((element) {
|
||||
|
||||
@@ -3,8 +3,14 @@ import 'dart:collection';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/customer_property.dart';
|
||||
import 'package:aitrainer_app/model/product_test.dart';
|
||||
import 'package:aitrainer_app/model/purchase.dart';
|
||||
import 'package:aitrainer_app/repository/property_repository.dart';
|
||||
import 'package:aitrainer_app/service/customer_service.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/product_test_service.dart';
|
||||
import 'package:aitrainer_app/service/purchase.dart';
|
||||
import 'package:aitrainer_app/util/not_found_exception.dart';
|
||||
|
||||
class GenderItem {
|
||||
GenderItem(this.dbValue, this.name);
|
||||
@@ -12,7 +18,7 @@ class GenderItem {
|
||||
String name;
|
||||
}
|
||||
|
||||
class CustomerRepository {
|
||||
class CustomerRepository with Logging {
|
||||
Customer customer;
|
||||
Customer _trainee;
|
||||
List<Customer> _trainees;
|
||||
@@ -244,4 +250,33 @@ class CustomerRepository {
|
||||
});
|
||||
return _trainee;
|
||||
}
|
||||
|
||||
Future<List<Purchase>> getPurchase() async {
|
||||
int customerId = Cache().userLoggedIn.customerId;
|
||||
List<Purchase> purchases = await PurchaseApi().getPurchasesByCustomer(customerId);
|
||||
return purchases;
|
||||
}
|
||||
|
||||
Future<void> addPurchase(Purchase purchase) async {
|
||||
await PurchaseApi().savePurchase(purchase);
|
||||
}
|
||||
|
||||
Future<List<ProductTest>> getProductTests() async {
|
||||
List<ProductTest> tests = List();
|
||||
try {
|
||||
int customerId = Cache().userLoggedIn.customerId;
|
||||
tests = await ProductTestApi().getProductTestByCustomer(customerId);
|
||||
} on NotFoundException catch (ex) {
|
||||
log("Product Tests not found");
|
||||
Cache().productTests = tests;
|
||||
} on Exception catch (ex) {
|
||||
log(ex.toString());
|
||||
Cache().productTests = tests;
|
||||
}
|
||||
return tests;
|
||||
}
|
||||
|
||||
Future<void> addProductTest(ProductTest productTest) async {
|
||||
await ProductTestApi().saveProductTest(productTest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,6 @@ class ExercisePlanRepository {
|
||||
|
||||
exercisePlan = await ExercisePlanApi().getLastExercisePlan(customerId);
|
||||
newPlan = (exercisePlan == null);
|
||||
print("New plan: " + newPlan.toString());
|
||||
Cache().setMyExercisePlan(exercisePlan);
|
||||
return exercisePlan;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/service/exercise_service.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
class ExerciseRepository {
|
||||
Exercise exercise;
|
||||
Customer customer;
|
||||
ExerciseType exerciseType;
|
||||
List<Exercise> exerciseList;
|
||||
List<Exercise> exerciseLogList = List();
|
||||
List<Exercise> actualExerciseList = List();
|
||||
|
||||
double rmWendler = 0;
|
||||
@@ -78,8 +81,11 @@ class ExerciseRepository {
|
||||
modelExercise.unitQuantity = null;
|
||||
}
|
||||
this.actualExerciseList.add(modelExercise);
|
||||
int index = this.actualExerciseList.length - 1;
|
||||
|
||||
Exercise savedExercise = await ExerciseApi().addExercise(modelExercise);
|
||||
|
||||
this.actualExerciseList[index].exerciseId = savedExercise.exerciseId;
|
||||
if (customer.customerId == Cache().userLoggedIn.customerId) {
|
||||
Cache().addExercise(savedExercise);
|
||||
} else if (Cache().getTrainee() != null && customer.customerId == Cache().getTrainee().customerId) {
|
||||
@@ -238,5 +244,44 @@ class ExerciseRepository {
|
||||
return actualExerciseType;
|
||||
}
|
||||
|
||||
void sortByDate() => exerciseList.sort((a, b) => b.dateAdd.compareTo(a.dateAdd));
|
||||
void sortByDate() {
|
||||
exerciseList.sort((a, b) => b.dateAdd.compareTo(a.dateAdd));
|
||||
|
||||
this.exerciseLogList = List();
|
||||
String summary = "";
|
||||
|
||||
String prevDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exerciseList[0].dateAdd);
|
||||
int prevExerciseTypeId = exerciseList[0].exerciseTypeId;
|
||||
Exercise prevExercise = exerciseList[0];
|
||||
int prevCount = 0;
|
||||
for (int i = 0; i < this.exerciseList.length; i++) {
|
||||
Exercise exercise = exerciseList[i];
|
||||
int exerciseTypeId = exercise.exerciseTypeId;
|
||||
String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd);
|
||||
//print(" -- $prevExerciseTypeId - $prevDate");
|
||||
if (!(exerciseTypeId == prevExerciseTypeId && prevDate == exerciseDate)) {
|
||||
ExerciseType exerciseType = Cache().getExercise(prevExercise.exerciseTypeId);
|
||||
String unit = exerciseType.unitQuantityUnit != null ? exerciseType.unitQuantityUnit : prevExercise.unit;
|
||||
prevExercise.summary = summary + " " + unit;
|
||||
exerciseLogList.add(prevExercise);
|
||||
//print("Log add " + exercise.toJson().toString());
|
||||
summary = "";
|
||||
prevCount = 0;
|
||||
}
|
||||
String delimiter = "";
|
||||
if (prevCount > 0) delimiter = ", ";
|
||||
summary += delimiter + exercise.quantity.toStringAsFixed(0);
|
||||
ExerciseType exerciseType = Cache().getExercise(exercise.exerciseTypeId);
|
||||
if (exerciseType.unitQuantity == "1") {
|
||||
summary += "x" + exercise.unitQuantity.toStringAsFixed(0);
|
||||
}
|
||||
//print(" --- sum " + exerciseType.name + " $summary");
|
||||
|
||||
prevExerciseTypeId = exerciseTypeId;
|
||||
prevDate = exerciseDate;
|
||||
prevExercise = exercise;
|
||||
prevCount++;
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_result.dart';
|
||||
import 'package:aitrainer_app/model/result.dart';
|
||||
import 'package:aitrainer_app/service/exercise_result_service.dart';
|
||||
|
||||
enum ResultType { running, man, woman, none }
|
||||
|
||||
@@ -37,4 +40,17 @@ class ExerciseResultRepository {
|
||||
}
|
||||
|
||||
List<ResultExt> getResults() => this._results;
|
||||
|
||||
Future<void> saveExerciseResults() async {
|
||||
this._results.forEach((result) async {
|
||||
ExerciseResult exerciseResult = ExerciseResult();
|
||||
exerciseResult.customerId = Cache().userLoggedIn.customerId;
|
||||
exerciseResult.exerciseId = result.exerciseId;
|
||||
exerciseResult.dateFrom = result.dateFrom;
|
||||
exerciseResult.dateTo = result.dateTo;
|
||||
exerciseResult.resultType = result.itemString;
|
||||
exerciseResult.value = result.data;
|
||||
await ExerciseResultApi().saveExerciseResult(exerciseResult);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Antagonist {
|
||||
@@ -29,7 +30,7 @@ class Antagonist {
|
||||
static int calfNr = 8;
|
||||
}
|
||||
|
||||
class WorkoutTreeRepository {
|
||||
class WorkoutTreeRepository with Logging {
|
||||
final LinkedHashMap tree = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
SplayTreeMap sortedTree = SplayTreeMap<String, List<WorkoutMenuTree>>();
|
||||
bool isEnglish;
|
||||
@@ -48,7 +49,7 @@ class WorkoutTreeRepository {
|
||||
|
||||
Future<void> createTree() async {
|
||||
isEnglish = AppLanguage().appLocal == Locale('en');
|
||||
print("** Start creating tree on lang: " + AppLanguage().appLocal.languageCode);
|
||||
log("** Start creating tree on lang: " + AppLanguage().appLocal.languageCode);
|
||||
|
||||
List<ExerciseTree> exerciseTree = Cache().getExerciseTree();
|
||||
if (exerciseTree == null || exerciseTree.length == 0) {
|
||||
@@ -61,7 +62,7 @@ class WorkoutTreeRepository {
|
||||
}
|
||||
|
||||
exerciseTree.forEach((treeItem) async {
|
||||
//print(" -- TreeItem " + treeItem.toJson().toString() + " active " + treeItem.active.toString());
|
||||
//log(" -- TreeItem " + treeItem.toJson().toString() + " active " + treeItem.active.toString());
|
||||
if (treeItem.active == true) {
|
||||
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + treeItem.imageUrl.substring(7);
|
||||
@@ -99,7 +100,7 @@ class WorkoutTreeRepository {
|
||||
);
|
||||
menuItem = this.setWorkoutTypes(menuItem, treeItem);
|
||||
this.tree[treeItem.name + "_" + treeItem.parentId.toString()] = menuItem;
|
||||
//print("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
//log("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -119,19 +120,19 @@ class WorkoutTreeRepository {
|
||||
WorkoutMenuTree menuItem = WorkoutMenuTree(exerciseType.exerciseTypeId, parentId, exerciseTypeName, assetImage, Colors.white,
|
||||
24, true, exerciseType.exerciseTypeId, exerciseType, exerciseType.base, is1RM, isEndurance, isRunning, exerciseType.name);
|
||||
this.tree[exerciseType.name] = menuItem;
|
||||
print("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
print("ExerciseType in Menu item " +
|
||||
//log("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
/* log("ExerciseType in Menu item " +
|
||||
exerciseType.toJson().toString() +
|
||||
" is1RM: " +
|
||||
is1RM.toString() +
|
||||
" isEndurance: " +
|
||||
isEndurance.toString());
|
||||
isEndurance.toString()); */
|
||||
});
|
||||
} else {
|
||||
//print("No Parents " + exerciseType.toJson().toString());
|
||||
//log("No Parents " + exerciseType.toJson().toString());
|
||||
}
|
||||
} else {
|
||||
//print("ExerciseType missing data: " + exerciseType.exerciseTypeId.toString());
|
||||
//log("ExerciseType missing data: " + exerciseType.exerciseTypeId.toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -166,7 +167,7 @@ class WorkoutTreeRepository {
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
if (treeItem.id == treeId) {
|
||||
isTreeItemRunning = isTreeItemRunning || treeItem.isRunning;
|
||||
//print (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
//log (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
}
|
||||
});
|
||||
|
||||
@@ -180,7 +181,7 @@ class WorkoutTreeRepository {
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
if (treeItem.id == treeId) {
|
||||
isTreeItem1RM = isTreeItem1RM || treeItem.is1RM;
|
||||
//print (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
//log (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
}
|
||||
});
|
||||
|
||||
@@ -194,7 +195,7 @@ class WorkoutTreeRepository {
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
if (treeItem.id == treeId) {
|
||||
isTreeItemEndurance = isTreeItemEndurance || treeItem.isEndurance;
|
||||
//print(treeItem.id.toString() + " " + treeItem.name + " Endurance? " + treeItem.isEndurance.toString());
|
||||
//log(treeItem.id.toString() + " " + treeItem.name + " Endurance? " + treeItem.isEndurance.toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -208,7 +209,7 @@ class WorkoutTreeRepository {
|
||||
WorkoutMenuTree workoutTree = value;
|
||||
isChild = isChild && workoutTree.child;
|
||||
});
|
||||
//print("Check child " + parentId.toString() + " child: " + isChild.toString());
|
||||
//log("Check child " + parentId.toString() + " child: " + isChild.toString());
|
||||
return isChild;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user