WT1.1.10 compact test, paralell test
This commit is contained in:
+37
-2
@@ -24,6 +24,7 @@ import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'customer_exercise_device.dart';
|
||||
import 'exercise_device.dart';
|
||||
@@ -66,6 +67,7 @@ class Cache with Logging {
|
||||
static final String loginTypeKey = 'login_type';
|
||||
static final String timerDisplayKey = 'timer_display';
|
||||
static final String activeExercisePlanKey = 'active_exercise_plan';
|
||||
static final String activeExercisePlanDateKey = 'active_exercise_plan_date';
|
||||
static final String activeExercisePlanDetailsKey = 'active_exercise_details_plan';
|
||||
|
||||
static String baseUrl = 'http://aitrainer.info:8888/api/';
|
||||
@@ -144,14 +146,27 @@ class Cache with Logging {
|
||||
this.activeExercisePlan = exercisePlan;
|
||||
this.activeExercisePlanDetails = exercisePlanDetails;
|
||||
String exercisePlanJson = JsonEncoder().convert(exercisePlan.toJson());
|
||||
String detailsJson = jsonEncode(exercisePlanDetails);
|
||||
String detailsJson = jsonEncode(exercisePlanDetails.map((i) => i.toJsonWithExerciseList()).toList()).toString();
|
||||
|
||||
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||
SharedPreferences sharedPreferences;
|
||||
sharedPreferences = await prefs;
|
||||
|
||||
final DateTime now = DateTime.now();
|
||||
sharedPreferences.setString(Cache.activeExercisePlanKey, exercisePlanJson);
|
||||
sharedPreferences.setString(Cache.activeExercisePlanDetailsKey, detailsJson);
|
||||
String savingDay = DateFormat("yyyy-MM-dd HH:mm:ss").format(now);
|
||||
sharedPreferences.setString(Cache.activeExercisePlanDateKey, savingDay);
|
||||
}
|
||||
|
||||
Future<void> deleteActiveExercisePlan() async {
|
||||
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||
SharedPreferences sharedPreferences;
|
||||
sharedPreferences = await prefs;
|
||||
|
||||
sharedPreferences.remove(Cache.activeExercisePlanDateKey);
|
||||
this.activeExercisePlan = null;
|
||||
this.activeExercisePlanDetails = null;
|
||||
}
|
||||
|
||||
Future<void> getActiveExercisePlan() async {
|
||||
@@ -159,6 +174,25 @@ class Cache with Logging {
|
||||
SharedPreferences sharedPreferences;
|
||||
sharedPreferences = await prefs;
|
||||
|
||||
final savedPlanDateString = sharedPreferences.getString(Cache.activeExercisePlanDateKey);
|
||||
if (savedPlanDateString == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DateFormat format = DateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
DateTime savedPlanDate;
|
||||
try {
|
||||
savedPlanDate = format.parse(savedPlanDateString);
|
||||
} on Exception catch (e) {
|
||||
return;
|
||||
}
|
||||
|
||||
final DateTime now = DateTime.now();
|
||||
final DateTime added = savedPlanDate.add(Duration(days: 1));
|
||||
if (added.isBefore(now)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String exercisePlanJson = sharedPreferences.getString(Cache.activeExercisePlanKey);
|
||||
if (exercisePlanJson != null) {
|
||||
final Map<String, dynamic> map = JsonDecoder().convert(exercisePlanJson);
|
||||
@@ -167,8 +201,9 @@ class Cache with Logging {
|
||||
|
||||
String detailsJson = sharedPreferences.getString(Cache.activeExercisePlanDetailsKey);
|
||||
if (detailsJson != null) {
|
||||
print("Details $detailsJson");
|
||||
Iterable json = jsonDecode(detailsJson);
|
||||
this.activeExercisePlanDetails = json.map((details) => ExercisePlanDetail.fromJson(details)).toList();
|
||||
this.activeExercisePlanDetails = json.map((details) => ExercisePlanDetail.fromJsonWithExerciseList(details)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,4 +59,9 @@ class Exercise {
|
||||
newExercise.exercisePlanDetailId = this.exercisePlanDetailId;
|
||||
return newExercise;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return this.toJson().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
enum ExerciseAbility { oneRepMax, endurance, running, mini_test, none }
|
||||
enum ExerciseAbility { oneRepMax, endurance, running, mini_test_set, paralell_test, none }
|
||||
|
||||
extension ExerciseAbilityExt on ExerciseAbility {
|
||||
String enumToString() => this.toString().split(".").last;
|
||||
bool equalsTo(ExerciseAbility ability) => this.toString() == ability.toString();
|
||||
bool equalsStringTo(String ability) => this.toString() == ability;
|
||||
String get description {
|
||||
switch (this) {
|
||||
case ExerciseAbility.endurance:
|
||||
return "Endurance";
|
||||
case ExerciseAbility.oneRepMax:
|
||||
return "One Rep Max";
|
||||
case ExerciseAbility.running:
|
||||
return "Running";
|
||||
case ExerciseAbility.mini_test_set:
|
||||
return "Compact Test";
|
||||
case ExerciseAbility.paralell_test:
|
||||
return "Custom Test";
|
||||
default:
|
||||
return "Compact Test";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
import 'exercise_type.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
|
||||
enum ExercisePlanDetailState { start, inProgress, finished }
|
||||
|
||||
extension ExericisePlanDetailStateExt on ExercisePlanDetailState {
|
||||
bool equalsTo(ExercisePlanDetailState state) => this.toString() == state.toString();
|
||||
bool equalsStringTo(String state) => this.toString() == state;
|
||||
}
|
||||
|
||||
class ExercisePlanDetail {
|
||||
int exercisePlanDetailId;
|
||||
@@ -8,6 +18,10 @@ class ExercisePlanDetail {
|
||||
int repeats;
|
||||
String weightEquation;
|
||||
|
||||
List exercises;
|
||||
bool finished;
|
||||
ExercisePlanDetailState state = ExercisePlanDetailState.start;
|
||||
|
||||
ExerciseType exerciseType;
|
||||
String change; // 1: update -1:delete 0: new
|
||||
|
||||
@@ -24,6 +38,28 @@ class ExercisePlanDetail {
|
||||
this.weightEquation = json['weightEquation'];
|
||||
}
|
||||
|
||||
ExercisePlanDetail.fromJsonWithExerciseList(Map json) {
|
||||
this.exercisePlanDetailId = json['exercisePlanDetailId'];
|
||||
this.exercisePlanId = json['exercisePlanId'];
|
||||
this.exerciseTypeId = json['exerciseTypeId'];
|
||||
this.serie = json['serie'];
|
||||
this.repeats = json['repeats'];
|
||||
this.weightEquation = json['weightEquation'];
|
||||
try {
|
||||
final String exercises = json['exercises'];
|
||||
String jsonExercises = exercises.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]}\"");
|
||||
|
||||
jsonExercises = jsonExercises.replaceAll(r'\"null\"', 'null');
|
||||
|
||||
print("Exercises $jsonExercises");
|
||||
Iterable iterable = jsonDecode(jsonExercises);
|
||||
this.exercises = iterable.map((exercise) => Exercise.fromJson(exercise)).toList();
|
||||
} on Exception catch (e) {
|
||||
print("JsonDecode error " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"exercisePlanId": exercisePlanId,
|
||||
"exerciseTypeId": exerciseTypeId,
|
||||
@@ -31,4 +67,14 @@ class ExercisePlanDetail {
|
||||
"repeats": repeats,
|
||||
"weightEquation": weightEquation
|
||||
};
|
||||
|
||||
Map<String, dynamic> toJsonWithExerciseList() => {
|
||||
"exercisePlanDetailId": exercisePlanDetailId,
|
||||
"exercisePlanId": exercisePlanId,
|
||||
"exerciseTypeId": exerciseTypeId,
|
||||
"serie": serie,
|
||||
"repeats": repeats,
|
||||
"weightEquation": weightEquation,
|
||||
'exercises': exercises.map((exercise) => exercise.toJson()).toList().toString(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
class ExerciseTree {
|
||||
/// treeId
|
||||
int treeId;
|
||||
|
||||
/// parentId
|
||||
int parentId;
|
||||
|
||||
/// name
|
||||
String name;
|
||||
|
||||
/// imageUrl
|
||||
String imageUrl;
|
||||
|
||||
/// active
|
||||
bool active;
|
||||
|
||||
/// nameTranslation
|
||||
String nameTranslation;
|
||||
|
||||
/// sort
|
||||
int sort;
|
||||
|
||||
ExerciseTree();
|
||||
|
||||
@@ -1,24 +1,51 @@
|
||||
import 'package:aitrainer_app/model/exercise_ability.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ExerciseType {
|
||||
///exerciseTypeId
|
||||
int exerciseTypeId;
|
||||
//int treeId;
|
||||
|
||||
/// name
|
||||
String name;
|
||||
|
||||
/// description
|
||||
String description;
|
||||
BinaryCodec video;
|
||||
|
||||
/// unit
|
||||
String unit;
|
||||
|
||||
/// unitQuantity
|
||||
String unitQuantity;
|
||||
|
||||
/// unitQuantityUnit
|
||||
String unitQuantityUnit;
|
||||
|
||||
///active
|
||||
bool active;
|
||||
|
||||
/// base
|
||||
bool base;
|
||||
|
||||
/// imageUrl
|
||||
String imageUrl = "";
|
||||
|
||||
/// nameTranslation
|
||||
String nameTranslation = "";
|
||||
|
||||
/// descriptionTranslation
|
||||
String descriptionTranslation = "";
|
||||
|
||||
/// devices[]
|
||||
List<int> devices = List();
|
||||
|
||||
/// parents[]
|
||||
List<int> parents = List();
|
||||
|
||||
/// alternatives []
|
||||
List<int> alternatives = List();
|
||||
|
||||
/// ability
|
||||
ExerciseAbility ability;
|
||||
|
||||
ExerciseType({this.name, this.description});
|
||||
@@ -37,8 +64,8 @@ class ExerciseType {
|
||||
this.imageUrl = json['images'][0]['url'];
|
||||
}
|
||||
if (json['translations'].length > 0) {
|
||||
this.nameTranslation = json['translations'][0]['name'];
|
||||
this.descriptionTranslation = json['translations'][0]['description'];
|
||||
this.nameTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['name'] : json['name'];
|
||||
this.descriptionTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['description'] : json['description'];
|
||||
}
|
||||
|
||||
if (json['devices'].length > 0) {
|
||||
@@ -86,11 +113,12 @@ class ExerciseType {
|
||||
return this.ability;
|
||||
}
|
||||
|
||||
bool isEndurance() {
|
||||
return this.ability.equalsTo(ExerciseAbility.endurance);
|
||||
}
|
||||
|
||||
bool is1RM() {
|
||||
return this.ability.equalsTo(ExerciseAbility.oneRepMax);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return this.toJson().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ class WorkoutMenuTree {
|
||||
bool base;
|
||||
|
||||
bool is1RM;
|
||||
bool isEndurance;
|
||||
bool isRunning;
|
||||
List<WorkoutType> workoutTypes = List();
|
||||
bool selected = false;
|
||||
@@ -42,24 +41,8 @@ class WorkoutMenuTree {
|
||||
String parentNameEnglish;
|
||||
int sort;
|
||||
|
||||
WorkoutMenuTree(
|
||||
this.id,
|
||||
this.parent,
|
||||
this.name,
|
||||
this.imageName,
|
||||
this.color,
|
||||
this.fontSize,
|
||||
this.child,
|
||||
this.exerciseTypeId,
|
||||
this.exerciseType,
|
||||
this.base,
|
||||
this.is1RM,
|
||||
this.isEndurance,
|
||||
this.isRunning,
|
||||
this.nameEnglish,
|
||||
this.parentName,
|
||||
this.parentNameEnglish,
|
||||
this.sort);
|
||||
WorkoutMenuTree(this.id, this.parent, this.name, this.imageName, this.color, this.fontSize, this.child, this.exerciseTypeId,
|
||||
this.exerciseType, this.base, this.is1RM, this.isRunning, this.nameEnglish, this.parentName, this.parentNameEnglish, this.sort);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
@@ -73,7 +56,6 @@ class WorkoutMenuTree {
|
||||
"exerciseTypeId": exerciseTypeId.toString(),
|
||||
"base": base.toString(),
|
||||
"is1RM": is1RM.toString(),
|
||||
"isEndurance": isEndurance.toString(),
|
||||
"isRunning": isRunning.toString(),
|
||||
"sort": sort,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user