75 lines
2.3 KiB
Dart
75 lines
2.3 KiB
Dart
import 'dart:collection';
|
|
import 'package:aitrainer_app/localization/app_language.dart';
|
|
import 'package:aitrainer_app/model/auth.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';
|
|
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
|
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class MenuTreeRepository {
|
|
final LinkedHashMap tree = LinkedHashMap<String, WorkoutTree>();
|
|
|
|
Future<void> createTree() async {
|
|
|
|
final AppLanguage appLanguage = AppLanguage();
|
|
bool isEnglish = appLanguage.appLocal == Locale('en');
|
|
|
|
List<ExerciseTree> exerciseTree = Auth().getExerciseTree();
|
|
if ( exerciseTree == null || exerciseTree.length == 0) {
|
|
await ExerciseTreeApi().getExerciseTree();
|
|
}
|
|
|
|
exerciseTree.forEach( (treeItem) async {
|
|
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
|
String assetImage = 'asset/menu/' + treeItem.imageUrl.substring(7);
|
|
this.tree[treeItem.name] = WorkoutTree(
|
|
treeItem.treeId,
|
|
treeItem.parentId,
|
|
treeName,
|
|
assetImage, Colors.white,
|
|
32,
|
|
false,
|
|
0,
|
|
null,
|
|
false
|
|
);
|
|
});
|
|
|
|
List<ExerciseType> exerciseTypes = Auth().getExerciseTypes();
|
|
if ( exerciseTypes == null || exerciseTypes.length == 0) {
|
|
await ExerciseTypeApi().getExerciseTypes();
|
|
}
|
|
|
|
exerciseTypes.forEach( (exerciseType) {
|
|
String exerciseTypeName = isEnglish ?
|
|
exerciseType.name : exerciseType.nameTranslation;
|
|
String assetImage = 'asset/menu/' + exerciseType.imageUrl.substring(7);
|
|
this.tree[exerciseType.name] = WorkoutTree(
|
|
exerciseType.exerciseTypeId,
|
|
exerciseType.treeId,
|
|
exerciseTypeName,
|
|
assetImage,
|
|
Colors.white,
|
|
16,
|
|
true,
|
|
exerciseType.exerciseTypeId,
|
|
exerciseType,
|
|
exerciseType.base
|
|
);
|
|
});
|
|
}
|
|
|
|
|
|
LinkedHashMap getBranch(int parent) {
|
|
LinkedHashMap branch = LinkedHashMap<String, WorkoutTree>();
|
|
tree.forEach((key, value) {
|
|
WorkoutTree workoutTree = value as WorkoutTree;
|
|
if ( parent == workoutTree.parent) {
|
|
branch[key] = value;
|
|
}
|
|
});
|
|
return branch;
|
|
}
|
|
} |