wt1.1c auth->cache, control page, animation base exercise percent

This commit is contained in:
Bossanyi Tibor
2020-09-01 16:47:45 +02:00
parent 18d6994068
commit 6b0892ec09
38 changed files with 1148 additions and 261 deletions
+43 -14
View File
@@ -1,5 +1,10 @@
import 'dart:collection';
import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/exercise_tree.dart';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/model/workout_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:shared_preferences/shared_preferences.dart';
@@ -27,8 +32,8 @@ enum SharePrefsChange {
- is_logged_in
*/
class Auth {
static final Auth _singleton = Auth._internal();
class Cache {
static final Cache _singleton = Cache._internal();
// Keys to store and fetch data from SharedPreferences
static final String authTokenKey = 'auth_token';
@@ -45,16 +50,20 @@ class Auth {
String authToken = "";
Customer userLoggedIn;
bool firstLoad = true;
List<ExerciseType> _exerciseTypes;
List<ExerciseTree> _exerciseTree;
List<Exercise> _exercises;
LinkedHashMap _tree = LinkedHashMap<String, WorkoutTree>();
List deviceLanguages;
String startPage;
factory Auth() {
factory Cache() {
return _singleton;
}
Auth._internal();
Cache._internal();
String getAuthToken() {
return this.authToken;
@@ -101,23 +110,26 @@ class Auth {
sharedPreferences = await prefs;
DateTime now = DateTime.now();
sharedPreferences.setString(Auth.lastStoreDateKey, now.toString());
sharedPreferences.setString(Cache.lastStoreDateKey, now.toString());
ExerciseRepository exerciseRepository = ExerciseRepository();
if ( type == SharePrefsChange.registration ) {
Auth().startPage = "home";
sharedPreferences.setInt(Auth.customerIdKey, customerId);
sharedPreferences.setBool(Auth.isRegisteredKey, true);
sharedPreferences.setBool(Auth.isLoggedInKey, true);
Cache().startPage = "home";
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setBool(Cache.isRegisteredKey, true);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree();
exerciseRepository.getExercisesByCustomer(customerId);
} else if ( type == SharePrefsChange.login ) {
Auth().startPage = "home";
sharedPreferences.setInt(Auth.customerIdKey, customerId);
sharedPreferences.setBool(Auth.isLoggedInKey, true);
Cache().startPage = "home";
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree();
exerciseRepository.getExercisesByCustomer(customerId);
} else if ( type == SharePrefsChange.logout ) {
sharedPreferences.setBool(Auth.isLoggedInKey, false);
sharedPreferences.setInt(Auth.customerIdKey, 0);
sharedPreferences.setBool(Cache.isLoggedInKey, false);
sharedPreferences.setInt(Cache.customerIdKey, 0);
sharedPreferences.setString(authTokenKey, "");
}
}
@@ -130,6 +142,14 @@ class Auth {
this._exerciseTree = exerciseTree;
}
void setExercises( List<Exercise> exercises ) {
this._exercises = exercises;
}
void setWorkoutTree( LinkedHashMap<String, WorkoutTree> tree) {
this._tree = tree;
}
List<ExerciseType> getExerciseTypes() {
return this._exerciseTypes;
}
@@ -137,4 +157,13 @@ class Auth {
List<ExerciseTree> getExerciseTree() {
return this._exerciseTree;
}
List<Exercise> getExercises() {
return this._exercises;
}
LinkedHashMap<String, WorkoutTree> getWorkoutTree() {
return this._tree;
}
}
+10
View File
@@ -15,6 +15,8 @@ class ExerciseType {
String nameTranslation;
String descriptionTranslation;
bool is1RM;
ExerciseType({this.name, this.description});
ExerciseType.fromJson(Map json) {
@@ -41,4 +43,12 @@ class ExerciseType {
"unitQuantityUnit": unitQuantityUnit,
"active": active
};
void set1RM(bool is1RM) {
this.is1RM = is1RM;
}
bool get1RM() {
return this.is1RM;
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
class User {
class User {
String email;
String password;
int customerId;
@@ -12,4 +12,4 @@ class User {
"username": email,
"password": password,
};
}
}
+3 -1
View File
@@ -14,6 +14,8 @@ class WorkoutTree {
ExerciseType exerciseType;
bool base;
WorkoutTree(this.id, this.parent, this.name, this.imageName, this.color, this.fontSize, this.child, this.exerciseTypeId, this.exerciseType, this.base);
bool is1RM;
WorkoutTree(this.id, this.parent, this.name, this.imageName, this.color, this.fontSize, this.child, this.exerciseTypeId, this.exerciseType, this.base, this.is1RM);
}