Merge ssh://git.aitrainer.app:6622/bossanyit/aitrainer_app
This commit is contained in:
+92
-2
@@ -4,15 +4,22 @@ import 'package:aitrainer_app/model/exercise_plan.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/model_change.dart';
|
||||
import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/service/customer_exercise_device_service.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
import 'package:aitrainer_app/util/env.dart';
|
||||
import 'package:flurry/flurry.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
|
||||
import 'customer_exercise_device.dart';
|
||||
import 'exercise_device.dart';
|
||||
|
||||
enum SharePrefsChange {
|
||||
login,
|
||||
registration,
|
||||
@@ -64,6 +71,8 @@ class Cache {
|
||||
List<Exercise> _exercises;
|
||||
ExercisePlan _myExercisePlan;
|
||||
List<Property> _properties;
|
||||
List<ExerciseDevice> _devices;
|
||||
List<CustomerExerciseDevice> _customerDevices;
|
||||
|
||||
LinkedHashMap<int, ExercisePlanDetail> _myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
|
||||
@@ -75,6 +84,8 @@ class Cache {
|
||||
ExercisePlan _traineeExercisePlan;
|
||||
List<ExercisePlanDetail> _traineeExercisesPlanDetail;
|
||||
|
||||
LinkedHashMap<String, int> _badges = LinkedHashMap();
|
||||
|
||||
List deviceLanguages;
|
||||
String startPage;
|
||||
|
||||
@@ -158,7 +169,10 @@ class Cache {
|
||||
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
|
||||
Cache().setCustomerDevices(customerDevices);
|
||||
await exerciseRepository.getExercisesByCustomer(customerId);
|
||||
Flurry.setUserId(customerId.toString());
|
||||
} else if (type == SharePrefsChange.login) {
|
||||
Cache().startPage = "home";
|
||||
sharedPreferences.setInt(Cache.customerIdKey, customerId);
|
||||
@@ -166,13 +180,17 @@ class Cache {
|
||||
sharedPreferences.setBool(Cache.isLoggedInKey, true);
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
|
||||
Cache().setCustomerDevices(customerDevices);
|
||||
await exerciseRepository.getExercisesByCustomer(customerId);
|
||||
Flurry.setUserId(customerId.toString());
|
||||
} else if (type == SharePrefsChange.logout) {
|
||||
sharedPreferences.setBool(Cache.isLoggedInKey, false);
|
||||
sharedPreferences.setInt(Cache.customerIdKey, 0);
|
||||
sharedPreferences.setString(Cache.firebaseUidKey, null);
|
||||
sharedPreferences.setString(authTokenKey, "");
|
||||
}
|
||||
initBadges();
|
||||
}
|
||||
|
||||
void setExerciseTypes(List<ExerciseType> exerciseTypes) {
|
||||
@@ -241,13 +259,85 @@ class Cache {
|
||||
void deleteMyExercisePlanDetail(ExercisePlanDetail detail) => this.deleteMyExercisePlanDetailByExerciseTypeId(detail.exerciseTypeId);
|
||||
|
||||
void deletedMyExercisePlanDetail(ExercisePlanDetail detail) =>
|
||||
this._myExercisesPlanDetails[detail.exerciseTypeId].change = ExercisePlanDetailChange.deleted;
|
||||
this._myExercisesPlanDetails[detail.exerciseTypeId].change = ModelChange.deleted;
|
||||
|
||||
void deleteMyExercisePlanDetailByExerciseTypeId(int exerciseTypeId) {
|
||||
this._myExercisesPlanDetails[exerciseTypeId].change = ExercisePlanDetailChange.delete;
|
||||
this._myExercisesPlanDetails[exerciseTypeId].change = ModelChange.delete;
|
||||
}
|
||||
|
||||
void setProperties(List<Property> properties) => this._properties = properties;
|
||||
|
||||
List<Property> getProperties() => _properties;
|
||||
|
||||
void setDevices(List<ExerciseDevice> devices) => this._devices = devices;
|
||||
|
||||
List<ExerciseDevice> getDevices() => this._devices;
|
||||
|
||||
void setCustomerDevices(List<CustomerExerciseDevice> devices) => this._customerDevices = devices;
|
||||
|
||||
List<CustomerExerciseDevice> getCustomerDevices() => this._customerDevices;
|
||||
|
||||
LinkedHashMap getBadges() => _badges;
|
||||
|
||||
void setBadge(String key, bool inc) {
|
||||
if (inc) {
|
||||
if (_badges[key] != null) {
|
||||
_badges[key]++;
|
||||
} else {
|
||||
_badges[key] = 1;
|
||||
}
|
||||
} else {
|
||||
if (_badges[key] != null) {
|
||||
if (_badges[key] == 1) {
|
||||
_badges.remove(key);
|
||||
} else {
|
||||
_badges[key]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setBadgeNr(String key, int counter) {
|
||||
if (_badges[key] != null) {
|
||||
_badges[key] += counter;
|
||||
} else {
|
||||
_badges[key] = counter;
|
||||
}
|
||||
}
|
||||
|
||||
void initBadges() {
|
||||
CustomerRepository customerRepository = CustomerRepository();
|
||||
_badges = LinkedHashMap();
|
||||
customerRepository.setCustomer(userLoggedIn);
|
||||
if (this.userLoggedIn != null) {
|
||||
if (this.userLoggedIn.firstname == null || userLoggedIn.firstname.length == 0) {
|
||||
setBadge("personalData", true);
|
||||
setBadge("account", true);
|
||||
}
|
||||
if (this._customerDevices == null || this._customerDevices.isEmpty) {
|
||||
setBadge("customerDevice", true);
|
||||
setBadge("account", true);
|
||||
}
|
||||
if (userLoggedIn.properties == null || userLoggedIn.properties.isEmpty) {
|
||||
setBadge("personalData", true);
|
||||
setBadge("Sizes", true);
|
||||
setBadge("BMI", true);
|
||||
setBadge("BMR", true);
|
||||
setBadgeNr("Body Compositions", 3);
|
||||
setBadgeNr("home", 3);
|
||||
} else if (customerRepository.getWeight() == 0) {
|
||||
setBadge("BMI", true);
|
||||
setBadge("BMR", true);
|
||||
setBadge("Body Compositions", true);
|
||||
setBadgeNr("home", 1);
|
||||
}
|
||||
if (customerRepository.getHeight() == 0) {
|
||||
setBadge("BMI", true);
|
||||
setBadge("BMR", true);
|
||||
setBadge("Body Compositions", true);
|
||||
setBadgeNr("home", 1);
|
||||
}
|
||||
}
|
||||
print("Badges: " + _badges.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
class CustomerExerciseDevice {
|
||||
int customerExerciseDeviceId;
|
||||
int exerciseDeviceId;
|
||||
int customerId;
|
||||
bool favourite;
|
||||
DateTime dateAdd;
|
||||
|
||||
String change;
|
||||
|
||||
CustomerExerciseDevice({this.exerciseDeviceId, this.customerId, this.favourite}) {
|
||||
dateAdd = DateTime.now();
|
||||
}
|
||||
|
||||
CustomerExerciseDevice.fromJson(Map json) {
|
||||
this.customerExerciseDeviceId = json['customerExerciseDeviceId'];
|
||||
this.exerciseDeviceId = json['exerciseDeviceId'];
|
||||
this.customerId = json['customerId'];
|
||||
this.favourite = json['favourite'] == 1 ? true : false;
|
||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
if (customerExerciseDeviceId == null) {
|
||||
return {
|
||||
"exerciseDeviceId": exerciseDeviceId,
|
||||
"customerId": customerId,
|
||||
"favourite": favourite == true ? 1 : 0,
|
||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
"customerExerciseDeviceId": customerExerciseDeviceId,
|
||||
"exerciseDeviceId": exerciseDeviceId,
|
||||
"customerId": customerId,
|
||||
"favourite": favourite == true ? 1 : 0,
|
||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
class ExerciseDevice {
|
||||
int exerciseDeviceId;
|
||||
String name;
|
||||
String description;
|
||||
String imageUrl;
|
||||
String nameTranslation;
|
||||
int sort;
|
||||
bool place;
|
||||
|
||||
ExerciseDevice.fromJson(Map json) {
|
||||
this.exerciseDeviceId = json['exerciseDeviceId'];
|
||||
this.name = json['name'];
|
||||
this.description = json['description'];
|
||||
this.imageUrl = json['imageUrl'];
|
||||
this.nameTranslation = json['translations'][0]['name'];
|
||||
this.sort = json['sort'];
|
||||
this.place = json['place'] == 1 ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -21,19 +21,18 @@ class ExercisePlan {
|
||||
this.name = json['name'];
|
||||
this.private = json['private'];
|
||||
this.description = json['description'];
|
||||
this.dateAdd = json['dateAdd'] == null ? null : DateTime.parse( json['dateAdd'] );
|
||||
this.dateUpd = json['dateUpd'] == null ? null : DateTime.parse( json['dateUpd'] );
|
||||
this.dateAdd = json['dateAdd'] == null ? null : DateTime.parse(json['dateAdd']);
|
||||
this.dateUpd = json['dateUpd'] == null ? null : DateTime.parse(json['dateUpd']);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
String formattedDateAdd;
|
||||
if ( dateAdd != null) {
|
||||
if (dateAdd != null) {
|
||||
formattedDateAdd = DateFormat('yyyy-MM-dd HH:mm').format(dateAdd);
|
||||
}
|
||||
String formattedDateUpd = DateFormat('yyyy-MM-dd HH:mm').format(dateUpd);
|
||||
|
||||
print("DateAdd $formattedDateAdd");
|
||||
if ( exercisePlanId == null ) {
|
||||
if (exercisePlanId == null) {
|
||||
return {
|
||||
"customerId": customerId,
|
||||
"name": name,
|
||||
@@ -54,5 +53,4 @@ class ExercisePlan {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import 'exercise_type.dart';
|
||||
|
||||
class ExercisePlanDetailChange {
|
||||
static const String add = "add";
|
||||
static const String delete = "delete";
|
||||
static const String update = "update";
|
||||
static const String deleted = "deleted";
|
||||
static const String saved = "saved";
|
||||
}
|
||||
|
||||
class ExercisePlanDetail {
|
||||
int exercisePlanDetailId;
|
||||
int exercisePlanId;
|
||||
@@ -32,12 +24,11 @@ class ExercisePlanDetail {
|
||||
this.weightEquation = json['weightEquation'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
"exercisePlanId": exercisePlanId,
|
||||
"exerciseTypeId": exerciseTypeId,
|
||||
"serie": serie,
|
||||
"repeats": repeats,
|
||||
"weightEquation": weightEquation
|
||||
};
|
||||
}
|
||||
Map<String, dynamic> toJson() => {
|
||||
"exercisePlanId": exercisePlanId,
|
||||
"exerciseTypeId": exerciseTypeId,
|
||||
"serie": serie,
|
||||
"repeats": repeats,
|
||||
"weightEquation": weightEquation
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'package:flutter/semantics.dart';
|
||||
|
||||
class FitnessState {
|
||||
final String value;
|
||||
final String stateText;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class ModelChange {
|
||||
static const String add = "add";
|
||||
static const String delete = "delete";
|
||||
static const String update = "update";
|
||||
static const String deleted = "deleted";
|
||||
static const String saved = "saved";
|
||||
}
|
||||
Reference in New Issue
Block a user