WT1.1.0+40 Premium feature settings

This commit is contained in:
bossanyit
2020-12-28 14:39:54 +01:00
parent 5c7a3d67e8
commit 9755cc764a
84 changed files with 2069 additions and 1192 deletions
+57 -24
View File
@@ -5,14 +5,19 @@ import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/model/exercise_tree.dart';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/model/product.dart';
import 'package:aitrainer_app/model/product_test.dart';
import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/model/purchase.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.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/logging.dart';
import 'package:aitrainer_app/util/env.dart';
import 'package:flurry/flurry.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -43,7 +48,7 @@ enum SharePrefsChange {
- is_logged_in
*/
class Cache {
class Cache with Logging {
static final Cache _singleton = Cache._internal();
// Keys to store and fetch data from SharedPreferences
@@ -65,6 +70,7 @@ class Cache {
String authToken = "";
Customer userLoggedIn;
String firebaseUid;
Purchase purchased;
bool firstLoad = true;
@@ -74,6 +80,10 @@ class Cache {
List<Exercise> _exercises;
ExercisePlan _myExercisePlan;
List<Property> _properties;
List<Product> _products;
List<Purchase> _purchases;
List<ProductTest> _productTests;
List<ExerciseDevice> _devices;
List<CustomerExerciseDevice> _customerDevices;
@@ -130,7 +140,7 @@ class Cache {
void getHardware(SharedPreferences prefs) {
final bool hasHardware = prefs.getBool(Cache.hardwareKey);
print("Has Hardware: " + hasHardware.toString());
//log("Has Hardware: " + hasHardware.toString());
this.hasHardware = hasHardware;
if (hasHardware == null) {
this.hasHardware = false;
@@ -182,11 +192,11 @@ class Cache {
return mediaUrl;
}
afterRegistration(Customer customer) {
afterRegistration(Customer customer) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
userLoggedIn = customer;
setPreferences(prefs, SharePrefsChange.registration, customer.customerId, Cache().firebaseUid);
await setPreferences(prefs, SharePrefsChange.registration, customer.customerId, Cache().firebaseUid);
}
afterLogin(Customer customer) async {
@@ -211,43 +221,28 @@ class Cache {
_traineeExercisePlan = null;
_exercises = List();
_myExercisesPlanDetails = LinkedHashMap();
print("Trainees is null? " + (_trainee == null).toString());
log("Trainees is null? " + (_trainee == null).toString());
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
await setPreferences(prefs, SharePrefsChange.logout, 0, "");
}
setPreferences(Future<SharedPreferences> prefs, SharePrefsChange type, int customerId, String firebaseUid) async {
Future<void> setPreferences(Future<SharedPreferences> prefs, SharePrefsChange type, int customerId, String firebaseUid) async {
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
DateTime now = DateTime.now();
sharedPreferences.setString(Cache.lastStoreDateKey, now.toString());
ExerciseRepository exerciseRepository = ExerciseRepository();
if (type == SharePrefsChange.registration) {
Cache().startPage = "home";
Flurry.setUserId(customerId.toString());
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setBool(Cache.isRegisteredKey, true);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree();
await ExerciseDeviceApi().getDevices();
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
Cache().setCustomerDevices(customerDevices);
await exerciseRepository.getExercisesByCustomer(customerId);
await initCustomer(customerId);
} else if (type == SharePrefsChange.login) {
Flurry.setUserId(customerId.toString());
Cache().startPage = "home";
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree();
await ExerciseDeviceApi().getDevices();
final customerDevices = await CustomerExerciseDeviceApi().getDevices(customerId);
Cache().setCustomerDevices(customerDevices);
await exerciseRepository.getExercisesByCustomer(customerId);
await initCustomer(customerId);
} else if (type == SharePrefsChange.logout) {
sharedPreferences.setBool(Cache.isLoggedInKey, false);
sharedPreferences.setInt(Cache.customerIdKey, 0);
@@ -279,6 +274,16 @@ class Cache {
List<ExerciseType> getExerciseTypes() => this._exerciseTypes;
ExerciseType getExercise(int exerciseTypeId) {
ExerciseType exerciseType;
this._exerciseTypes.forEach((element) {
if (element.exerciseTypeId == exerciseTypeId) {
exerciseType = element;
}
});
return exerciseType;
}
List<ExerciseTree> getExerciseTree() => this._exerciseTree;
List<Exercise> getExercises() => this._exercises;
@@ -402,6 +407,34 @@ class Cache {
setBadgeNr("home", 1);
}
}
print("Badges: " + _badges.toString());
log("Badges: " + _badges.toString());
}
List get products => _products;
void setProducts(List value) => _products = value;
List get purchases => _purchases;
setPurchases(List value) => _purchases = value;
List get productTests => _productTests;
set productTests(List value) => _productTests = value;
Future<void> initCustomer(int customerId) async {
log(" *** initCustomer");
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);
ExerciseRepository exerciseRepository = ExerciseRepository();
await exerciseRepository.getExercisesByCustomer(customerId);
CustomerRepository customerRepository = CustomerRepository(customer: this.userLoggedIn);
await customerRepository.getPurchase();
await customerRepository.getProductTests();
}
}
+13 -17
View File
@@ -12,8 +12,7 @@ class Exercise {
String datePart;
double calculated;
String summary;
Exercise({this.exerciseTypeId, this.customerId, this.quantity, this.dateAdd});
@@ -24,13 +23,12 @@ class Exercise {
this.quantity = json['quantity'];
this.unit = json['unit'];
this.unitQuantity = json['unitQuantity'];
this.dateAdd = DateTime.parse( json['dateAdd'] );
this.dateAdd = DateTime.parse(json['dateAdd']);
this.datePart = DateFormat('yyyy-MM-dd').format(this.dateAdd);
this.calculated = quantity;
}
Map<String, dynamic> toJson() =>
{
Map<String, dynamic> toJson() => {
"exerciseTypeId": exerciseTypeId,
"customerId": customerId,
"quantity": quantity,
@@ -40,17 +38,15 @@ class Exercise {
"exercisePlanDetailId": exercisePlanDetailId,
};
Map<String, dynamic> toJsonDatePart() =>
{
"exerciseTypeId": exerciseTypeId,
"customerId": customerId,
"quantity": quantity,
'calculated': calculated,
"unit": unit,
"unitQuantity": unitQuantity,
"datePart": this.datePart,
};
Map<String, dynamic> toJsonDatePart() => {
"exerciseTypeId": exerciseTypeId,
"customerId": customerId,
"quantity": quantity,
'calculated': calculated,
"unit": unit,
"unitQuantity": unitQuantity,
"datePart": this.datePart,
};
Exercise copy() {
Exercise newExercise = Exercise();
@@ -63,4 +59,4 @@ class Exercise {
newExercise.exercisePlanDetailId = this.exercisePlanDetailId;
return newExercise;
}
}
}
+2
View File
@@ -13,6 +13,8 @@ class ExerciseResult {
ResultExt resultExtension;
ExerciseResult();
Map<String, dynamic> toJson() {
String formattedDateTo;
if (dateTo != null) {
-1
View File
@@ -59,7 +59,6 @@ class FitnessItem {
FitnessState selected;
elements.forEach((element) {
if (element.value == value) {
print("selected " + element.value);
selected = element;
}
});
+36 -2
View File
@@ -3,15 +3,49 @@ class Product {
String name;
String description;
String type;
String appVersion;
int sort;
int productSet;
DateTime validFrom;
DateTime validTo;
String productIdIos;
String productIdAndroid;
double priceIos;
double priceAndroid;
Product.fromJson(Map json) {
this.productId = json['productId'];
this.name = json['name'];
this.description = json['description'];
this.type = json['type'];
this.validFrom = json['validFrom'];
this.validTo = json['validTo'];
this.appVersion = json['appVersion'];
this.sort = json['sort'];
this.productSet = json['productSet'];
this.validFrom = json['validFrom'] == null ? null : DateTime.parse(json['validFrom']);
this.validTo = json['validTo'] == null ? null : DateTime.parse(json['validTo']);
this.productIdIos = json['productIdIos'];
this.productIdAndroid = json['productIdAndroid'];
this.priceIos = json['priceIos'];
this.priceAndroid = json['priceAndroid'];
}
@override
String toString() {
Map<String, dynamic> json = {
'productId': this.productId,
'name': this.name,
'description': this.description,
'type': this.type,
'appVersion': this.appVersion,
'sort': this.sort,
'productSet': this.productSet,
'validFrom': this.validFrom,
'validTo': validTo,
'productIdIos': this.productIdIos,
'productIdAndroid': this.productIdAndroid,
'priceIos': this.priceIos,
'priceAndroid': this.priceAndroid,
};
return json.toString();
}
}
+24 -1
View File
@@ -1,3 +1,5 @@
import 'package:intl/intl.dart';
class ProductTest {
int productTestId;
int customerId;
@@ -6,11 +8,32 @@ class ProductTest {
DateTime dateView;
bool purchaseClick;
ProductTest();
ProductTest.fromJson(Map json) {
this.productTestId = json['productTestId'];
this.customerId = json['customerId'];
this.productId = json['productId'];
this.dateView = json['dateView'];
this.dateView = DateTime.parse(json['dateView']);
this.purchaseClick = json['purchaseClick'];
}
Map<String, dynamic> toJson() {
if (productTestId != null) {
return {
"productTestId": productTestId,
"customerId": customerId,
"productId": productId,
"dateView": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateView),
"purchaseClick": purchaseClick
};
} else {
return {
"customerId": customerId,
"productId": productId,
"dateView": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateView),
"purchaseClick": purchaseClick
};
}
}
}
+4 -5
View File
@@ -1,4 +1,4 @@
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
import 'package:intl/intl.dart';
class Purchase {
int purchaseId;
@@ -13,13 +13,12 @@ class Purchase {
this.purchaseId = json['purchaseId'];
this.customerId = json['customerId'];
this.productId = json['productId'];
this.dateAdd = json['dateAdd'];
this.dateAdd = DateTime.parse(json['dateAdd']);
this.purchaseSum = json['purchaseSum'];
this.customerId = json['currency'];
this.currency = json['currency'];
}
Map<String, dynamic> toJson() =>
{
Map<String, dynamic> toJson() => {
"purchaseId": purchaseId,
"customerId": customerId,
"productId": productId,
+12 -4
View File
@@ -72,7 +72,11 @@ extension ResultItemExt on ResultItem {
class ResultExt {
final String itemString;
ResultItem item;
String data = "0";
double data = 0;
int exerciseId;
DateTime dateFrom;
DateTime dateTo;
ResultExt({this.itemString}) {
ResultItem.values.forEach((element) {
@@ -84,9 +88,13 @@ class ResultExt {
String getDescription() => item.description;
String getImage() => "asset/image/" + item.image;
bool isHardware() {
return item.isHardware;
}
bool isHardware() => item.isHardware;
int get getExerciseId => exerciseId;
set setExerciseId(int exerciseId) => this.exerciseId = exerciseId;
set setDateFrom(DateTime dateFrom) => this.dateFrom = dateFrom;
DateTime get getDateFrom => dateFrom;
set setDateTo(DateTime dateTo) => this.dateTo = dateTo;
DateTime get getDateTo => dateTo;
bool equals(ResultItem item) => this.item.equals(item);
bool equalsString(String item) => this.item.equalsString(item);