WT1.1.5 In-app-purchase
This commit is contained in:
@@ -31,11 +31,15 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
double bmr = 0;
|
||||
double goalBMI = 0;
|
||||
double goalWeight = 0;
|
||||
double goalMilestoneBMI = 0;
|
||||
double goalMilestoneWeight = 0;
|
||||
double bmiAngle = 0;
|
||||
double bmiTop = 0;
|
||||
double bmiLeft = 0;
|
||||
double weight;
|
||||
double height;
|
||||
double bmrEnergy = 0;
|
||||
int birthYear;
|
||||
String fitnessLevel;
|
||||
bool changedWeight = false;
|
||||
bool changedSizes = false;
|
||||
@@ -66,6 +70,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
customerRepository.customer = Cache().userLoggedIn;
|
||||
weight = customerRepository.customer.getProperty("Weight");
|
||||
height = customerRepository.customer.getProperty("Height");
|
||||
birthYear = customerRepository.customer.birthYear;
|
||||
fitnessLevel = customerRepository.customer.fitnessLevel;
|
||||
this.isMan = (customerRepository.customer.sex == "m");
|
||||
}
|
||||
@@ -315,6 +320,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
changedWeight = true;
|
||||
weight = event.value;
|
||||
getBMI();
|
||||
getGoalBMI();
|
||||
getBMR();
|
||||
yield ExerciseNewReady();
|
||||
} else if (event is ExerciseNewFitnessLevelChange) {
|
||||
@@ -324,12 +330,20 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
changedWeight = true;
|
||||
getBMR();
|
||||
yield ExerciseNewReady();
|
||||
} else if (event is ExerciseNewBirthyearChange) {
|
||||
yield ExerciseNewLoading();
|
||||
changedWeight = true;
|
||||
customerRepository.setBirthYear(event.value.toInt());
|
||||
birthYear = event.value;
|
||||
getBMR();
|
||||
yield ExerciseNewReady();
|
||||
} else if (event is ExerciseNewHeightChange) {
|
||||
yield ExerciseNewLoading();
|
||||
customerRepository.setHeight(event.value.toInt());
|
||||
changedWeight = true;
|
||||
height = event.value;
|
||||
getBMI();
|
||||
getGoalBMI();
|
||||
getBMR();
|
||||
yield ExerciseNewReady();
|
||||
} else if (event is ExerciseNewSaveWeight) {
|
||||
@@ -390,6 +404,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
//BMR = 655.1 + ( 9.563 × ömeg kg-ban ) + ( 1.85 × magasság cm-ben) − ( 4.676 × életkor évben kifejezve )
|
||||
bmr = 655.1 + (9.563 * weight) + (1.85 * height) - (4.676 * (year - customerRepository.customer.birthYear));
|
||||
}
|
||||
bmrEnergy = bmr;
|
||||
|
||||
if (customerRepository.customer.fitnessLevel == FitnessState.beginner) {
|
||||
bmr *= 1.2;
|
||||
@@ -424,32 +439,38 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
|
||||
this.bmiAngle = (bmi * 90 / 25) - 90;
|
||||
if (bmi < 18.5) {
|
||||
goalBMI = 19;
|
||||
goalMilestoneBMI = 19;
|
||||
goalBMI = 21.75;
|
||||
this.bmiTop = 99 * distortionHeight;
|
||||
this.bmiLeft = 77 * distortionWidth;
|
||||
bmiAngle = -62;
|
||||
} else if (bmi > 18.5 && bmi < 25) {
|
||||
goalBMI = this.bmi;
|
||||
goalBMI = 21.75;
|
||||
goalMilestoneBMI = 21.75;
|
||||
this.bmiTop = 48 * distortionHeight;
|
||||
this.bmiLeft = 130 * distortionWidth;
|
||||
bmiAngle = -23;
|
||||
} else if (bmi < 30 && bmi > 24.9) {
|
||||
goalBMI = 24;
|
||||
goalMilestoneBMI = 24;
|
||||
goalBMI = 21.75;
|
||||
this.bmiTop = 40.0 * distortionHeight;
|
||||
this.bmiLeft = 184.0 * distortionWidth;
|
||||
bmiAngle = 7.2;
|
||||
} else if (bmi < 34.9 && 29.9 < bmi) {
|
||||
goalBMI = 29;
|
||||
goalMilestoneBMI = 29;
|
||||
goalBMI = 24;
|
||||
bmiTop = 48 * distortionHeight;
|
||||
bmiLeft = 211 * distortionWidth;
|
||||
} else if (bmi > 35) {
|
||||
goalBMI = 34;
|
||||
goalMilestoneBMI = 34;
|
||||
goalBMI = 24;
|
||||
bmiTop = 94 * distortionHeight;
|
||||
bmiLeft = 260 * distortionWidth;
|
||||
bmiAngle = 59;
|
||||
}
|
||||
|
||||
this.goalWeight = goalBMI * (height * height / 10000);
|
||||
this.goalMilestoneWeight = goalMilestoneBMI * (height * height / 10000);
|
||||
|
||||
//print("Angle: " + bmiAngle.toStringAsFixed(1));
|
||||
|
||||
|
||||
@@ -28,6 +28,13 @@ class ExerciseNewQuantityUnitChange extends ExerciseNewEvent {
|
||||
List<Object> get props => [quantity];
|
||||
}
|
||||
|
||||
class ExerciseNewBirthyearChange extends ExerciseNewEvent {
|
||||
final int value;
|
||||
const ExerciseNewBirthyearChange({this.value});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class ExerciseNewWeightChange extends ExerciseNewEvent {
|
||||
final double value;
|
||||
const ExerciseNewWeightChange({this.value});
|
||||
|
||||
@@ -7,7 +7,6 @@ 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:flurry/flurry.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'exercise_plan_event.dart';
|
||||
|
||||
@@ -164,7 +164,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
ability = ExerciseAbility.endurance;
|
||||
break;
|
||||
case "Cardio":
|
||||
case "Body Compositions":
|
||||
case "My Body":
|
||||
ability = ExerciseAbility.none;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
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';
|
||||
@@ -38,6 +37,10 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
ResultBloc({this.resultRepository, this.exerciseRepository, this.context}) : super(ResultInitial()) {
|
||||
this.startTime = exerciseRepository.start;
|
||||
this.endTime = exerciseRepository.end;
|
||||
if (this.startTime == null) {
|
||||
this.startTime = exerciseRepository.exercise.dateAdd;
|
||||
exerciseRepository.start = exerciseRepository.exercise.dateAdd;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'dart:math' as 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/model/purchase.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/product_test_service.dart';
|
||||
import 'package:aitrainer_app/util/platform_purchase.dart';
|
||||
import 'package:aitrainer_app/service/purchase.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/purchases.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flurry/flurry.dart';
|
||||
import 'package:purchases_flutter/offering_wrapper.dart';
|
||||
|
||||
part 'sales_event.dart';
|
||||
part 'sales_state.dart';
|
||||
@@ -28,15 +31,34 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
try {
|
||||
if (event is SalesLoad) {
|
||||
yield SalesLoading();
|
||||
//Flurry.logEvent("SalesPageOpen");
|
||||
// await PlatformPurchaseApi().initPurchasePlatformState();
|
||||
// this.getProductSet();
|
||||
log("Load Sales");
|
||||
Common.sendMessage("Salespage Load");
|
||||
Flurry.logEvent("SalesPageOpen");
|
||||
//await PlatformPurchaseApi().initPurchasePlatform();
|
||||
await RevenueCatPurchases().getOfferings();
|
||||
this.getProductSet();
|
||||
yield SalesReady();
|
||||
} else if (event is SalesPurchase) {
|
||||
if (Cache().hasPurchased) {
|
||||
throw Exception("You have already a successfull subscription");
|
||||
}
|
||||
yield SalesLoading();
|
||||
final int productId = event.productId;
|
||||
trace("Requesting purchase for" + productId.toString());
|
||||
//Flurry.logEvent("PurchaseRequest");
|
||||
// PlatformPurchaseApi().purchase(getSelectedProduct(productId));
|
||||
log("Requesting purchase for: " + productId.toString());
|
||||
Flurry.logEvent("PurchaseRequest");
|
||||
final Product selectedProduct = this.getSelectedProduct(productId);
|
||||
log("SelectedProduct for purchase " + selectedProduct.toString());
|
||||
await RevenueCatPurchases().makePurchase(selectedProduct);
|
||||
if (Cache().hasPurchased) {
|
||||
Purchase purchase = Purchase(customerId: Cache().userLoggedIn.customerId, productId: productId);
|
||||
purchase.dateAdd = DateTime.now();
|
||||
purchase.purchaseSum = 0;
|
||||
purchase.currency = "EUR";
|
||||
await PurchaseApi().savePurchase(purchase);
|
||||
Flurry.logEvent("PurchaseSuccessful");
|
||||
Common.sendMessage("Purchase: " + purchase.toJson().toString());
|
||||
}
|
||||
yield SalesSuccessful();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield SalesError(message: ex.toString());
|
||||
@@ -53,18 +75,24 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
return prod;
|
||||
}
|
||||
|
||||
/* String getLocalizedPrice(String productId) {
|
||||
String getLocalizedPrice(String productId) {
|
||||
String price = "";
|
||||
for (var product in PlatformPurchaseApi().getIAPItems()) {
|
||||
if (Platform.isAndroid) {
|
||||
print("PlatformProduct " + product.toString());
|
||||
if (productId == product.productId) {
|
||||
price = product.localizedPrice;
|
||||
Offering offering = RevenueCatPurchases().offering;
|
||||
if (offering != null) {
|
||||
for (var package in offering.availablePackages) {
|
||||
log("PlatformProduct " + package.toString());
|
||||
if (productId == package.product.identifier) {
|
||||
price = package.product.priceString;
|
||||
if (price.contains(r'HUF')) {
|
||||
price = price.replaceAll(RegExp(r'HUF'), 'Ft');
|
||||
price = price.replaceAll(RegExp(r',00'), "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log(" !!! No Offering");
|
||||
}
|
||||
|
||||
return price;
|
||||
}
|
||||
|
||||
@@ -73,7 +101,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
this.tests = Cache().productTests;
|
||||
|
||||
if (tests.isEmpty) {
|
||||
var rand = Random.secure();
|
||||
var rand = math.Random.secure();
|
||||
productSet = rand.nextInt(5) + 1;
|
||||
} else {
|
||||
trace("Previous ProductTest: " + tests[0].toJson().toString());
|
||||
@@ -88,7 +116,9 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
}
|
||||
|
||||
ProductTest productTest = ProductTest();
|
||||
trace("ProductSet: " + productSet.toString());
|
||||
|
||||
productSet = 2;
|
||||
log("ProductSet: " + productSet.toString());
|
||||
for (var elem in Cache().products) {
|
||||
Product product = elem as Product;
|
||||
|
||||
@@ -109,5 +139,5 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
productTest.dateView = DateTime.now();
|
||||
//ProductTestApi().saveProductTest(productTest);
|
||||
//Cache().productTests.add(productTest);
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ class SalesReady extends SalesState {
|
||||
const SalesReady();
|
||||
}
|
||||
|
||||
class SalesSuccessful extends SalesState {
|
||||
const SalesSuccessful();
|
||||
}
|
||||
|
||||
class SalesError extends SalesState {
|
||||
final String message;
|
||||
const SalesError({this.message});
|
||||
|
||||
@@ -3,7 +3,6 @@ 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';
|
||||
|
||||
@@ -74,7 +74,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
|
||||
HealthDataType.RESTING_HEART_RATE
|
||||
];
|
||||
final HealthFactory health = HealthFactory(); */
|
||||
DateTime now = DateTime.now();
|
||||
//DateTime now = DateTime.now();
|
||||
//List<HealthDataPoint> _healthDataList = await health.getHealthDataFromTypes(now.subtract(Duration(minutes: 5)), now, types);
|
||||
//log(_healthDataList.toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user