Merge ssh://git.aitrainer.app:6622/bossanyit/aitrainer_app
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -77,6 +78,7 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
yield CustomerSaving();
|
||||
if (validation()) {
|
||||
await customerRepository.saveCustomer();
|
||||
Cache().initBadges();
|
||||
yield CustomerSaveSuccess();
|
||||
} else {
|
||||
yield CustomerSaveError(message: "Please provide the necessary information");
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_device.dart';
|
||||
import 'package:aitrainer_app/repository/customer_exercise_device_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'customer_exercise_device_event.dart';
|
||||
part 'customer_exercise_device_state.dart';
|
||||
|
||||
class CustomerExerciseDeviceBloc extends Bloc<CustomerExerciseDeviceEvent, CustomerExerciseDeviceState> {
|
||||
final CustomerExerciseDeviceRepository repository;
|
||||
final List<ExerciseDevice> devices;
|
||||
|
||||
CustomerExerciseDeviceBloc({this.repository, this.devices}) : super(CustomerExerciseDeviceInitial()) {
|
||||
if (repository.getDevices().isEmpty) {
|
||||
repository.setDevices(Cache().getCustomerDevices());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<CustomerExerciseDeviceState> mapEventToState(
|
||||
CustomerExerciseDeviceEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (event is CustomerExerciseDeviceLoad) {
|
||||
yield CustomerExerciseDeviceLoading();
|
||||
yield CustomerExerciseDeviceReady();
|
||||
} else if (event is CustomerExerciseDeviceAdd) {
|
||||
yield CustomerExerciseDeviceLoading();
|
||||
print("Add device " + event.device.exerciseDeviceId.toString());
|
||||
await repository.addDevice(event.device);
|
||||
Cache().initBadges();
|
||||
yield CustomerExerciseDeviceReady();
|
||||
} else if (event is CustomerExerciseDeviceRemove) {
|
||||
print("Remove device " + event.device.exerciseDeviceId.toString());
|
||||
yield CustomerExerciseDeviceLoading();
|
||||
await repository.removeDevice(event.device);
|
||||
Cache().initBadges();
|
||||
yield CustomerExerciseDeviceReady();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield CustomerExerciseDeviceError(message: ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
bool hasCustomerDevice(int exerciseDeviceId) {
|
||||
return repository.hasDevice(exerciseDeviceId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
part of 'customer_exercise_device_bloc.dart';
|
||||
|
||||
abstract class CustomerExerciseDeviceEvent extends Equatable {
|
||||
const CustomerExerciseDeviceEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceLoad extends CustomerExerciseDeviceEvent {
|
||||
const CustomerExerciseDeviceLoad();
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceAdd extends CustomerExerciseDeviceEvent {
|
||||
final ExerciseDevice device;
|
||||
const CustomerExerciseDeviceAdd({this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [device];
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceRemove extends CustomerExerciseDeviceEvent {
|
||||
final ExerciseDevice device;
|
||||
const CustomerExerciseDeviceRemove({this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [device];
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceSave extends CustomerExerciseDeviceEvent {
|
||||
const CustomerExerciseDeviceSave();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
part of 'customer_exercise_device_bloc.dart';
|
||||
|
||||
abstract class CustomerExerciseDeviceState extends Equatable {
|
||||
const CustomerExerciseDeviceState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceInitial extends CustomerExerciseDeviceState {
|
||||
const CustomerExerciseDeviceInitial();
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceLoading extends CustomerExerciseDeviceState {
|
||||
const CustomerExerciseDeviceLoading();
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceReady extends CustomerExerciseDeviceState {
|
||||
const CustomerExerciseDeviceReady();
|
||||
}
|
||||
|
||||
class CustomerExerciseDeviceError extends CustomerExerciseDeviceState {
|
||||
final String message;
|
||||
const CustomerExerciseDeviceError({this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flurry/flurry.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'exercise_execute_plan_add_event.dart';
|
||||
@@ -30,27 +31,23 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
double scrollOffset = 0;
|
||||
|
||||
@override
|
||||
ExerciseExecutePlanAddBloc({
|
||||
this.exerciseRepository,
|
||||
this.exercisePlanRepository,
|
||||
this.customerId,
|
||||
this.workoutTree,
|
||||
this.planBloc}): super(ExerciseExecutePlanAddInitial()) {
|
||||
exerciseRepository.exerciseType = workoutTree.exerciseType;
|
||||
if ( Cache().userLoggedIn.customerId == customerId) {
|
||||
customer = Cache().userLoggedIn;
|
||||
} else if ( Cache().getTrainee().customerId == customerId) {
|
||||
customer = Cache().getTrainee();
|
||||
}
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
exerciseRepository.customer = customer;
|
||||
countSteps = exercisePlanRepository.getActualPlanDetail().serie;
|
||||
ExerciseExecutePlanAddBloc({this.exerciseRepository, this.exercisePlanRepository, this.customerId, this.workoutTree, this.planBloc})
|
||||
: super(ExerciseExecutePlanAddInitial()) {
|
||||
exerciseRepository.exerciseType = workoutTree.exerciseType;
|
||||
if (Cache().userLoggedIn.customerId == customerId) {
|
||||
customer = Cache().userLoggedIn;
|
||||
} else if (Cache().getTrainee().customerId == customerId) {
|
||||
customer = Cache().getTrainee();
|
||||
}
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
exerciseRepository.customer = customer;
|
||||
countSteps = exercisePlanRepository.getActualPlanDetail().serie;
|
||||
|
||||
unitQuantity = double.parse(exercisePlanRepository.getActualPlanDetail().weightEquation);
|
||||
quantity = exercisePlanRepository.getActualPlanDetail().repeats.toDouble();
|
||||
unitQuantity = double.parse(exercisePlanRepository.getActualPlanDetail().weightEquation);
|
||||
quantity = exercisePlanRepository.getActualPlanDetail().repeats.toDouble();
|
||||
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -71,12 +68,12 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddSubmit) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
exerciseRepository.exercise.exercisePlanDetailId =
|
||||
exercisePlanRepository.getActualPlanDetail().exercisePlanDetailId;
|
||||
exerciseRepository.exercise.exercisePlanDetailId = exercisePlanRepository.getActualPlanDetail().exercisePlanDetailId;
|
||||
exerciseRepository.exercise.unit = workoutTree.exerciseType.unit;
|
||||
workoutTree.executed = true;
|
||||
print("On Submitting Exercise Execute Plan Add " + exerciseRepository.exercise.toJson().toString());
|
||||
await exerciseRepository.addExercise();
|
||||
Flurry.logEvent("ExecuteExercisePlan");
|
||||
step++;
|
||||
scrollOffset = step * 200.0;
|
||||
planBloc.add(ExerciseByPlanLoad());
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flurry/flurry.dart';
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
@@ -266,6 +267,8 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
|
||||
customerRepository.saveCustomer();
|
||||
changedWeight = false;
|
||||
this.changedSizes = false;
|
||||
Cache().initBadges();
|
||||
Flurry.logEvent("Sizes");
|
||||
yield ExerciseNewReady();
|
||||
} else if (event is ExerciseNewSizeChange) {
|
||||
yield ExerciseNewLoading();
|
||||
@@ -277,6 +280,8 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
|
||||
yield ExerciseNewLoading();
|
||||
await exerciseRepository.addExercise();
|
||||
menuBloc.add(MenuTreeDown(parent: 0));
|
||||
Cache().initBadges();
|
||||
Flurry.logEvent("newExercise");
|
||||
yield ExerciseNewReady();
|
||||
} else if (event is ExerciseNewBMIAnimate) {
|
||||
yield ExerciseNewLoading();
|
||||
@@ -288,7 +293,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
|
||||
}
|
||||
|
||||
double getBMI() {
|
||||
if (height == 0) {
|
||||
if (height == 0 || weight == 0) {
|
||||
this.bmi = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -299,6 +304,10 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
|
||||
|
||||
double getBMR() {
|
||||
var date = DateTime.now();
|
||||
if (height == 0 || weight == 0) {
|
||||
this.bmi = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int year = int.parse(DateFormat(DateFormat.YEAR).format(date));
|
||||
|
||||
@@ -334,14 +343,15 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
|
||||
this.bmiLeft = 72;
|
||||
bmiAngle = -62;
|
||||
} else if (bmi < 25 && 18.5 < bmi) {
|
||||
goalBMI = bmi;
|
||||
goalBMI = 27;
|
||||
this.bmiTop = 46;
|
||||
this.bmiLeft = 130;
|
||||
bmiAngle = -21;
|
||||
bmiAngle = -23;
|
||||
} else if (bmi < 30 && 24.9 < bmi) {
|
||||
goalBMI = 24;
|
||||
this.bmiTop = 38.0;
|
||||
this.bmiLeft = 186.0;
|
||||
bmiAngle = 7.2;
|
||||
} else if (bmi < 34.9 && 29.9 < bmi) {
|
||||
goalBMI = 29;
|
||||
bmiTop = 48;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/model_change.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flurry/flurry.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'exercise_plan_event.dart';
|
||||
@@ -31,7 +33,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
workoutTree.selected = false;
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() > 0) {
|
||||
ExercisePlanDetail planDetail = exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId);
|
||||
if (planDetail != null && planDetail.change != ExercisePlanDetailChange.deleted) {
|
||||
if (planDetail != null && planDetail.change != ModelChange.deleted) {
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +41,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
});
|
||||
}
|
||||
|
||||
void setExercisePlanRepository(ExercisePlanRepository repo ) => exercisePlanRepository = repo;
|
||||
void setExercisePlanRepository(ExercisePlanRepository repo) => exercisePlanRepository = repo;
|
||||
|
||||
@override
|
||||
Stream<ExercisePlanState> mapEventToState(ExercisePlanEvent event) async* {
|
||||
@@ -55,14 +57,12 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
|
||||
WorkoutMenuTree workoutTree = event.workoutTree;
|
||||
if (workoutTree != null) {
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
workoutTree.selected = true;
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
else if (event is ExercisePlanAddExercise) {
|
||||
} else if (event is ExercisePlanAddExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.actualPlanDetail = planDetail;
|
||||
@@ -74,16 +74,14 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if ( element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
if (element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
else if (event is ExercisePlanRemoveExercise) {
|
||||
} else if (event is ExercisePlanRemoveExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId);
|
||||
@@ -91,7 +89,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if ( element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
if (element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = false;
|
||||
}
|
||||
});
|
||||
@@ -99,12 +97,11 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
exercisePlanRepository.saveExercisePlan();
|
||||
Flurry.logEvent("SaveExercisePlan");
|
||||
}
|
||||
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
} on Exception catch (e) {
|
||||
yield ExercisePlanError(message: e.toString());
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ class LoginFormBloc extends FormBloc<String, String> with Common {
|
||||
}
|
||||
emitSuccess(canSubmitAgain: false);
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
Cache().initBadges();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
emitFailure(failureResponse: ex.toString());
|
||||
|
||||
@@ -11,19 +11,14 @@ class RegistrationFormBloc extends FormBloc<String, String> with Common {
|
||||
FieldBlocValidators.required,
|
||||
],
|
||||
);
|
||||
final passwordField = TextFieldBloc(
|
||||
validators: [
|
||||
FieldBlocValidators.required,
|
||||
]
|
||||
);
|
||||
final passwordField = TextFieldBloc(validators: [
|
||||
FieldBlocValidators.required,
|
||||
]);
|
||||
final UserRepository userRepository;
|
||||
|
||||
RegistrationFormBloc({this.userRepository, this.accountBloc}) {
|
||||
addFieldBlocs(fieldBlocs: [
|
||||
emailField,
|
||||
passwordField
|
||||
]);
|
||||
|
||||
addFieldBlocs(fieldBlocs: [emailField, passwordField]);
|
||||
|
||||
emailField.onValueChanges(onData: (previous, current) async* {
|
||||
userRepository.setEmail(current.value);
|
||||
});
|
||||
@@ -31,18 +26,17 @@ class RegistrationFormBloc extends FormBloc<String, String> with Common {
|
||||
passwordField.onValueChanges(onData: (previous, current) async* {
|
||||
userRepository.setPassword(current.value);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void onSubmitting() async {
|
||||
try {
|
||||
emitLoading(progress: 30);
|
||||
if ( ! validateEmail(userRepository)) {
|
||||
if (!validateEmail(userRepository)) {
|
||||
emailField.addFieldError(EMAIL_ERROR, isPermanent: true);
|
||||
|
||||
emitFailure(failureResponse: EMAIL_ERROR);
|
||||
} else if ( ! validatePassword(userRepository)) {
|
||||
} else if (!validatePassword(userRepository)) {
|
||||
passwordField.addFieldError(PASSWORD_ERROR, isPermanent: true);
|
||||
emitFailure(failureResponse: PASSWORD_ERROR);
|
||||
} else {
|
||||
@@ -50,12 +44,10 @@ class RegistrationFormBloc extends FormBloc<String, String> with Common {
|
||||
await userRepository.addUser();
|
||||
emitSuccess(canSubmitAgain: false);
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
Cache().initBadges();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
emitFailure(failureResponse: ex.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user