WT1.1.0+40 Premium feature settings
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
@@ -18,19 +17,21 @@ class CustomExerciseFormBloc extends FormBloc<String, String> {
|
||||
);
|
||||
|
||||
//1RM calculated Fields
|
||||
final rmWendlerField = TextFieldBloc( initialValue: "0",);
|
||||
final rmMayhewField = TextFieldBloc( initialValue: "0");
|
||||
final rmOconnerField = TextFieldBloc( initialValue: "0");
|
||||
final rmWathenField = TextFieldBloc( initialValue: "0");
|
||||
final rmAverageField = TextFieldBloc( initialValue: "0");
|
||||
final rm90Field = TextFieldBloc( initialValue: "0");
|
||||
final rm80Field = TextFieldBloc( initialValue: "0");
|
||||
final rm75Field = TextFieldBloc( initialValue: "0");
|
||||
final rm75WendlerField = TextFieldBloc( initialValue: "0");
|
||||
final rm75OconnorField = TextFieldBloc( initialValue: "0");
|
||||
final rm70Field = TextFieldBloc( initialValue: "0");
|
||||
final rm60Field = TextFieldBloc( initialValue: "0");
|
||||
final rm50Field = TextFieldBloc( initialValue: "0");
|
||||
final rmWendlerField = TextFieldBloc(
|
||||
initialValue: "0",
|
||||
);
|
||||
final rmMayhewField = TextFieldBloc(initialValue: "0");
|
||||
final rmOconnerField = TextFieldBloc(initialValue: "0");
|
||||
final rmWathenField = TextFieldBloc(initialValue: "0");
|
||||
final rmAverageField = TextFieldBloc(initialValue: "0");
|
||||
final rm90Field = TextFieldBloc(initialValue: "0");
|
||||
final rm80Field = TextFieldBloc(initialValue: "0");
|
||||
final rm75Field = TextFieldBloc(initialValue: "0");
|
||||
final rm75WendlerField = TextFieldBloc(initialValue: "0");
|
||||
final rm75OconnorField = TextFieldBloc(initialValue: "0");
|
||||
final rm70Field = TextFieldBloc(initialValue: "0");
|
||||
final rm60Field = TextFieldBloc(initialValue: "0");
|
||||
final rm50Field = TextFieldBloc(initialValue: "0");
|
||||
|
||||
CustomExerciseFormBloc({this.exerciseRepository}) {
|
||||
addFieldBlocs(fieldBlocs: [
|
||||
@@ -64,7 +65,6 @@ class CustomExerciseFormBloc extends FormBloc<String, String> {
|
||||
|
||||
@override
|
||||
void onSubmitting() async {
|
||||
print("on Submitting Custom form");
|
||||
try {
|
||||
emitLoading(progress: 30);
|
||||
// Emit either Loaded or Error
|
||||
@@ -78,30 +78,27 @@ class CustomExerciseFormBloc extends FormBloc<String, String> {
|
||||
void calculate1RM() {
|
||||
double weight = exerciseRepository.exercise.unitQuantity;
|
||||
double repeat = exerciseRepository.exercise.quantity;
|
||||
if ( weight == 0 || repeat == 0) {
|
||||
if (weight == 0 || repeat == 0) {
|
||||
return;
|
||||
}
|
||||
print("Calculating 1RM");
|
||||
exerciseRepository.rmWendler = weight * repeat * 0.0333 + weight;
|
||||
rmWendlerField.updateValue(exerciseRepository.rmWendler.toStringAsFixed(1));
|
||||
exerciseRepository.rmOconner = weight * (1 + repeat / 40);
|
||||
rmOconnerField.updateValue(exerciseRepository.rmOconner.toStringAsFixed(1));
|
||||
exerciseRepository.rmMayhew =
|
||||
100 * weight / (52.2 + 41.9 * pow(e, -0.055 * repeat));
|
||||
exerciseRepository.rmMayhew = 100 * weight / (52.2 + 41.9 * pow(e, -0.055 * repeat));
|
||||
rmMayhewField.updateValue(exerciseRepository.rmMayhew.toStringAsFixed(1));
|
||||
exerciseRepository.rmWathen =
|
||||
100 * weight / (48.8 + 53.8 * pow(e, -0.075 * repeat));
|
||||
exerciseRepository.rmWathen = 100 * weight / (48.8 + 53.8 * pow(e, -0.075 * repeat));
|
||||
rmWathenField.updateValue(exerciseRepository.rmWathen.toStringAsFixed(1));
|
||||
double average = (exerciseRepository.rmWendler + exerciseRepository.rmOconner)/2;
|
||||
double average = (exerciseRepository.rmWendler + exerciseRepository.rmOconner) / 2;
|
||||
rmAverageField.updateValue(average.toStringAsFixed(1));
|
||||
rm90Field.updateValue((average*0.9).toStringAsFixed(1));
|
||||
rm80Field.updateValue((average*0.8).toStringAsFixed(1));
|
||||
rm75Field.updateValue((average*0.75).toStringAsFixed(1));
|
||||
rm75OconnorField.updateValue((exerciseRepository.rmOconner*0.75).toStringAsFixed(1));
|
||||
rm75WendlerField.updateValue((exerciseRepository.rmWendler*0.75).toStringAsFixed(1));
|
||||
rm70Field.updateValue((average*0.7).toStringAsFixed(1));
|
||||
rm60Field.updateValue((average*0.6).toStringAsFixed(1));
|
||||
rm50Field.updateValue((average*0.5).toStringAsFixed(1));
|
||||
rm90Field.updateValue((average * 0.9).toStringAsFixed(1));
|
||||
rm80Field.updateValue((average * 0.8).toStringAsFixed(1));
|
||||
rm75Field.updateValue((average * 0.75).toStringAsFixed(1));
|
||||
rm75OconnorField.updateValue((exerciseRepository.rmOconner * 0.75).toStringAsFixed(1));
|
||||
rm75WendlerField.updateValue((exerciseRepository.rmWendler * 0.75).toStringAsFixed(1));
|
||||
rm70Field.updateValue((average * 0.7).toStringAsFixed(1));
|
||||
rm60Field.updateValue((average * 0.6).toStringAsFixed(1));
|
||||
rm50Field.updateValue((average * 0.5).toStringAsFixed(1));
|
||||
}
|
||||
|
||||
//@override
|
||||
|
||||
@@ -104,7 +104,6 @@ class CustomerChangeFormBloc extends FormBloc<String, String> {
|
||||
|
||||
@override
|
||||
void onSubmitting() async {
|
||||
print("on Submitting Customer Change form");
|
||||
try {
|
||||
emitLoading(progress: 30);
|
||||
// Emit either Loaded or Error
|
||||
|
||||
@@ -29,13 +29,11 @@ class CustomerExerciseDeviceBloc extends Bloc<CustomerExerciseDeviceEvent, Custo
|
||||
yield CustomerExerciseDeviceReady();
|
||||
} else if (event is CustomerExerciseDeviceAdd) {
|
||||
yield CustomerExerciseDeviceLoading();
|
||||
print("Add device " + event.device.exerciseDeviceId.toString());
|
||||
//await Future.delayed(const Duration(seconds: 2), () => "2");
|
||||
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();
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/calculate.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/group_data.dart';
|
||||
@@ -48,18 +49,16 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
|
||||
GroupDate({this.inputList, this.outputList});
|
||||
|
||||
|
||||
|
||||
double getQuantityByDate(Exercise exercise) {
|
||||
double sum = 0;
|
||||
if ( this.diagramType == DiagramType.sumMass ) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
if (this.diagramType == DiagramType.sumMass) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = exercise.quantity * exercise.unitQuantity;
|
||||
} else {
|
||||
sum = exercise.quantity;
|
||||
}
|
||||
} else if ( this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent ) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
} else if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
} else {
|
||||
sum = exercise.quantity;
|
||||
@@ -93,8 +92,8 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
Exercise tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
if ( this.checkNewType(element)) {
|
||||
if ( _origDatePart == null ) {
|
||||
if (this.checkNewType(element)) {
|
||||
if (_origDatePart == null) {
|
||||
this.addTempData(element);
|
||||
} else {
|
||||
this.temp2Output(_origExercise);
|
||||
@@ -105,7 +104,7 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
this.addTempData(element);
|
||||
}
|
||||
});
|
||||
if ( tempExercise != null) {
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise);
|
||||
}
|
||||
}
|
||||
@@ -134,7 +133,6 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
=========== CHART DATA CLASS
|
||||
*/
|
||||
class GroupChart extends GroupData with Calculate {
|
||||
|
||||
final List<dynamic> inputList;
|
||||
LinkedHashMap<int, ChartDataExtended> outputList = LinkedHashMap();
|
||||
|
||||
@@ -149,7 +147,7 @@ class GroupChart extends GroupData with Calculate {
|
||||
GroupChart({this.inputList, this.outputList});
|
||||
|
||||
double getBasePercent(Exercise exercise) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
this._basePercent = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
} else {
|
||||
this._basePercent = exercise.quantity;
|
||||
@@ -160,14 +158,14 @@ class GroupChart extends GroupData with Calculate {
|
||||
double getDiagramValue(Exercise exercise) {
|
||||
double value = 0;
|
||||
|
||||
if ( diagramType == DiagramType.percent) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
if (diagramType == DiagramType.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
double oneRepMax = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
value = (oneRepMax / this._basePercent) * 100;
|
||||
} else {
|
||||
value = (exercise.quantity / this._basePercent ) * 100;
|
||||
value = (exercise.quantity / this._basePercent) * 100;
|
||||
}
|
||||
} else if ( diagramType == DiagramType.oneRepMax || diagramType == DiagramType.sumMass) {
|
||||
} else if (diagramType == DiagramType.oneRepMax || diagramType == DiagramType.sumMass) {
|
||||
value = exercise.calculated;
|
||||
}
|
||||
return value;
|
||||
@@ -175,7 +173,6 @@ class GroupChart extends GroupData with Calculate {
|
||||
|
||||
@override
|
||||
void addTempData(Exercise exercise) {
|
||||
|
||||
double diagramValue = this.getDiagramValue(exercise);
|
||||
|
||||
if (_maxData < diagramValue) {
|
||||
@@ -185,32 +182,27 @@ class GroupChart extends GroupData with Calculate {
|
||||
_minData = diagramValue;
|
||||
}
|
||||
|
||||
BarChartGroupData data = BarChartGroupData(
|
||||
x: exercise.dateAdd.millisecondsSinceEpoch,
|
||||
barRods: [
|
||||
BarChartRodData(y: diagramValue, width: 12, colors: [Colors.lightBlue, Colors.lightBlueAccent])
|
||||
]
|
||||
);
|
||||
BarChartGroupData data = BarChartGroupData(x: exercise.dateAdd.millisecondsSinceEpoch, barRods: [
|
||||
BarChartRodData(y: diagramValue, width: 12, colors: [Colors.lightBlue, Colors.lightBlueAccent])
|
||||
]);
|
||||
_chartData.add(data);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId;
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkNewType(Exercise exercise) {
|
||||
return _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
return _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
|
||||
this.resetTemp();
|
||||
Exercise tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
|
||||
if ( this.checkNewType(element)) {
|
||||
if ( _origExerciseTypeId == null ) {
|
||||
if (this.checkNewType(element)) {
|
||||
if (_origExerciseTypeId == null) {
|
||||
_basePercent = getBasePercent(element);
|
||||
this.addTempData(element);
|
||||
} else {
|
||||
@@ -223,7 +215,7 @@ class GroupChart extends GroupData with Calculate {
|
||||
this.addTempData(element);
|
||||
}
|
||||
});
|
||||
if ( tempExercise != null) {
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise);
|
||||
}
|
||||
}
|
||||
@@ -234,9 +226,8 @@ class GroupChart extends GroupData with Calculate {
|
||||
int gridInterval = (dInterval / 3).floor();
|
||||
|
||||
ChartDataExtended extended;
|
||||
if ( outputList[_origExerciseTypeId] == null ) {
|
||||
extended = ChartDataExtended(
|
||||
data: _chartData, interval: dInterval, gridInterval: gridInterval);
|
||||
if (outputList[_origExerciseTypeId] == null) {
|
||||
extended = ChartDataExtended(data: _chartData, interval: dInterval, gridInterval: gridInterval);
|
||||
outputList[_origExerciseTypeId] = extended;
|
||||
} else {
|
||||
extended = outputList[_origExerciseTypeId];
|
||||
@@ -252,7 +243,6 @@ class GroupChart extends GroupData with Calculate {
|
||||
_maxData = 0;
|
||||
_chartData = List();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ChartDataExtended {
|
||||
@@ -272,7 +262,6 @@ class ChartDataExtended {
|
||||
};
|
||||
listBarChartData.add(barChartData);
|
||||
});
|
||||
|
||||
});
|
||||
var chartData = {
|
||||
"data": listBarChartData.toString(),
|
||||
@@ -281,10 +270,9 @@ class ChartDataExtended {
|
||||
};
|
||||
return chartData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Calculate {
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Calculate, Logging {
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
LinkedHashMap<int, ChartDataExtended> listChartData = LinkedHashMap();
|
||||
@@ -294,12 +282,9 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
double basePercent = 0;
|
||||
|
||||
@override
|
||||
DevelopmentByMuscleBloc({
|
||||
this.workoutTreeRepository}) :
|
||||
super(DevelopmentByMuscleStateInitial());
|
||||
DevelopmentByMuscleBloc({this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
|
||||
workoutTreeRepository.sortedTree = null;
|
||||
workoutTreeRepository.sortByMuscleType();
|
||||
|
||||
@@ -311,7 +296,6 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
});
|
||||
|
||||
this.getChartData();
|
||||
|
||||
}
|
||||
|
||||
void getChartData() {
|
||||
@@ -331,21 +315,18 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
groupChart.iteration();
|
||||
listChartData = groupChart.outputList;
|
||||
|
||||
|
||||
listChartData.forEach((key, value) {
|
||||
print ("typeid " + key.toString() + " chardata " + value.toJson().toString());
|
||||
trace("typeid " + key.toString() + " chardata " + value.toJson().toString());
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<Exercise> groupByDate(List<Exercise> exercises) {
|
||||
List<Exercise> groupedExercises = List();
|
||||
|
||||
exercises = sort(exercises, false);
|
||||
exercises.forEach((exercise) {
|
||||
print ("Date exercise " + exercise.toJsonDatePart().toString());
|
||||
trace("Date exercise " + exercise.toJsonDatePart().toString());
|
||||
});
|
||||
|
||||
GroupDate groupDate = GroupDate(inputList: exercises, outputList: groupedExercises);
|
||||
@@ -358,12 +339,11 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
print("Grouped " + element.toJsonDatePart().toString());
|
||||
});*/
|
||||
|
||||
|
||||
return groupedExercises;
|
||||
}
|
||||
|
||||
List<Exercise> sort(List<Exercise> exercises, bool asc) {
|
||||
exercises.sort( (a, b) {
|
||||
exercises.sort((a, b) {
|
||||
var aDateId = a.exerciseTypeId.toString() + "_" + a.datePart.toString();
|
||||
var bDateId = b.exerciseTypeId.toString() + "_" + b.datePart.toString();
|
||||
|
||||
@@ -383,13 +363,13 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
await getData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if ( event is DevelopmentByMuscleDiagramTypeChange ) {
|
||||
} else if (event is DevelopmentByMuscleDiagramTypeChange) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String type = event.diagramType;
|
||||
this.diagramType = type;
|
||||
getChartData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if ( event is DevelopmentByMuscleDateRateChange ) {
|
||||
} else if (event is DevelopmentByMuscleDateRateChange) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String dateRate = event.dateRate;
|
||||
this.dateRate = dateRate;
|
||||
|
||||
@@ -59,14 +59,14 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
if (event.step == step) {
|
||||
step++;
|
||||
scrollOffset = step * 200.0;
|
||||
print("step " +
|
||||
/* print("step " +
|
||||
step.toString() +
|
||||
" quantity " +
|
||||
quantity.toString() +
|
||||
" origQuantity: " +
|
||||
origQuantity.toString() +
|
||||
" scrollOffset: " +
|
||||
scrollOffset.toString());
|
||||
scrollOffset.toString()); */
|
||||
repeats.add(quantity);
|
||||
quantity = origQuantity;
|
||||
exerciseRepository.end = DateTime.now();
|
||||
|
||||
@@ -71,7 +71,6 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
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++;
|
||||
|
||||
@@ -343,8 +343,6 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
|
||||
}
|
||||
final double distortionWidth = mediaWidth / baseWidth;
|
||||
final double distortionHeight = mediaHeight / baseHeight;
|
||||
print("W m " + mediaWidth.toString() + " b" + baseWidth.toString() + " d: " + distortionWidth.toString());
|
||||
print("H m " + mediaHeight.toString() + " b" + baseHeight.toString() + " d: " + distortionHeight.toString());
|
||||
this.bmiAngle = (bmi * 90 / 25) - 90;
|
||||
if (bmi < 18.5) {
|
||||
goalBMI = 19;
|
||||
|
||||
@@ -25,16 +25,16 @@ class ExercisePlanCustomAddBloc extends Bloc<ExercisePlanCustomAddEvent, Exercis
|
||||
double quantity;
|
||||
double serie;
|
||||
double quantityUnit;
|
||||
|
||||
|
||||
@override
|
||||
ExercisePlanCustomAddBloc({this.exercisePlanRepository, this.planBloc, this.workoutMenuTree}) : super(ExercisePlanCustomAddInitial()) {
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutMenuTree.exerciseType);
|
||||
quantity = exercisePlanRepository.getActualPlanDetail().repeats != null ?
|
||||
exercisePlanRepository.getActualPlanDetail().repeats.toDouble() : 12;
|
||||
serie = exercisePlanRepository.getActualPlanDetail().serie != null ?
|
||||
exercisePlanRepository.getActualPlanDetail().serie.toDouble() : 3;
|
||||
quantityUnit = exercisePlanRepository.getActualPlanDetail().weightEquation != null ?
|
||||
double.parse(exercisePlanRepository.getActualPlanDetail().weightEquation) : 30;
|
||||
quantity =
|
||||
exercisePlanRepository.getActualPlanDetail().repeats != null ? exercisePlanRepository.getActualPlanDetail().repeats.toDouble() : 12;
|
||||
serie = exercisePlanRepository.getActualPlanDetail().serie != null ? exercisePlanRepository.getActualPlanDetail().serie.toDouble() : 3;
|
||||
quantityUnit = exercisePlanRepository.getActualPlanDetail().weightEquation != null
|
||||
? double.parse(exercisePlanRepository.getActualPlanDetail().weightEquation)
|
||||
: 30;
|
||||
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation = quantityUnit.toString();
|
||||
exercisePlanRepository.getActualPlanDetail().serie = serie.toInt();
|
||||
@@ -47,24 +47,24 @@ class ExercisePlanCustomAddBloc extends Bloc<ExercisePlanCustomAddEvent, Exercis
|
||||
if (event is ExercisePlanCustomAddLoad) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddChangeSerie ) {
|
||||
} else if (event is ExercisePlanCustomAddChangeSerie) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
serie = event.quantity;
|
||||
exercisePlanRepository.getActualPlanDetail().serie = event.quantity.toInt();
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddChangeQuantity ) {
|
||||
} else if (event is ExercisePlanCustomAddChangeQuantity) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
quantity = event.quantity;
|
||||
exercisePlanRepository.getActualPlanDetail().repeats = event.quantity.toInt();
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddChangeQuantityUnit ) {
|
||||
} else if (event is ExercisePlanCustomAddChangeQuantityUnit) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
quantityUnit = event.quantity;
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation = event.quantity.toStringAsFixed(0);
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddSubmit) {
|
||||
} else if (event is ExercisePlanCustomAddSubmit) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
if ( exercisePlanRepository.exercisePlanDetails[exercisePlanRepository.getActualPlanDetail()] == null ) {
|
||||
if (exercisePlanRepository.exercisePlanDetails[exercisePlanRepository.getActualPlanDetail()] == null) {
|
||||
exercisePlanRepository.getActualPlanDetail().change = ExercisePlanDetailChange.add;
|
||||
} else {
|
||||
exercisePlanRepository.getActualPlanDetail().change = ExercisePlanDetailChange.update;
|
||||
@@ -72,9 +72,8 @@ class ExercisePlanCustomAddBloc extends Bloc<ExercisePlanCustomAddEvent, Exercis
|
||||
exercisePlanRepository.addDetailToPlan();
|
||||
planBloc.add(ExercisePlanAddExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()));
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddRemove ) {
|
||||
} else if (event is ExercisePlanCustomAddRemove) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
print("Remove " + exercisePlanRepository.getActualPlanDetail().exerciseType.name);
|
||||
exercisePlanRepository.getActualPlanDetail().change = ExercisePlanDetailChange.delete;
|
||||
planBloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()));
|
||||
|
||||
|
||||
@@ -47,11 +47,8 @@ class LoginFormBloc extends FormBloc<String, String> with Common {
|
||||
} else {
|
||||
// Emit either Loaded or Error
|
||||
await PropertyApi().getProperties();
|
||||
print("properties OK");
|
||||
await userRepository.getUser();
|
||||
print("get User OK");
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
print("exerciesTypes OK");
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
if (Cache().userLoggedIn != null && Cache().userLoggedIn.customerId > 0) {
|
||||
ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_device_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -16,7 +17,7 @@ import 'package:meta/meta.dart';
|
||||
part 'menu_event.dart';
|
||||
part 'menu_state.dart';
|
||||
|
||||
class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans {
|
||||
class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
final WorkoutTreeRepository menuTreeRepository;
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
ExerciseDeviceRepository exerciseDeviceRepository = ExerciseDeviceRepository();
|
||||
@@ -48,7 +49,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans {
|
||||
}
|
||||
if (context == null) return;
|
||||
percent = percent * 100;
|
||||
print("Percent " + percent.toString());
|
||||
log("Percent " + percent.toString());
|
||||
if (percent == -1 || percent == 0) {
|
||||
infoTitle = t("Greetings!");
|
||||
infoText = t("The purpose is to measure you physical condition") +
|
||||
@@ -69,7 +70,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans {
|
||||
|
||||
menuTreeRepository.sortByMuscleType();
|
||||
missingTreeName = exerciseRepository.nextMissingBaseExercise(menuTreeRepository.sortedTree);
|
||||
//print("Missing " + missingTreeName);
|
||||
//log("Missing " + missingTreeName);
|
||||
if (missingTreeName != null) {
|
||||
if (percent > 0) {
|
||||
infoText = t("Please continue your tests with a") + " '" + missingTreeName + "' " + t("exercise!");
|
||||
@@ -163,7 +164,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans {
|
||||
ability = ExerciseAbility.none;
|
||||
break;
|
||||
}
|
||||
print("Ability: " + ability.toString() + " name:" + name);
|
||||
log("Ability: " + ability.toString() + " name:" + name);
|
||||
}
|
||||
|
||||
bool selectedDevice(int deviceId) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/result.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_result_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
@@ -12,7 +13,7 @@ import 'package:health/health.dart';
|
||||
part 'result_event.dart';
|
||||
part 'result_state.dart';
|
||||
|
||||
class ResultBloc extends Bloc<ResultEvent, ResultState> {
|
||||
class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
final ExerciseResultRepository resultRepository;
|
||||
final ExerciseRepository exerciseRepository;
|
||||
List<HealthDataPoint> _healthDataList = List();
|
||||
@@ -46,6 +47,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> {
|
||||
|
||||
await _fetchHealthData();
|
||||
_matchExerciseData();
|
||||
await resultRepository.saveExerciseResults();
|
||||
yield ResultReady();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
@@ -55,25 +57,28 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> {
|
||||
|
||||
void _matchExerciseData() {
|
||||
resultRepository.getResults().forEach((element) {
|
||||
element.dateFrom = startTime;
|
||||
element.dateTo = endTime;
|
||||
element.exerciseId = exerciseRepository.actualExerciseList[0].exerciseId;
|
||||
switch (element.item) {
|
||||
case ResultItem.bpm_avg:
|
||||
element.data = _gethHealthDataPointValueAvg(HealthDataType.HEART_RATE).toStringAsFixed(0);
|
||||
element.data = _gethHealthDataPointValueAvg(HealthDataType.HEART_RATE);
|
||||
break;
|
||||
case ResultItem.bpm_min:
|
||||
element.data = element.data = _gethHealthDataPointValueMin(HealthDataType.HEART_RATE).toStringAsFixed(0);
|
||||
element.data = element.data = _gethHealthDataPointValueMin(HealthDataType.HEART_RATE);
|
||||
break;
|
||||
case ResultItem.bpm_max:
|
||||
element.data = element.data = _gethHealthDataPointValueMax(HealthDataType.HEART_RATE).toStringAsFixed(0);
|
||||
element.data = element.data = _gethHealthDataPointValueMax(HealthDataType.HEART_RATE);
|
||||
break;
|
||||
case ResultItem.calorie:
|
||||
element.data = _gethHealthDataPointValueSum(HealthDataType.ACTIVE_ENERGY_BURNED).toStringAsFixed(0);
|
||||
element.data = _gethHealthDataPointValueSum(HealthDataType.ACTIVE_ENERGY_BURNED);
|
||||
break;
|
||||
case ResultItem.development_percent_bodypart:
|
||||
// TODO: Handle this case.
|
||||
break;
|
||||
case ResultItem.distance:
|
||||
if (exerciseRepository.exerciseType.unit == "meter") {
|
||||
element.data = exerciseRepository.exercise.quantity.toStringAsFixed(0);
|
||||
element.data = exerciseRepository.exercise.quantity;
|
||||
}
|
||||
break;
|
||||
case ResultItem.fatburn_percent:
|
||||
@@ -92,9 +97,9 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> {
|
||||
}
|
||||
});
|
||||
if (counter > 0) {
|
||||
element.data = (burnCounter / counter * 100).toStringAsFixed(2);
|
||||
element.data = (burnCounter / counter * 100);
|
||||
} else {
|
||||
element.data = "0";
|
||||
element.data = 0;
|
||||
}
|
||||
break;
|
||||
case ResultItem.speed_max:
|
||||
@@ -106,11 +111,11 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> {
|
||||
exerciseRepository.actualExerciseList.forEach((element) {
|
||||
value += element.quantity;
|
||||
});
|
||||
element.data = value.toStringAsFixed(0);
|
||||
element.data = value;
|
||||
}
|
||||
break;
|
||||
case ResultItem.steps:
|
||||
element.data = _gethHealthDataPointValueSum(HealthDataType.STEPS).toStringAsFixed(0);
|
||||
element.data = _gethHealthDataPointValueSum(HealthDataType.STEPS);
|
||||
break;
|
||||
/* case ResultItem.time:
|
||||
final Duration duration = this.endTime.difference(this.startTime);
|
||||
@@ -122,7 +127,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> {
|
||||
exerciseRepository.actualExerciseList.forEach((element) {
|
||||
value += element.quantity * element.unitQuantity;
|
||||
});
|
||||
element.data = value.toStringAsFixed(0);
|
||||
element.data = value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -195,13 +200,13 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
print("Get Health data between " + startTime.toString() + " AND " + endTime.toString());
|
||||
log("Get Health data between " + startTime.toString() + " AND " + endTime.toString());
|
||||
_healthDataList = await health.getHealthDataFromTypes(this.startTime, this.endTime, types);
|
||||
_healthDataList.forEach((element) {
|
||||
print(element.toString());
|
||||
log(element.toString());
|
||||
});
|
||||
} on Exception catch (e) {
|
||||
print("Caught exception in getHealthDataFromTypes: $e");
|
||||
log("Caught exception in getHealthDataFromTypes: $e");
|
||||
throw Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/product.dart';
|
||||
import 'package:aitrainer_app/model/product_test.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/product_test_service.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'sales_event.dart';
|
||||
part 'sales_state.dart';
|
||||
|
||||
class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
List<ProductTest> tests = List();
|
||||
List<Product> product2Display = List();
|
||||
int productSet = -1;
|
||||
SalesBloc() : super(SalesInitial());
|
||||
|
||||
@override
|
||||
Stream<SalesState> mapEventToState(
|
||||
SalesEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (event is SalesLoad) {
|
||||
yield SalesLoading();
|
||||
this.getProductSet();
|
||||
yield SalesReady();
|
||||
} else if (event is SalesPurchase) {
|
||||
final int productId = event.productId;
|
||||
trace("Requesting purchase for" + productId.toString());
|
||||
//PlatformPurchaseApi().requestPurchase(null);
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield SalesError(message: ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void getProductSet() {
|
||||
int productId = 0;
|
||||
this.tests = Cache().productTests;
|
||||
|
||||
if (tests.isEmpty) {
|
||||
var rand = Random.secure();
|
||||
productSet = rand.nextInt(5) + 1;
|
||||
} else {
|
||||
trace("Previous ProductTest: " + tests[0].toJson().toString());
|
||||
productId = tests[0].productId;
|
||||
for (var elem in Cache().products) {
|
||||
Product product = elem as Product;
|
||||
if (product.productId == productId) {
|
||||
productSet = product.productSet;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProductTest productTest = ProductTest();
|
||||
trace("ProductSet: " + productSet.toString());
|
||||
for (var elem in Cache().products) {
|
||||
Product product = elem as Product;
|
||||
if (product.productSet == productSet) {
|
||||
productId = product.productId;
|
||||
product2Display.add(product);
|
||||
}
|
||||
}
|
||||
|
||||
product2Display.sort((a, b) {
|
||||
return a.sort < b.sort ? a.sort : b.sort;
|
||||
});
|
||||
|
||||
productTest.productId = productId;
|
||||
productTest.customerId = Cache().userLoggedIn.customerId;
|
||||
productTest.dateView = DateTime.now();
|
||||
ProductTestApi().saveProductTest(productTest);
|
||||
Cache().productTests.add(productTest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
part of 'sales_bloc.dart';
|
||||
|
||||
abstract class SalesEvent extends Equatable {
|
||||
const SalesEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SalesLoad extends SalesEvent {
|
||||
const SalesLoad();
|
||||
}
|
||||
|
||||
class SalesPurchase extends SalesEvent {
|
||||
final int productId;
|
||||
const SalesPurchase({this.productId});
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
part of 'sales_bloc.dart';
|
||||
|
||||
abstract class SalesState extends Equatable {
|
||||
const SalesState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SalesInitial extends SalesState {
|
||||
const SalesInitial();
|
||||
}
|
||||
|
||||
class SalesLoading extends SalesState {
|
||||
const SalesLoading();
|
||||
}
|
||||
|
||||
class SalesReady extends SalesState {
|
||||
const SalesReady();
|
||||
}
|
||||
|
||||
class SalesError extends SalesState {
|
||||
final String message;
|
||||
const SalesError({this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
@@ -2,16 +2,18 @@ import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/bloc/settings/settings_bloc.dart';
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/platform_purchase.dart';
|
||||
import 'package:aitrainer_app/util/session.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'session_event.dart';
|
||||
part 'session_state.dart';
|
||||
|
||||
class SessionBloc extends Bloc<SessionEvent, SessionState> {
|
||||
class SessionBloc extends Bloc<SessionEvent, SessionState> with Logging {
|
||||
final Session session;
|
||||
|
||||
SessionBloc({this.session}) : super(SessionInitial());
|
||||
|
||||
@override
|
||||
@@ -20,23 +22,26 @@ class SessionBloc extends Bloc<SessionEvent, SessionState> {
|
||||
) async* {
|
||||
try {
|
||||
if (event is SessionStart) {
|
||||
log(" -------- Session starting...");
|
||||
yield SessionLoading();
|
||||
// ignore: close_sinks
|
||||
SettingsBloc settingsBloc = event.settingsBloc;
|
||||
await session.fetchSessionAndNavigate();
|
||||
await PlatformPurchaseApi().initPurchasePlatformState();
|
||||
String lang = AppLanguage().appLocal.languageCode;
|
||||
print("Change lang to $lang");
|
||||
log("Change lang to $lang");
|
||||
settingsBloc.add(SettingsChangeLanguage(language: lang));
|
||||
yield SessionReady();
|
||||
}
|
||||
} on Exception catch(ex) {
|
||||
} on Exception catch (ex) {
|
||||
yield SessionFailure(message: ex.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await this.close(); super.close();
|
||||
await this.close();
|
||||
PlatformPurchaseApi().close();
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
part of 'session_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class SessionEvent extends Equatable {
|
||||
const SessionEvent();
|
||||
|
||||
@@ -15,4 +14,3 @@ class SessionStart extends SessionEvent {
|
||||
@override
|
||||
List<Object> get props => [settingsBloc];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
part of 'session_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class SessionState extends Equatable {
|
||||
const SessionState();
|
||||
|
||||
@@ -26,7 +25,4 @@ class SessionFailure extends SessionState {
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/localization/app_localization.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -12,7 +13,7 @@ import 'package:meta/meta.dart';
|
||||
part 'settings_event.dart';
|
||||
part 'settings_state.dart';
|
||||
|
||||
class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
|
||||
class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
|
||||
String language;
|
||||
Locale _locale;
|
||||
BuildContext context;
|
||||
@@ -48,7 +49,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
|
||||
yield SettingsLoading();
|
||||
|
||||
bool selectedHardwareBefore = await Cache().selectedHardwareBefore();
|
||||
print("selectedBefore " + selectedHardwareBefore.toString());
|
||||
log("selectedBefore " + selectedHardwareBefore.toString());
|
||||
if (!selectedHardwareBefore) {
|
||||
await _accessHealthData();
|
||||
}
|
||||
@@ -73,11 +74,11 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
|
||||
final HealthFactory health = HealthFactory();
|
||||
DateTime now = DateTime.now();
|
||||
List<HealthDataPoint> _healthDataList = await health.getHealthDataFromTypes(now.subtract(Duration(minutes: 5)), now, types);
|
||||
print(_healthDataList.toString());
|
||||
log(_healthDataList.toString());
|
||||
}
|
||||
|
||||
Future<void> _changeLang(String lang) async {
|
||||
print("_change to $lang");
|
||||
log("_change to $lang");
|
||||
switch (lang) {
|
||||
case "English":
|
||||
case "en":
|
||||
@@ -97,15 +98,15 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
|
||||
|
||||
Future<void> loadLang() async {
|
||||
if (_locale != null) {
|
||||
print(" -- Loading lang $_locale");
|
||||
log(" -- Loading lang $_locale");
|
||||
if (context != null) {
|
||||
AppLocalizations.of(context).setLocale(_locale);
|
||||
await AppLocalizations.of(context).load();
|
||||
} else {
|
||||
print("no context, does not load");
|
||||
log("no context, does not load");
|
||||
}
|
||||
} else {
|
||||
print("no locale, does not load");
|
||||
log("no locale, does not load");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user