From 6ef311286c53b91121bc3dbfce974f5cf5765d46 Mon Sep 17 00:00:00 2001 From: bossanyit Date: Sun, 13 Nov 2022 09:43:49 +0100 Subject: [PATCH] v1.1.26 android release --- android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- ios/Runner.xcodeproj/project.pbxproj | 6 +- lib/bloc/sales/sales_bloc.dart | 60 ++++++++++++------ lib/bloc/session/session_bloc.dart | 29 +++++---- lib/main.dart | 6 +- lib/model/cache.dart | 2 +- lib/service/api.dart | 7 ++- lib/util/purchases.dart | 63 +++++++------------ lib/widgets/home.dart | 11 +++- pubspec.yaml | 2 +- 11 files changed, 107 insertions(+), 83 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index aa242ea..135a7a5 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:4.0.2" + classpath "com.android.tools.build:gradle:7.0.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.google.gms:google-services:4.3.4" } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index de2ccd6..562c5e4 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 47ace6a..8ff73d6 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -372,7 +372,7 @@ CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = SFJJBDCU6Z; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -518,7 +518,7 @@ CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = SFJJBDCU6Z; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -556,7 +556,7 @@ CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = SFJJBDCU6Z; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( diff --git a/lib/bloc/sales/sales_bloc.dart b/lib/bloc/sales/sales_bloc.dart index 3da9751..3b3e755 100644 --- a/lib/bloc/sales/sales_bloc.dart +++ b/lib/bloc/sales/sales_bloc.dart @@ -15,7 +15,10 @@ 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:flutter/services.dart'; +import 'package:purchases_flutter/errors.dart'; import 'package:purchases_flutter/models/offering_wrapper.dart'; +import 'package:sentry_flutter/sentry_flutter.dart'; part 'sales_event.dart'; part 'sales_state.dart'; @@ -50,25 +53,46 @@ class SalesBloc extends Bloc with Logging { final int productId = event.productId; log("Requesting purchase for: " + productId.toString()); Track().track(TrackingEvent.purchase_request); - final Product? selectedProduct = this.getSelectedProduct(productId); - log("SelectedProduct for purchase $selectedProduct"); - if (selectedProduct != null) { - 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); - Track().track(TrackingEvent.purchase_successful, eventValue: selectedProduct.localizedPrice.toString()); - CustomerRepository customerRepository = CustomerRepository(); - customerRepository.customer = Cache().userLoggedIn; - MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); - await mauticRepository.sendMauticPurchase(); + try { + final Product? selectedProduct = this.getSelectedProduct(productId); + + log("SelectedProduct for purchase $selectedProduct"); + if (selectedProduct != null) { + 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); + Track().track(TrackingEvent.purchase_successful, eventValue: selectedProduct.localizedPrice.toString()); + CustomerRepository customerRepository = CustomerRepository(); + customerRepository.customer = Cache().userLoggedIn; + MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); + await mauticRepository.sendMauticPurchase(); + } + emit(SalesSuccessful()); + } else { + emit(SalesError(message: "No selected product")); } - emit(SalesSuccessful()); - } else { - emit(SalesError(message: "No selected product")); + } on PlatformException catch (e) { + await Sentry.captureException(e); + var errorCode = PurchasesErrorHelper.getErrorCode(e); + if (errorCode == PurchasesErrorCode.invalidReceiptError) { + log("iOS Sandbox invalid receipt"); + Cache().hasPurchased = true; + log(" -- Purchased -- "); + return; + } + log(e.toString()); + if (errorCode == PurchasesErrorCode.purchaseCancelledError) { + emit(SalesError(message: "Purchase was cancelled")); + } else { + emit(SalesError(message: "Purchase was not successful")); + } + } on Exception catch (e) { + log(e.toString()); + emit(SalesError(message: "Purchase was not successful")); } } diff --git a/lib/bloc/session/session_bloc.dart b/lib/bloc/session/session_bloc.dart index 80ef64c..468a6fc 100644 --- a/lib/bloc/session/session_bloc.dart +++ b/lib/bloc/session/session_bloc.dart @@ -25,18 +25,23 @@ class SessionBloc extends Bloc with Logging { log(" -------- Session starting..."); emit(SessionLoading()); - this.settingsBloc = event.settingsBloc; - await session.fetchSessionAndNavigate(); - FirebaseApi().setupRemoteConfig(); - String lang = AppLanguage().appLocal.languageCode; - log("Change lang to $lang"); - settingsBloc!.add(SettingsChangeLanguage(language: lang)); - final iTunes = ITunesSearchAPI(); - final resultsFuture = iTunes.lookupByBundleId('com.aitrainer.app'); - resultsFuture.then((results) { - print('iTunes results: $results'); - }); - emit(SessionReady()); + try { + this.settingsBloc = event.settingsBloc; + await session.fetchSessionAndNavigate(); + FirebaseApi().setupRemoteConfig(); + String lang = AppLanguage().appLocal.languageCode; + log("Change lang to $lang"); + settingsBloc!.add(SettingsChangeLanguage(language: lang)); + final iTunes = ITunesSearchAPI(); + final resultsFuture = iTunes.lookupByBundleId('com.aitrainer.app'); + resultsFuture.then((results) { + print('iTunes results: $results'); + }); + } on Exception catch (e) { + emit(SessionFailure(message: e.toString())); + } finally { + emit(SessionReady()); + } } @override diff --git a/lib/main.dart b/lib/main.dart index 8f7963e..ed9c150 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -70,7 +70,6 @@ import 'view/training_evaluation_page.dart'; import 'package:syncfusion_localizations/syncfusion_localizations.dart'; const dsn = 'https://2309523cf2374c089fa1143d19209bc1@glitch.workouttest.org/2'; -//const dsn = 'https://be8b4f90398a45e68b6798c32c4e6baf@app.glitchtip.com/1992'; /// Whether the VM is running in debug mode. /// @@ -152,10 +151,7 @@ Future main() async { await initThirdParty(); final FirebaseAnalytics analytics = FirebaseAnalytics.instance; - await SentryFlutter.init( - (options) => options - ..dsn = dsn - ..debug = true, + await SentryFlutter.init((options) => options..dsn = dsn, appRunner: () => runApp(MultiBlocProvider( providers: [ BlocProvider( diff --git a/lib/model/cache.dart b/lib/model/cache.dart index f674a84..123b34e 100644 --- a/lib/model/cache.dart +++ b/lib/model/cache.dart @@ -118,7 +118,7 @@ class Cache with Logging { static final String myTrainingPlanKey = "myTrainingPlan"; static String baseUrlLive = 'https://api.workouttest.org/api/'; - static String baseUrlTest = 'https://api-test.workouttest.org/api/'; + static String baseUrlTest = 'https://apitest.workouttest.org/api/'; late String baseUrl; static final String mediaUrl = 'https://admin.aitrainer.app/media/'; static final String username = 'bosi'; diff --git a/lib/service/api.dart b/lib/service/api.dart index fbbff28..35a3dac 100644 --- a/lib/service/api.dart +++ b/lib/service/api.dart @@ -52,7 +52,12 @@ class APIClient with Common, Logging { return jsonDecode(await result.transform(utf8.decoder).join()); } catch (exception) { print(exception.toString()); - await Sentry.captureException(exception); + try { + await Sentry.captureException(exception); + } on Exception catch (e) { + print(e); + } + throw Exception("Network error, try again later!"); } } diff --git a/lib/util/purchases.dart b/lib/util/purchases.dart index fbc3721..034311e 100644 --- a/lib/util/purchases.dart +++ b/lib/util/purchases.dart @@ -75,49 +75,34 @@ class RevenueCatPurchases with Logging { } Future makePurchase(wtproduct.Product product) async { - try { - if (_offering == null) { - _offering = await getOfferings(); - } - if (_offering != null) { - String productId = Platform.isAndroid ? product.productIdAndroid! : product.productIdIos!; - Package? selectedPackage; - log("Nr of packages: " + _offering!.availablePackages.length.toString() + " ProductId: " + productId); - for (var package in _offering!.availablePackages) { - log("package to check " + package.product.identifier.toString()); - if (package.product.identifier == productId) { - selectedPackage = package; - log("**** Selected package to purchase" + package.product.identifier); - break; - } + if (_offering == null) { + _offering = await getOfferings(); + } + if (_offering != null) { + String productId = Platform.isAndroid ? product.productIdAndroid! : product.productIdIos!; + Package? selectedPackage; + log("Nr of packages: " + _offering!.availablePackages.length.toString() + " ProductId: " + productId); + for (var package in _offering!.availablePackages) { + log("package to check " + package.product.identifier.toString()); + if (package.product.identifier == productId) { + selectedPackage = package; + log("**** Selected package to purchase" + package.product.identifier); + break; } - if (selectedPackage != null) { - PurchaserInfo purchaserInfo = await Purchases.purchasePackage(selectedPackage); - if (purchaserInfo.entitlements.all["wt_subscription"] != null && purchaserInfo.entitlements.all["wt_subscription"]!.isActive) { - Cache().hasPurchased = true; - log(" -- Purchased -- "); - } - } else { - log("!!!! No Selected package to purchase"); - throw Exception("Purchase was not successful"); + } + if (selectedPackage != null) { + PurchaserInfo purchaserInfo = await Purchases.purchasePackage(selectedPackage); + if (purchaserInfo.entitlements.all["wt_subscription"] != null && purchaserInfo.entitlements.all["wt_subscription"]!.isActive) { + Cache().hasPurchased = true; + log(" -- Purchased -- "); } } else { - log("!!!! No active offering"); - } - } on PlatformException catch (e) { - var errorCode = PurchasesErrorHelper.getErrorCode(e); - if (errorCode == PurchasesErrorCode.invalidReceiptError) { - log("iOS Sandbox invalid receipt"); - Cache().hasPurchased = true; - log(" -- Purchased -- "); - return; - } - log(e.toString()); - if (errorCode == PurchasesErrorCode.purchaseCancelledError) { - throw Exception("Purchase was cancelled"); - } else { - throw Exception("Purchase was not successful"); + log("!!!! No Selected package to purchase"); + throw Exception("No Selected package to purchase"); } + } else { + log("!!!! No active offering"); + throw Exception("No active offering"); } } } diff --git a/lib/widgets/home.dart b/lib/widgets/home.dart index d20b421..95b7915 100644 --- a/lib/widgets/home.dart +++ b/lib/widgets/home.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:aitrainer_app/bloc/session/session_bloc.dart'; import 'package:aitrainer_app/bloc/settings/settings_bloc.dart'; import 'package:aitrainer_app/model/cache.dart'; @@ -72,11 +74,18 @@ class _HomePageState extends State with Logging, Trans, Traceable final appcastURL = "https://raw.githubusercontent.com/bossanyit/appcast/main/android_rss.xml"; final cfg = AppcastConfiguration(url: appcastURL, supportedOS: ['android']); print("Packageinfo ${Cache().packageInfo}"); + String minVersion = ""; + if (Platform.isAndroid) { + minVersion = "[Minimum supported app version: 1.1.26]"; + } else { + minVersion = "[:mav: 1.1.26]"; + } return Scaffold( key: _scaffoldKey, body: UpgradeAlert( - upgrader: Upgrader(appcastConfig: cfg, messages: MyLocalizedUpgraderMessages(context: context)), + upgrader: Upgrader( + countryCode: "hu", minAppVersion: minVersion, appcastConfig: cfg, messages: MyLocalizedUpgraderMessages(context: context)), child: BlocConsumer(listener: (context, state) { if (state is SessionFailure) { showDialog( diff --git a/pubspec.yaml b/pubspec.yaml index 272711a..2413958 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.1.26+107 +version: 1.1.26+108 environment: sdk: ">=2.12.0 <3.9.0"