1.1.22+3 corrections

This commit is contained in:
bossanyit
2021-09-05 07:47:15 +02:00
parent cebd83648b
commit e34add8185
57 changed files with 1577 additions and 1490 deletions
+49
View File
@@ -0,0 +1,49 @@
import 'package:intl/intl.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/mautic.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/service/mautic.dart';
import 'package:aitrainer_app/util/app_language.dart';
class MauticRepository {
final CustomerRepository customerRepository;
const MauticRepository({required this.customerRepository});
Future<void> sendMauticSubscription() async {
Mautic mautic = Mautic();
mautic.formId = 2;
mautic.databaseId = Cache().userLoggedIn!.customerId!;
mautic.firstname = customerRepository.customer!.firstname == null ? "" : customerRepository.customer!.firstname!;
mautic.lastname = customerRepository.customer!.name == null ? "" : customerRepository.customer!.name!;
mautic.email = customerRepository.customer!.email == null ? "" : customerRepository.customer!.email!;
if (mautic.email == null || mautic.email!.contains("privaterelay.appleid.com")) {
return;
}
mautic.fitnessLevel = customerRepository.customer!.fitnessLevel == null ? "" : customerRepository.customer!.fitnessLevel!;
mautic.goal = customerRepository.customer!.goal == null ? "" : customerRepository.customer!.goal!;
mautic.subscriptionDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now());
mautic.language = AppLanguage().appLocal.languageCode;
await MauticApi().sendMauticForm(mautic);
customerRepository.customer!.syncedDate = DateTime.now();
await customerRepository.saveCustomer();
}
Future<void> sendMauticDataChange() async {
Mautic mautic = Mautic();
mautic.formId = 3;
mautic.databaseId = Cache().userLoggedIn!.customerId!;
mautic.firstname = customerRepository.customer!.firstname == null ? "" : customerRepository.customer!.firstname!;
mautic.lastname = customerRepository.customer!.name == null ? "" : customerRepository.customer!.name!;
mautic.email = customerRepository.customer!.email == null ? "" : customerRepository.customer!.email!;
if (mautic.email == null || mautic.email!.contains("privaterelay.appleid.com")) {
return;
}
mautic.fitnessLevel = customerRepository.customer!.fitnessLevel == null ? "" : customerRepository.customer!.fitnessLevel!;
mautic.goal = customerRepository.customer!.goal == null ? "" : customerRepository.customer!.goal!;
await MauticApi().sendMauticForm(mautic);
}
}
+21 -7
View File
@@ -63,6 +63,7 @@ class TrainingPlanRepository {
TrainingPlan? trainingPlan = this.getTrainingPlanById(trainingPlanId);
if (trainingPlan == null || trainingPlan.details == null) {
print("trainingPlan null");
return null;
}
@@ -274,14 +275,26 @@ class TrainingPlanRepository {
bool isWoman = Cache().userLoggedIn!.sex == "w";
if (Cache().userLoggedIn!.fitnessLevel == FitnessState.beginner) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_beginner") : getTrainingPlanByInternalName("beginner_man");
} else if (Cache().userLoggedIn!.fitnessLevel == FitnessState.intermediate) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_beginner_split") : getTrainingPlanByInternalName("beginner_split");
} else if (Cache().userLoggedIn!.fitnessLevel == FitnessState.advanced) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_advanced") : getTrainingPlanByInternalName("man_routine4");
if (Cache().userLoggedIn!.goal == "shape_forming") {
if (Cache().userLoggedIn!.fitnessLevel == FitnessState.beginner) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_beginner") : getTrainingPlanByInternalName("man_routine1");
} else if (Cache().userLoggedIn!.fitnessLevel == FitnessState.intermediate) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_beginner_split") : getTrainingPlanByInternalName("man_routine3");
} else if (Cache().userLoggedIn!.fitnessLevel == FitnessState.advanced) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_advanced") : getTrainingPlanByInternalName("man_routine4");
} else {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("man_routine2") : getTrainingPlanByInternalName("man_routine2");
}
} else {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("5day") : getTrainingPlanByInternalName("5day");
if (Cache().userLoggedIn!.fitnessLevel == FitnessState.beginner) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_beginner") : getTrainingPlanByInternalName("beginner_man");
} else if (Cache().userLoggedIn!.fitnessLevel == FitnessState.intermediate) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_beginner_split") : getTrainingPlanByInternalName("man_foundation");
} else if (Cache().userLoggedIn!.fitnessLevel == FitnessState.advanced) {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("woman_advanced") : getTrainingPlanByInternalName("basic_mass_building");
} else {
trainingPlanId = isWoman ? getTrainingPlanByInternalName("man_routine2") : getTrainingPlanByInternalName("mass_building");
}
}
print("Generated plan $trainingPlanId fitness ${Cache().userLoggedIn!.fitnessLevel} - ${FitnessState.beginner}");
@@ -290,6 +303,7 @@ class TrainingPlanRepository {
CustomerTrainingPlan? customerTrainingPlan = activateTrainingPlan(trainingPlanId);
if (customerTrainingPlan != null) {
Cache().myTrainingPlan = customerTrainingPlan;
Cache().saveMyTrainingPlan();
}
}
}