WT1.1.0+40 Premium feature settings
This commit is contained in:
+20
-24
@@ -4,6 +4,7 @@ import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/repository/user_repository.dart';
|
||||
import 'package:aitrainer_app/util/env.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
@@ -15,26 +16,23 @@ class DateRate {
|
||||
}
|
||||
|
||||
mixin Common {
|
||||
|
||||
final EMAIL_ERROR = "Please type a right email address here.";
|
||||
final PASSWORD_ERROR = "The password must have at least 8 characters.";
|
||||
|
||||
|
||||
|
||||
String toJson( Map<String, String> map ) {
|
||||
String toJson(Map<String, String> map) {
|
||||
String rc = "{";
|
||||
map.forEach((key, value) {
|
||||
rc += "'$key':'$value'";
|
||||
rc += "'$key':'$value'";
|
||||
});
|
||||
rc += "}";
|
||||
return rc;
|
||||
}
|
||||
|
||||
ExerciseType getExerciseType( int exerciseTypeId ) {
|
||||
ExerciseType getExerciseType(int exerciseTypeId) {
|
||||
ExerciseType returnElement;
|
||||
List<ExerciseType> listExerciseType = Cache().getExerciseTypes();
|
||||
if ( listExerciseType != null ) {
|
||||
for ( var element in listExerciseType ) {
|
||||
if (listExerciseType != null) {
|
||||
for (var element in listExerciseType) {
|
||||
if (exerciseTypeId == element.exerciseTypeId) {
|
||||
returnElement = element;
|
||||
break;
|
||||
@@ -44,12 +42,12 @@ mixin Common {
|
||||
return returnElement;
|
||||
}
|
||||
|
||||
String getDateLocale( DateTime datetime, bool timeDisplay ) {
|
||||
String getDateLocale(DateTime datetime, bool timeDisplay) {
|
||||
var date = datetime;
|
||||
|
||||
String dateName = DateFormat(DateFormat.YEAR_MONTH_DAY, AppLanguage().appLocal.toString()).format(date.toUtc());
|
||||
if ( timeDisplay ) {
|
||||
dateName += " " +DateFormat(DateFormat.HOUR_MINUTE, AppLanguage().appLocal.toString()).format(date.toUtc());
|
||||
if (timeDisplay) {
|
||||
dateName += " " + DateFormat(DateFormat.HOUR_MINUTE, AppLanguage().appLocal.toString()).format(date.toUtc());
|
||||
}
|
||||
|
||||
return dateName;
|
||||
@@ -60,8 +58,8 @@ mixin Common {
|
||||
return utf8.decode(bytes);
|
||||
}
|
||||
|
||||
double mediaSizeWidth( BuildContext context ) {
|
||||
return MediaQuery.of(context).size.width;
|
||||
double mediaSizeWidth(BuildContext context) {
|
||||
return MediaQuery.of(context).size.width;
|
||||
}
|
||||
|
||||
bool validateEmail(UserRepository userRepository) {
|
||||
@@ -74,8 +72,7 @@ mixin Common {
|
||||
|
||||
bool validatePassword(UserRepository userRepository) {
|
||||
final password = userRepository.user.password;
|
||||
final RegExp _passwordRegExp =
|
||||
RegExp(r'^(?=.*[A-Za-z0-9])(?=.*\d)[A-Za-z\d]{7,}$');
|
||||
final RegExp _passwordRegExp = RegExp(r'^(?=.*[A-Za-z0-9])(?=.*\d)[A-Za-z\d]{7,}$');
|
||||
|
||||
return _passwordRegExp.hasMatch(password);
|
||||
}
|
||||
@@ -88,16 +85,15 @@ mixin Common {
|
||||
|
||||
String getDatePart(DateTime date, String dateRate) {
|
||||
String datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
if ( dateRate == DateRate.weekly ) {
|
||||
if (dateRate == DateRate.weekly) {
|
||||
datePart = weekNumber(date).toString();
|
||||
} else if ( dateRate == DateRate.monthly ) {
|
||||
datePart = DateFormat('MMM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if ( dateRate == DateRate.yearly ) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if ( dateRate == DateRate.daily ) {
|
||||
datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DateRate.monthly) {
|
||||
datePart = DateFormat('MMM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DateRate.yearly) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DateRate.daily) {
|
||||
datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
}
|
||||
return datePart;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
|
||||
|
||||
class PlatformPurchaseApi with Logging {
|
||||
static final PlatformPurchaseApi _singleton = PlatformPurchaseApi._internal();
|
||||
|
||||
StreamSubscription _purchaseUpdatedSubscription;
|
||||
StreamSubscription _purchaseErrorSubscription;
|
||||
StreamSubscription _conectionSubscription;
|
||||
String _platformVersion = 'Unknown';
|
||||
List<IAPItem> _items = [];
|
||||
List<PurchasedItem> _purchases = [];
|
||||
|
||||
final List<String> _productLists = List();
|
||||
/* Platform.isAndroid
|
||||
? [
|
||||
'android.test.purchased',
|
||||
'point_1000',
|
||||
'5000_point',
|
||||
'android.test.canceled',
|
||||
]
|
||||
: ['com.cooni.point1000', 'com.cooni.point5000'];
|
||||
*/
|
||||
|
||||
factory PlatformPurchaseApi() {
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
PlatformPurchaseApi._internal();
|
||||
|
||||
void close() {
|
||||
if (_conectionSubscription != null) {
|
||||
_conectionSubscription.cancel();
|
||||
_conectionSubscription = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Platform messages are asynchronous, so we initialize in an async method.
|
||||
Future<void> initPurchasePlatformState() async {
|
||||
String platformVersion;
|
||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||
try {
|
||||
platformVersion = await FlutterInappPurchase.instance.platformVersion;
|
||||
} on Exception {
|
||||
platformVersion = 'Failed to get platform version for InAppPurchase.';
|
||||
log(platformVersion);
|
||||
}
|
||||
|
||||
// prepare
|
||||
var result = await FlutterInappPurchase.instance.initConnection;
|
||||
log('result: $result');
|
||||
|
||||
_platformVersion = platformVersion;
|
||||
|
||||
// refresh items for android
|
||||
try {
|
||||
String msg = await FlutterInappPurchase.instance.consumeAllItems;
|
||||
log('consumeAllItems: $msg');
|
||||
} catch (err) {
|
||||
log('consumeAllItems error: $err');
|
||||
}
|
||||
|
||||
_conectionSubscription = FlutterInappPurchase.connectionUpdated.listen((connected) {
|
||||
log('connected: $connected');
|
||||
});
|
||||
|
||||
_purchaseUpdatedSubscription = FlutterInappPurchase.purchaseUpdated.listen((productItem) {
|
||||
log('purchase-updated: $productItem');
|
||||
});
|
||||
|
||||
_purchaseErrorSubscription = FlutterInappPurchase.purchaseError.listen((purchaseError) {
|
||||
log('purchase-error: $purchaseError');
|
||||
});
|
||||
}
|
||||
|
||||
void requestPurchase(IAPItem item) {
|
||||
//FlutterInappPurchase.instance.requestPurchase(item.productId);
|
||||
FlutterInappPurchase.instance.requestPurchase("WT_monthly");
|
||||
}
|
||||
|
||||
Future _getProduct() async {
|
||||
List<IAPItem> items = await FlutterInappPurchase.instance.getProducts(_productLists);
|
||||
for (var item in items) {
|
||||
log('${item.toString()}');
|
||||
this._items.add(item);
|
||||
}
|
||||
|
||||
this._items = items;
|
||||
this._purchases = [];
|
||||
}
|
||||
|
||||
Future _getPurchases() async {
|
||||
List<PurchasedItem> items = await FlutterInappPurchase.instance.getAvailablePurchases();
|
||||
for (var item in items) {
|
||||
log('${item.toString()}');
|
||||
this._purchases.add(item);
|
||||
}
|
||||
|
||||
this._items = [];
|
||||
this._purchases = items;
|
||||
}
|
||||
|
||||
Future _getPurchaseHistory() async {
|
||||
List<PurchasedItem> items = await FlutterInappPurchase.instance.getPurchaseHistory();
|
||||
for (var item in items) {
|
||||
log('${item.toString()}');
|
||||
this._purchases.add(item);
|
||||
}
|
||||
|
||||
this._items = [];
|
||||
this._purchases = items;
|
||||
}
|
||||
}
|
||||
+21
-35
@@ -1,39 +1,34 @@
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/localization/app_localization.dart';
|
||||
import 'package:aitrainer_app/model/customer_exercise_device.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
import 'package:aitrainer_app/service/customer_exercise_device_service.dart';
|
||||
import 'package:aitrainer_app/service/customer_service.dart';
|
||||
import 'package:aitrainer_app/service/exercise_device_service.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
import 'package:aitrainer_app/service/firebase_api.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/product_service.dart';
|
||||
import 'package:aitrainer_app/service/property_service.dart';
|
||||
import 'package:devicelocale/devicelocale.dart';
|
||||
import 'package:flurry/flurry.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
|
||||
class Session {
|
||||
class Session with Logging {
|
||||
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
||||
|
||||
SharedPreferences _sharedPreferences;
|
||||
|
||||
fetchSessionAndNavigate() async {
|
||||
print(" -- Session: await prefs..");
|
||||
log(" -- Session: await prefs..");
|
||||
_sharedPreferences = await _prefs;
|
||||
|
||||
if (Cache().firstLoad) {
|
||||
print(" -- Session: fetch locale..");
|
||||
log(" -- Session: fetch locale..");
|
||||
await AppLanguage().getLocale(_sharedPreferences);
|
||||
await AppLocalizations.delegate.load(AppLanguage().appLocal);
|
||||
print(" -- Session: fetch token..");
|
||||
log(" -- Session: fetch token..");
|
||||
Cache().setServerAddress(_sharedPreferences);
|
||||
Cache().getHardware(_sharedPreferences);
|
||||
await _fetchToken(_sharedPreferences);
|
||||
print(" -- FireBase init..");
|
||||
log(" -- FireBase init..");
|
||||
await FirebaseApi().initializeFlutterFire();
|
||||
//initDeviceLocale();
|
||||
|
||||
@@ -50,15 +45,15 @@ class Session {
|
||||
try {
|
||||
languages = await Devicelocale.preferredLanguages;
|
||||
Cache().deviceLanguages = languages;
|
||||
print("device langs " + languages.toString());
|
||||
log("device langs " + languages.toString());
|
||||
} on PlatformException {
|
||||
print("Error obtaining preferred languages");
|
||||
log("Error obtaining preferred languages");
|
||||
}
|
||||
try {
|
||||
currentLocale = await Devicelocale.currentLocale;
|
||||
print("Device currentlocale " + currentLocale);
|
||||
log("Device currentlocale " + currentLocale);
|
||||
} on PlatformException {
|
||||
print("Error obtaining current locale");
|
||||
log("Error obtaining current locale");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,18 +61,19 @@ class Session {
|
||||
Auth flow of the user, see auth.dart
|
||||
*/
|
||||
_fetchToken(SharedPreferences prefs) async {
|
||||
var responseJson = await APIClient.authenticateUser(Cache.username, Cache.password);
|
||||
var responseJson = await APIClient().authenticateUser(Cache.username, Cache.password);
|
||||
int customerId = 0;
|
||||
print("--- Lang: " + AppLanguage().appLocal.toString());
|
||||
log("--- Lang: " + AppLanguage().appLocal.toString());
|
||||
if (responseJson['error'] != null) {
|
||||
print("************** Here big error - no authentication");
|
||||
log("************** Here big error - no authentication");
|
||||
} else if (responseJson['token'] != null) {
|
||||
prefs.setString(Cache.authTokenKey, responseJson['token']);
|
||||
Cache().authToken = responseJson['token'];
|
||||
Cache().firebaseUid = prefs.get(Cache.firebaseUidKey);
|
||||
await PropertyApi().getProperties();
|
||||
await ProductApi().getProducts();
|
||||
if (prefs.get(Cache.customerIdKey) == null) {
|
||||
print("************** Registration");
|
||||
log("************** Registration");
|
||||
// registration
|
||||
prefs.setBool(Cache.isRegisteredKey, true);
|
||||
Cache().startPage = "registration";
|
||||
@@ -90,31 +86,21 @@ class Session {
|
||||
lastStoreDate.difference(minStoreDate) > Duration(days: 10) ||
|
||||
prefs.get(Cache.isLoggedInKey) == null ||
|
||||
prefs.get(Cache.isLoggedInKey) == false) {
|
||||
print("************* Login");
|
||||
log("************* Login");
|
||||
Cache().startPage = "login";
|
||||
} else {
|
||||
// only
|
||||
if (Cache().firebaseUid == null) {
|
||||
print("************* firebaseUid is null, Login");
|
||||
log("************* firebaseUid is null, Login");
|
||||
Cache().startPage = "login";
|
||||
} else {
|
||||
// get API customer
|
||||
customerId = prefs.getInt(Cache.customerIdKey);
|
||||
await CustomerApi().getCustomer(customerId);
|
||||
Cache().startPage = "home";
|
||||
Flurry.setUserId(customerId.toString());
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
await ExerciseDeviceApi().getDevices();
|
||||
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
|
||||
Cache().setCustomerDevices(customerDevices);
|
||||
if (customerId > 0) {
|
||||
ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
await exerciseRepository.getExercisesByCustomer(customerId);
|
||||
}
|
||||
await Cache().initCustomer(customerId);
|
||||
}
|
||||
}
|
||||
print("--- Session finished");
|
||||
log("--- Session finished");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user