WT 1.1.14+2 sales page update
This commit is contained in:
@@ -6,6 +6,7 @@ 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/repository/description_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/purchase_service.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
@@ -13,6 +14,7 @@ import 'package:aitrainer_app/util/purchases.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:firebase_remote_config/firebase_remote_config.dart';
|
||||
import 'package:purchases_flutter/offering_wrapper.dart';
|
||||
|
||||
part 'sales_event.dart';
|
||||
@@ -22,8 +24,29 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
List<ProductTest>? tests = [];
|
||||
List<Product> product2Display = [];
|
||||
int productSet = -1;
|
||||
final DescriptionRepository descriptionRepository = DescriptionRepository();
|
||||
SalesBloc() : super(SalesInitial());
|
||||
|
||||
String? salesText;
|
||||
|
||||
String salesButtonText = "<h1>Workout Test Monthly</h1><p>localizedPrice</p><p><small>cancel any time</small></p>";
|
||||
Product? offeredProduct;
|
||||
|
||||
Product? getProductByName(String name) {
|
||||
Product? product;
|
||||
if (product2Display.isNotEmpty) {
|
||||
product2Display.forEach((element) {
|
||||
if (element.type == name) {
|
||||
product = element;
|
||||
salesButtonText = salesButtonText.replaceFirst(RegExp(r'localizedPrice'), product!.localizedPrice!);
|
||||
print("Localized Price ${product!.localizedPrice!} - Text: $salesButtonText");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<SalesState> mapEventToState(
|
||||
SalesEvent event,
|
||||
@@ -32,9 +55,30 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
if (event is SalesLoad) {
|
||||
yield SalesLoading();
|
||||
log("Load Sales");
|
||||
Track().track(TrackingEvent.sales_page);
|
||||
if (Cache().userLoggedIn == null) {
|
||||
throw Exception("Please log in");
|
||||
}
|
||||
|
||||
String descriptionName = "sales_page_text";
|
||||
RemoteConfig? remoteConfig = Cache().remoteConfig;
|
||||
if (remoteConfig != null) {
|
||||
remoteConfig.fetchAndActivate();
|
||||
Map config = remoteConfig.getAll();
|
||||
RemoteConfigValue? value = config['sales_page_text_a'];
|
||||
if (value != null) {
|
||||
log("RemoteConfig sales_page_text value: ${value.asString()}");
|
||||
if (value.asString() == "1") {
|
||||
descriptionName = "sales_page_text_a";
|
||||
}
|
||||
}
|
||||
}
|
||||
await RevenueCatPurchases().getOfferings();
|
||||
this.getProductSet();
|
||||
salesText = descriptionRepository.getDescriptionByName(descriptionName);
|
||||
log(salesText!);
|
||||
salesButtonText = descriptionRepository.getDescriptionByName("sales_button_monthly");
|
||||
offeredProduct = getProductByName("wt_sub_2_3");
|
||||
Track().track(TrackingEvent.sales_page);
|
||||
yield SalesReady();
|
||||
} else if (event is SalesPurchase) {
|
||||
if (Cache().hasPurchased) {
|
||||
@@ -60,6 +104,22 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
} else {
|
||||
yield SalesError(message: "No selected product");
|
||||
}
|
||||
} else if (event is SalesChangeSubscription) {
|
||||
yield SalesLoading();
|
||||
print("offered product .. $offeredProduct");
|
||||
if (offeredProduct != null) {
|
||||
if (offeredProduct!.type == "wt_sub_2_3") {
|
||||
print("go yearly");
|
||||
salesButtonText = descriptionRepository.getDescriptionByName("sales_button_yearly");
|
||||
offeredProduct = getProductByName("wt_sub_2_1");
|
||||
} else {
|
||||
print("go monthly");
|
||||
salesButtonText = descriptionRepository.getDescriptionByName("sales_button_monthly");
|
||||
offeredProduct = getProductByName("wt_sub_2_3");
|
||||
}
|
||||
}
|
||||
|
||||
yield SalesReady();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield SalesError(message: ex.toString());
|
||||
@@ -76,7 +136,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
return prod;
|
||||
}
|
||||
|
||||
String getLocalizedPrice(String productId) {
|
||||
String getLocalizedPrice(String productId, Product product) {
|
||||
String price = "";
|
||||
Offering? offering = RevenueCatPurchases().offering;
|
||||
if (offering != null) {
|
||||
@@ -86,7 +146,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
price = package.product.priceString;
|
||||
if (price.contains(r'HUF')) {
|
||||
price = price.replaceAll(RegExp(r'HUF'), 'Ft');
|
||||
price = price.replaceAll(RegExp(r',00'), "");
|
||||
price = price.replaceAll(RegExp(r'\,00'), "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -94,18 +154,21 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
} else {
|
||||
log(" !!! No Offering");
|
||||
}
|
||||
if (price.isEmpty) {
|
||||
price = Platform.isAndroid ? product.priceAndroid.toString() : product.priceIos.toString();
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
void getProductSet() {
|
||||
int productId = 0;
|
||||
this.tests = Cache().productTests;
|
||||
//this.tests = Cache().productTests;
|
||||
List<Product>? products = Cache().products;
|
||||
if (products == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tests != null && tests!.isEmpty) {
|
||||
/* if (tests != null && tests!.isEmpty) {
|
||||
var rand = math.Random.secure();
|
||||
productSet = rand.nextInt(5) + 1;
|
||||
} else {
|
||||
@@ -118,9 +181,9 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
ProductTest productTest = ProductTest();
|
||||
//ProductTest productTest = ProductTest();
|
||||
|
||||
productSet = 2;
|
||||
log("ProductSet: " + productSet.toString());
|
||||
@@ -130,7 +193,8 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
if (product.productSet == productSet) {
|
||||
productId = product.productId;
|
||||
final String platformProductId = Platform.isAndroid ? product.productIdAndroid! : product.productIdIos!;
|
||||
product.localizedPrice = getLocalizedPrice(platformProductId);
|
||||
product.localizedPrice = getLocalizedPrice(platformProductId, product);
|
||||
log("product with localized price: $product");
|
||||
product2Display.add(product);
|
||||
}
|
||||
}
|
||||
@@ -139,9 +203,9 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
return a.sort < b.sort ? -1 : 1;
|
||||
});
|
||||
|
||||
productTest.productId = productId;
|
||||
productTest.customerId = Cache().userLoggedIn!.customerId!;
|
||||
productTest.dateView = DateTime.now();
|
||||
//productTest.productId = productId;
|
||||
//productTest.customerId = Cache().userLoggedIn!.customerId!;
|
||||
//productTest.dateView = DateTime.now();
|
||||
//ProductTestApi().saveProductTest(productTest);
|
||||
//Cache().productTests.add(productTest);
|
||||
}
|
||||
|
||||
@@ -15,3 +15,7 @@ class SalesPurchase extends SalesEvent {
|
||||
final int productId;
|
||||
const SalesPurchase({required this.productId});
|
||||
}
|
||||
|
||||
class SalesChangeSubscription extends SalesEvent {
|
||||
const SalesChangeSubscription();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/bloc/settings/settings_bloc.dart';
|
||||
import 'package:aitrainer_app/service/firebase_api.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/session.dart';
|
||||
@@ -26,6 +27,7 @@ class SessionBloc extends Bloc<SessionEvent, SessionState> with Logging {
|
||||
// ignore: close_sinks
|
||||
SettingsBloc settingsBloc = event.settingsBloc;
|
||||
await session.fetchSessionAndNavigate();
|
||||
FirebaseApi().setupRemoteConfig();
|
||||
String lang = AppLanguage().appLocal.languageCode;
|
||||
log("Change lang to $lang");
|
||||
settingsBloc.add(SettingsChangeLanguage(language: lang));
|
||||
|
||||
@@ -12,6 +12,7 @@ part 'tutorial_state.dart';
|
||||
|
||||
class TutorialBloc extends Bloc<TutorialEvent, TutorialState> with Logging {
|
||||
late String tutorialName;
|
||||
final double mediaHeightBase = 390;
|
||||
bool isActive = false;
|
||||
bool canActivate = false;
|
||||
|
||||
@@ -46,6 +47,7 @@ class TutorialBloc extends Bloc<TutorialEvent, TutorialState> with Logging {
|
||||
|
||||
setNextStepData(step);
|
||||
isActive = true;
|
||||
canActivate = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -58,8 +60,9 @@ class TutorialBloc extends Bloc<TutorialEvent, TutorialState> with Logging {
|
||||
}
|
||||
if (tutorial != null && tutorial!.steps != null) {
|
||||
actualText = tutorial!.steps![step].tutorialTextTranslation;
|
||||
print("Step: $step, text: $actualText");
|
||||
|
||||
this.actualCheck = tutorial!.steps![step].checkText;
|
||||
print("Step: $step, text: $actualCheck");
|
||||
this.checks = [];
|
||||
|
||||
if (this.actualCheck != null) {
|
||||
@@ -78,27 +81,31 @@ class TutorialBloc extends Bloc<TutorialEvent, TutorialState> with Logging {
|
||||
|
||||
calculateHeight();
|
||||
}
|
||||
/* else {
|
||||
this.add(TutorialFinished());
|
||||
} */
|
||||
}
|
||||
|
||||
bool activateTutorial() {
|
||||
if (!canActivate) {
|
||||
print("Tutorial canActivate false");
|
||||
return false;
|
||||
}
|
||||
bool isTutorialDone() {
|
||||
ActivityDone? activityDone = ActivityDone.tutorialBasic.searchByString(tutorialName);
|
||||
|
||||
if (activityDone == null) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool? isActivityDone = Cache().activitiesDone[activityDone.toStr()];
|
||||
log("isActivityDone? $isActivityDone");
|
||||
|
||||
log("$tutorialName isActivityDone? $isActivityDone");
|
||||
if (isActivityDone == null || isActivityDone == true) {
|
||||
return true;
|
||||
}
|
||||
canActivate = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool activateTutorial() {
|
||||
if (isTutorialDone()) {
|
||||
isActive = false;
|
||||
canActivate = false;
|
||||
return false;
|
||||
}
|
||||
log("Running tutorial $activityDone");
|
||||
|
||||
init();
|
||||
return true;
|
||||
}
|
||||
@@ -135,20 +142,9 @@ class TutorialBloc extends Bloc<TutorialEvent, TutorialState> with Logging {
|
||||
if (action == null) {
|
||||
return step + 1;
|
||||
}
|
||||
/* bool found = false;
|
||||
if (tutorial != null && tutorial!.steps != null) {
|
||||
for (var nextStep in tutorial!.steps!) {
|
||||
print("step $step parent: ${nextStep.action!.parent}");
|
||||
if (step + 1 == nextStep.step) {
|
||||
next = nextStep.step!;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} */
|
||||
step++;
|
||||
next = step;
|
||||
print("Next step:! $next");
|
||||
print("Next step:! $step");
|
||||
if (step >= tutorial!.steps!.length) {
|
||||
next = -1;
|
||||
this.add(TutorialFinished());
|
||||
@@ -172,6 +168,7 @@ class TutorialBloc extends Bloc<TutorialEvent, TutorialState> with Logging {
|
||||
menuBloc!.add(MenuCreate());
|
||||
}
|
||||
} else if (event is TutorialNext) {
|
||||
print("Tutorial Next: ${event.text}");
|
||||
if (tutorial != null) {
|
||||
yield TutorialLoading();
|
||||
|
||||
@@ -195,7 +192,6 @@ class TutorialBloc extends Bloc<TutorialEvent, TutorialState> with Logging {
|
||||
yield TutorialReady();
|
||||
} else if (event is TutorialStart) {
|
||||
yield TutorialLoading();
|
||||
isActive = true;
|
||||
canActivate = true;
|
||||
step = 0;
|
||||
yield TutorialReady();
|
||||
|
||||
Reference in New Issue
Block a user