wt1.1c auth->cache, control page, animation base exercise percent
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
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';
|
||||
@@ -7,6 +8,7 @@ class ExerciseRepository {
|
||||
Exercise exercise;
|
||||
Customer customer;
|
||||
ExerciseType exerciseType;
|
||||
List<Exercise> exerciseList;
|
||||
|
||||
double rmWendler = 0;
|
||||
double rmMcglothlin = 0;
|
||||
@@ -79,10 +81,51 @@ class ExerciseRepository {
|
||||
this.exerciseType = exerciseType;
|
||||
}
|
||||
|
||||
/*
|
||||
Future<List<ExerciseRepository>> getExercisesByCustomer( int customerId ) async {
|
||||
|
||||
Future<List<Exercise>> getExercisesByCustomer( int customerId ) async {
|
||||
final results = await ExerciseApi().getExercisesByCustomer(customerId);
|
||||
this.exerciseList = results.map((item) => ExerciseRepository(exercise: item)).toList();
|
||||
this.exerciseList = results;
|
||||
Cache().setExercises(exerciseList);
|
||||
return this.exerciseList;
|
||||
} */
|
||||
}
|
||||
|
||||
List<Exercise> getExerciseList() {
|
||||
if ( this.exerciseList == null || this.exerciseList.length == 0 ) {
|
||||
this.exerciseList = Cache().getExercises();
|
||||
}
|
||||
return this.exerciseList;
|
||||
}
|
||||
|
||||
double getBaseExerciseFinishedPercent() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void getLastExercise() {
|
||||
List<Exercise> exercises = this.getExerciseList();
|
||||
Exercise lastExercise = exercises[0];
|
||||
exercises.forEach((element) {
|
||||
Exercise actualExercise = element;
|
||||
if ( actualExercise.dateAdd.compareTo(lastExercise.dateAdd) > 0 ) {
|
||||
lastExercise = actualExercise;
|
||||
}
|
||||
});
|
||||
this.exercise = lastExercise;
|
||||
this.customer = Cache().userLoggedIn;
|
||||
this.exerciseType = getExerciseTypeById(exercise.exerciseTypeId);
|
||||
return;
|
||||
}
|
||||
|
||||
ExerciseType getExerciseTypeById(int exerciseTypeId) {
|
||||
ExerciseType actualExerciseType;
|
||||
Cache().getExerciseTypes().forEach((element) {
|
||||
ExerciseType exerciseType = element;
|
||||
if ( exerciseType.exerciseTypeId == exerciseTypeId) {
|
||||
actualExerciseType = exerciseType;
|
||||
}
|
||||
});
|
||||
if ( actualExerciseType == null ) {
|
||||
throw Exception("Data error, no ExerciseType for exerciseTypeId $exerciseTypeId" );
|
||||
}
|
||||
return actualExerciseType;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'dart:collection';
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/auth.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.dart';
|
||||
@@ -16,7 +16,7 @@ class MenuTreeRepository {
|
||||
final AppLanguage appLanguage = AppLanguage();
|
||||
bool isEnglish = appLanguage.appLocal == Locale('en');
|
||||
|
||||
List<ExerciseTree> exerciseTree = Auth().getExerciseTree();
|
||||
List<ExerciseTree> exerciseTree = Cache().getExerciseTree();
|
||||
if ( exerciseTree == null || exerciseTree.length == 0) {
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
}
|
||||
@@ -24,6 +24,10 @@ class MenuTreeRepository {
|
||||
exerciseTree.forEach( (treeItem) async {
|
||||
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + treeItem.imageUrl.substring(7);
|
||||
bool is1RM = treeItem.name == '1RM' ? true : false;
|
||||
if ( is1RM == false) {
|
||||
is1RM = false; //isParent1RM(treeItem.treeId);
|
||||
}
|
||||
this.tree[treeItem.name] = WorkoutTree(
|
||||
treeItem.treeId,
|
||||
treeItem.parentId,
|
||||
@@ -33,11 +37,12 @@ class MenuTreeRepository {
|
||||
false,
|
||||
0,
|
||||
null,
|
||||
false
|
||||
false,
|
||||
is1RM
|
||||
);
|
||||
});
|
||||
|
||||
List<ExerciseType> exerciseTypes = Auth().getExerciseTypes();
|
||||
List<ExerciseType> exerciseTypes = Cache().getExerciseTypes();
|
||||
if ( exerciseTypes == null || exerciseTypes.length == 0) {
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
}
|
||||
@@ -46,6 +51,7 @@ class MenuTreeRepository {
|
||||
String exerciseTypeName = isEnglish ?
|
||||
exerciseType.name : exerciseType.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + exerciseType.imageUrl.substring(7);
|
||||
bool is1RM = false; //this.isParent1RM(exerciseType.treeId);
|
||||
this.tree[exerciseType.name] = WorkoutTree(
|
||||
exerciseType.exerciseTypeId,
|
||||
exerciseType.treeId,
|
||||
@@ -56,11 +62,24 @@ class MenuTreeRepository {
|
||||
true,
|
||||
exerciseType.exerciseTypeId,
|
||||
exerciseType,
|
||||
exerciseType.base
|
||||
exerciseType.base,
|
||||
is1RM
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
bool isParent1RM(int treeId) {
|
||||
bool isTreeItem1RM = false;
|
||||
|
||||
for (int i = 0; i < this.tree.length; i++ ) {
|
||||
WorkoutTree treeItem = this.tree[i];
|
||||
if ( treeItem.id == treeId ) {
|
||||
isTreeItem1RM = treeItem.is1RM;
|
||||
break;
|
||||
}
|
||||
};
|
||||
return isTreeItem1RM;
|
||||
}
|
||||
|
||||
LinkedHashMap getBranch(int parent) {
|
||||
LinkedHashMap branch = LinkedHashMap<String, WorkoutTree>();
|
||||
|
||||
Reference in New Issue
Block a user