Merge ssh://git.aitrainer.app:6622/bossanyit/aitrainer_app
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer_exercise_device.dart';
|
||||
import 'package:aitrainer_app/model/exercise_device.dart';
|
||||
import 'package:aitrainer_app/model/model_change.dart';
|
||||
import 'package:aitrainer_app/service/customer_exercise_device_service.dart';
|
||||
|
||||
class CustomerExerciseDeviceRepository {
|
||||
List<CustomerExerciseDevice> _devices = List();
|
||||
|
||||
List<CustomerExerciseDevice> getDevices() => this._devices;
|
||||
|
||||
void setDevices(List<CustomerExerciseDevice> devices) => this._devices = devices;
|
||||
|
||||
Future<List<CustomerExerciseDevice>> getDBDevices() async {
|
||||
if (Cache().userLoggedIn != null) {
|
||||
final int customerId = Cache().userLoggedIn.customerId;
|
||||
this._devices = await CustomerExerciseDeviceApi().getDevices(customerId);
|
||||
}
|
||||
return this._devices;
|
||||
}
|
||||
|
||||
Future<void> addDevice(ExerciseDevice device) async {
|
||||
CustomerExerciseDevice found;
|
||||
if (_devices != null) {
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == device.exerciseDeviceId) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (found == null) {
|
||||
int customerId;
|
||||
if (Cache().userLoggedIn != null) {
|
||||
customerId = Cache().userLoggedIn.customerId;
|
||||
}
|
||||
CustomerExerciseDevice newDevice =
|
||||
CustomerExerciseDevice(customerId: customerId, exerciseDeviceId: device.exerciseDeviceId, favourite: false);
|
||||
newDevice.change = ModelChange.add;
|
||||
await CustomerExerciseDeviceApi().addDevice(newDevice);
|
||||
this._devices.add(newDevice);
|
||||
Cache().setCustomerDevices(_devices);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeDevice(ExerciseDevice device) async {
|
||||
print("Remove " + device.name);
|
||||
|
||||
CustomerExerciseDevice found;
|
||||
if (_devices != null) {
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == device.exerciseDeviceId) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (found != null) {
|
||||
this._devices.remove(found);
|
||||
if (found.change != ModelChange.add) {
|
||||
await CustomerExerciseDeviceApi().removeDevice(found.customerExerciseDeviceId);
|
||||
}
|
||||
Cache().setCustomerDevices(_devices);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasDevice(int exerciseDeviceId) {
|
||||
bool found = false;
|
||||
if (_devices != null) {
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == exerciseDeviceId) {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:aitrainer_app/model/exercise_device.dart';
|
||||
import 'package:aitrainer_app/service/exercise_device_service.dart';
|
||||
|
||||
class ExerciseDeviceRepository {
|
||||
List<ExerciseDevice> _devices = List();
|
||||
|
||||
List<ExerciseDevice> getDevices() {
|
||||
return this._devices;
|
||||
}
|
||||
|
||||
Future<List<ExerciseDevice>> getDBDevices() async {
|
||||
this._devices = await ExerciseDeviceApi().getDevices();
|
||||
return this._devices;
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,17 @@ import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/model_change.dart';
|
||||
import 'package:aitrainer_app/service/exercise_plan_service.dart';
|
||||
|
||||
class ExercisePlanRepository {
|
||||
bool newPlan = true;
|
||||
ExercisePlan exercisePlan;
|
||||
LinkedHashMap<int, ExercisePlanDetail> exercisePlanDetails =
|
||||
LinkedHashMap<int, ExercisePlanDetail>();
|
||||
LinkedHashMap<int, ExercisePlanDetail> exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
int customerId = 0;
|
||||
ExercisePlanDetail actualPlanDetail;
|
||||
|
||||
void setCustomerId( int customerId ) {
|
||||
void setCustomerId(int customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,10 @@ class ExercisePlanRepository {
|
||||
this.exercisePlan = plan;
|
||||
}
|
||||
|
||||
|
||||
ExercisePlan getExercisePlan() => exercisePlan;
|
||||
|
||||
void addDetailToPlan() {
|
||||
if ( exercisePlan != null ) {
|
||||
if (exercisePlan != null) {
|
||||
actualPlanDetail.exercisePlanId = exercisePlan.exercisePlanId;
|
||||
}
|
||||
exercisePlanDetails[actualPlanDetail.exerciseTypeId] = actualPlanDetail;
|
||||
@@ -39,7 +38,7 @@ class ExercisePlanRepository {
|
||||
|
||||
void setActualPlanDetailByExerciseType(ExerciseType exerciseType) {
|
||||
ExercisePlanDetail detail = exercisePlanDetails[exerciseType.exerciseTypeId];
|
||||
if ( detail != null ) {
|
||||
if (detail != null) {
|
||||
actualPlanDetail = detail;
|
||||
} else {
|
||||
actualPlanDetail = ExercisePlanDetail(exerciseType.exerciseTypeId);
|
||||
@@ -49,7 +48,7 @@ class ExercisePlanRepository {
|
||||
|
||||
ExercisePlanDetail getActualPlanDetail() => actualPlanDetail;
|
||||
|
||||
void setActualPlanDetail( ExercisePlanDetail detail ) {
|
||||
void setActualPlanDetail(ExercisePlanDetail detail) {
|
||||
this.actualPlanDetail = detail;
|
||||
}
|
||||
|
||||
@@ -58,10 +57,8 @@ class ExercisePlanRepository {
|
||||
String getPlanDetail(int exerciseTypeId) {
|
||||
ExercisePlanDetail detail = exercisePlanDetails[exerciseTypeId];
|
||||
String detailString = "";
|
||||
if ( detail != null) {
|
||||
detailString =
|
||||
detail.serie.toString() + "x" + detail.repeats.toString() + " " +
|
||||
detail.weightEquation + "kg";
|
||||
if (detail != null) {
|
||||
detailString = detail.serie.toString() + "x" + detail.repeats.toString() + " " + detail.weightEquation + "kg";
|
||||
}
|
||||
return detailString;
|
||||
}
|
||||
@@ -71,14 +68,14 @@ class ExercisePlanRepository {
|
||||
}
|
||||
|
||||
void updateExercisePlanDetail(ExerciseType exerciseType, int serie, int repeat, String weight) {
|
||||
if ( exercisePlanDetails[exerciseType.exerciseTypeId] == null) {
|
||||
if (exercisePlanDetails[exerciseType.exerciseTypeId] == null) {
|
||||
return;
|
||||
}
|
||||
ExercisePlanDetail exercisePlanDetail = exercisePlanDetails[exerciseType.exerciseTypeId];
|
||||
exercisePlanDetail.serie = serie;
|
||||
exercisePlanDetail.repeats = repeat;
|
||||
exercisePlanDetail.weightEquation = weight;
|
||||
exercisePlanDetail.change = ExercisePlanDetailChange.update;
|
||||
exercisePlanDetail.change = ModelChange.update;
|
||||
|
||||
exercisePlanDetails[exerciseType.exerciseTypeId] = exercisePlanDetail;
|
||||
}
|
||||
@@ -88,19 +85,18 @@ class ExercisePlanRepository {
|
||||
}
|
||||
|
||||
void removeExerciseTypeFromPlanByExerciseTypeId(int exerciseTypeId) {
|
||||
exercisePlanDetails[exerciseTypeId].change = ExercisePlanDetailChange.delete;
|
||||
exercisePlanDetails[exerciseTypeId].change = ModelChange.delete;
|
||||
Cache().deleteMyExercisePlanDetailByExerciseTypeId(exerciseTypeId);
|
||||
}
|
||||
|
||||
Future<void> saveExercisePlan() async {
|
||||
|
||||
if ( exercisePlan == null ) {
|
||||
if ( Cache().userLoggedIn == null ) {
|
||||
if (exercisePlan == null) {
|
||||
if (Cache().userLoggedIn == null) {
|
||||
throw Exception("please log in");
|
||||
}
|
||||
|
||||
String exercisePlanName;
|
||||
if ( this.customerId == Cache().userLoggedIn.customerId) {
|
||||
if (this.customerId == Cache().userLoggedIn.customerId) {
|
||||
exercisePlanName = Cache().userLoggedIn.name + " private";
|
||||
} else {
|
||||
exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private";
|
||||
@@ -108,55 +104,47 @@ class ExercisePlanRepository {
|
||||
|
||||
exercisePlan = ExercisePlan(exercisePlanName, this.customerId);
|
||||
}
|
||||
if ( newPlan ) {
|
||||
if (newPlan) {
|
||||
exercisePlan.dateAdd = DateTime.now();
|
||||
exercisePlan.private = true;
|
||||
ExercisePlan savedExercisePlan =
|
||||
await ExercisePlanApi().saveExercisePlan(exercisePlan);
|
||||
ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan);
|
||||
|
||||
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId;
|
||||
ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
savedExercisePlanDetails[savedDetail.exerciseTypeId] = savedDetail;
|
||||
});
|
||||
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId;
|
||||
ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
savedExercisePlanDetails[savedDetail.exerciseTypeId] = savedDetail;
|
||||
});
|
||||
|
||||
exercisePlan = savedExercisePlan;
|
||||
exercisePlanDetails = savedExercisePlanDetails;
|
||||
|
||||
} else {
|
||||
|
||||
//await ExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId);
|
||||
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
if ( exercisePlanDetail.change == ExercisePlanDetailChange.delete ) {
|
||||
await ExercisePlanApi()
|
||||
.deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
|
||||
exercisePlanDetail.change = ExercisePlanDetailChange.deleted;
|
||||
if (exercisePlanDetail.change == ModelChange.delete) {
|
||||
await ExercisePlanApi().deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
|
||||
exercisePlanDetail.change = ModelChange.deleted;
|
||||
Cache().deletedMyExercisePlanDetail(exercisePlanDetail);
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.update ) {
|
||||
await ExercisePlanApi()
|
||||
.updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
|
||||
} else if (exercisePlanDetail.change == ModelChange.update) {
|
||||
await ExercisePlanApi().updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
|
||||
Cache().updateMyExercisePlanDetail(exercisePlanDetail);
|
||||
exercisePlanDetail.change = ExercisePlanDetailChange.saved;
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.add ) {
|
||||
await ExercisePlanApi()
|
||||
.saveExercisePlanDetail(exercisePlanDetail);
|
||||
exercisePlanDetail.change = ModelChange.saved;
|
||||
} else if (exercisePlanDetail.change == ModelChange.add) {
|
||||
await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
Cache().addToMyExercisePlanDetails(exercisePlanDetail);
|
||||
exercisePlanDetail.change = ExercisePlanDetailChange.saved;
|
||||
exercisePlanDetail.change = ModelChange.saved;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Future<ExercisePlan> getLastExercisePlan() async {
|
||||
if ( customerId == 0) {
|
||||
if (customerId == 0) {
|
||||
return null;
|
||||
}
|
||||
ExercisePlan myExercisePlan = Cache().getMyExercisePlan();
|
||||
if ( myExercisePlan != null ) {
|
||||
if (myExercisePlan != null) {
|
||||
exercisePlan = myExercisePlan;
|
||||
return myExercisePlan;
|
||||
}
|
||||
@@ -171,15 +159,15 @@ class ExercisePlanRepository {
|
||||
Future<void> getExercisePlanDetails() async {
|
||||
if (exercisePlan == null) {
|
||||
ExercisePlan exercisePlan = await this.getLastExercisePlan();
|
||||
if ( exercisePlan == null ) {
|
||||
if (exercisePlan == null) {
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<ExercisePlanDetail> list = List();
|
||||
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
|
||||
if ( listCache.length > 0) {
|
||||
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
|
||||
if (listCache.length > 0) {
|
||||
exercisePlanDetails = listCache;
|
||||
return;
|
||||
} else {
|
||||
@@ -197,5 +185,4 @@ class ExercisePlanRepository {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/service/property_service.dart';
|
||||
|
||||
@@ -41,9 +41,7 @@ class UserRepository {
|
||||
String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password);
|
||||
|
||||
if (rc == FirebaseApi.SIGN_IN_OK) {
|
||||
print("Firebase login ok");
|
||||
await CustomerApi().getUserByEmail(modelUser.email);
|
||||
print("GetUserBy Email OK");
|
||||
Cache().afterFirebaseLogin();
|
||||
} else {
|
||||
print("Exception: user not found or password is wrong");
|
||||
|
||||
Reference in New Issue
Block a user